Update test files

This commit is contained in:
flip1995 2020-10-16 13:26:02 +02:00 committed by flip1995
parent ae2dd671f5
commit bb40db7adc
No known key found for this signature in database
GPG Key ID: 1CA0DF2AF59D68A5
6 changed files with 213 additions and 97 deletions

View File

@ -3,7 +3,7 @@
#![warn(clippy::use_self)]
#![allow(dead_code)]
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into)]
fn main() {}
@ -15,16 +15,13 @@ mod use_self {
Self {}
}
fn test() -> Self {
// FIXME: applicable here
Foo::new()
Self::new()
}
}
impl Default for Foo {
// FIXME: applicable here
fn default() -> Foo {
// FIXME: applicable here
Foo::new()
fn default() -> Self {
Self::new()
}
}
}
@ -74,13 +71,12 @@ mod lifetimes {
mod issue2894 {
trait IntoBytes {
#[allow(clippy::wrong_self_convention)]
fn into_bytes(&self) -> Vec<u8>;
fn to_bytes(&self) -> Vec<u8>;
}
// This should not be linted
impl IntoBytes for u8 {
fn into_bytes(&self) -> Vec<u8> {
fn to_bytes(&self) -> Vec<u8> {
vec![*self]
}
}
@ -90,11 +86,7 @@ mod existential {
struct Foo;
impl Foo {
// FIXME:
// TyKind::Def (used for `impl Trait` types) does not include type parameters yet.
// See documentation in rustc_hir::hir::TyKind.
// The hir tree walk stops at `impl Iterator` level and does not inspect &Foo.
fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
fn bad(foos: &[Self]) -> impl Iterator<Item = &Self> {
foos.iter()
}
@ -215,10 +207,8 @@ mod rustfix {
fn fun_1() {}
fn fun_2() {
// FIXME: applicable here
nested::A::fun_1();
// FIXME: applicable here
nested::A::A;
Self::fun_1();
Self::A;
Self {};
}
@ -239,8 +229,7 @@ mod issue3567 {
impl Test for TestStruct {
fn test() -> TestStruct {
// FIXME: applicable here
TestStruct::from_something()
Self::from_something()
}
}
}
@ -254,14 +243,12 @@ mod paths_created_by_lowering {
const A: usize = 0;
const B: usize = 1;
// FIXME: applicable here
async fn g() -> S {
async fn g() -> Self {
Self {}
}
fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
// FIXME: applicable here twice
&p[S::A..S::B]
&p[Self::A..Self::B]
}
}
@ -381,7 +368,6 @@ mod issue4305 {
impl<T: Foo> From<T> for Box<dyn Foo> {
fn from(t: T) -> Self {
// FIXME: applicable here
Box::new(t)
}
}
@ -461,8 +447,7 @@ mod nested_paths {
impl A<submod::C> {
fn test() -> Self {
// FIXME: applicable here
A::new::<submod::B>(submod::B {})
Self::new::<submod::B>(submod::B {})
}
}
}

View File

@ -3,7 +3,7 @@
#![warn(clippy::use_self)]
#![allow(dead_code)]
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into)]
fn main() {}
@ -15,15 +15,12 @@ mod use_self {
Foo {}
}
fn test() -> Foo {
// FIXME: applicable here
Foo::new()
}
}
impl Default for Foo {
// FIXME: applicable here
fn default() -> Foo {
// FIXME: applicable here
Foo::new()
}
}
@ -74,13 +71,12 @@ mod lifetimes {
mod issue2894 {
trait IntoBytes {
#[allow(clippy::wrong_self_convention)]
fn into_bytes(&self) -> Vec<u8>;
fn to_bytes(&self) -> Vec<u8>;
}
// This should not be linted
impl IntoBytes for u8 {
fn into_bytes(&self) -> Vec<u8> {
fn to_bytes(&self) -> Vec<u8> {
vec![*self]
}
}
@ -90,10 +86,6 @@ mod existential {
struct Foo;
impl Foo {
// FIXME:
// TyKind::Def (used for `impl Trait` types) does not include type parameters yet.
// See documentation in rustc_hir::hir::TyKind.
// The hir tree walk stops at `impl Iterator` level and does not inspect &Foo.
fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
foos.iter()
}
@ -215,9 +207,7 @@ mod rustfix {
fn fun_1() {}
fn fun_2() {
// FIXME: applicable here
nested::A::fun_1();
// FIXME: applicable here
nested::A::A;
nested::A {};
@ -239,7 +229,6 @@ mod issue3567 {
impl Test for TestStruct {
fn test() -> TestStruct {
// FIXME: applicable here
TestStruct::from_something()
}
}
@ -254,13 +243,11 @@ mod paths_created_by_lowering {
const A: usize = 0;
const B: usize = 1;
// FIXME: applicable here
async fn g() -> S {
S {}
}
fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
// FIXME: applicable here twice
&p[S::A..S::B]
}
}
@ -381,7 +368,6 @@ mod issue4305 {
impl<T: Foo> From<T> for Box<dyn Foo> {
fn from(t: T) -> Self {
// FIXME: applicable here
Box::new(t)
}
}
@ -461,7 +447,6 @@ mod nested_paths {
impl A<submod::C> {
fn test() -> Self {
// FIXME: applicable here
A::new::<submod::B>(submod::B {})
}
}

View File

@ -1,16 +1,16 @@
error: unnecessary structure name repetition
--> $DIR/use_self.rs:15:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
|
= note: `-D clippy::use-self` implied by `-D warnings`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:14:21
|
LL | fn new() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
= note: `-D clippy::use-self` implied by `-D warnings`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:15:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:17:22
@ -19,30 +19,43 @@ LL | fn test() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:96:24
--> $DIR/use_self.rs:18:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:23:25
|
LL | fn default() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:24:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:89:24
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:111:13
--> $DIR/use_self.rs:89:55
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:104:13
|
LL | TS(0)
| ^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:120:17
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
...
LL | use_self_expand!(); // Should lint in local macros
| ------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: unnecessary structure name repetition
--> $DIR/use_self.rs:119:25
--> $DIR/use_self.rs:112:25
|
LL | fn new() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
@ -53,82 +66,135 @@ LL | use_self_expand!(); // Should lint in local macros
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: unnecessary structure name repetition
--> $DIR/use_self.rs:144:21
--> $DIR/use_self.rs:113:17
|
LL | Bar { foo: Foo {} }
| ^^^ help: use the applicable keyword: `Self`
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
...
LL | use_self_expand!(); // Should lint in local macros
| ------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: unnecessary structure name repetition
--> $DIR/use_self.rs:143:29
--> $DIR/use_self.rs:136:29
|
LL | fn bar() -> Bar {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:156:13
--> $DIR/use_self.rs:137:21
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
LL | Bar { foo: Foo {} }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:155:21
--> $DIR/use_self.rs:148:21
|
LL | fn baz() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:173:21
--> $DIR/use_self.rs:149:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:166:21
|
LL | let _ = Enum::B(42);
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:174:21
--> $DIR/use_self.rs:167:21
|
LL | let _ = Enum::C { field: true };
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:175:21
--> $DIR/use_self.rs:168:21
|
LL | let _ = Enum::A;
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:222:13
--> $DIR/use_self.rs:210:13
|
LL | nested::A::fun_1();
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:211:13
|
LL | nested::A::A;
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:213:13
|
LL | nested::A {};
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:258:13
--> $DIR/use_self.rs:232:13
|
LL | TestStruct::from_something()
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:246:25
|
LL | async fn g() -> S {
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:247:13
|
LL | S {}
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:287:13
--> $DIR/use_self.rs:251:16
|
LL | Foo { value }
| ^^^ help: use the applicable keyword: `Self`
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:286:29
--> $DIR/use_self.rs:251:22
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:274:29
|
LL | fn foo(value: T) -> Foo<T> {
| ^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:324:21
--> $DIR/use_self.rs:275:13
|
LL | Foo { value }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:312:21
|
LL | type From = T::From;
| ^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:325:19
--> $DIR/use_self.rs:313:19
|
LL | type To = T::To;
| ^^^^^ help: use the applicable keyword: `Self`
error: aborting due to 20 previous errors
error: unnecessary structure name repetition
--> $DIR/use_self.rs:450:13
|
LL | A::new::<submod::B>(submod::B {})
| ^ help: use the applicable keyword: `Self`
error: aborting due to 31 previous errors

View File

@ -18,35 +18,36 @@ trait SelfTrait {
struct Bad;
impl SelfTrait for Bad {
fn refs(p1: &Bad) -> &Bad {
fn refs(p1: &Self) -> &Self {
p1
}
fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
p1
}
fn mut_refs(p1: &mut Bad) -> &mut Bad {
fn mut_refs(p1: &mut Self) -> &mut Self {
p1
}
fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
fn vals(_: Bad) -> Bad {
Bad::default()
fn vals(_: Self) -> Self {
Self::default()
}
}
impl Mul for Bad {
type Output = Self;
fn mul(self, rhs: Bad) -> Bad {
fn mul(self, rhs: Self) -> Self {
rhs
}
}
impl Clone for Bad {
fn clone(&self) -> Self {
// FIXME: applicable here
Bad
}
}

View File

@ -47,6 +47,7 @@ impl Mul for Bad {
impl Clone for Bad {
fn clone(&self) -> Self {
// FIXME: applicable here
Bad
}
}

View File

@ -1,10 +1,88 @@
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:21:18
|
LL | fn refs(p1: &Bad) -> &Bad {
| ^^^ help: use the applicable keyword: `Self`
|
= note: `-D clippy::use-self` implied by `-D warnings`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:21:27
|
LL | fn refs(p1: &Bad) -> &Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:25:33
|
LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:25:49
|
LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:29:26
|
LL | fn mut_refs(p1: &mut Bad) -> &mut Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:29:39
|
LL | fn mut_refs(p1: &mut Bad) -> &mut Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:33:24
|
LL | fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:33:42
|
LL | fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:35:16
|
LL | fn vals(_: Bad) -> Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:35:24
|
LL | fn vals(_: Bad) -> Bad {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:36:9
|
LL | Bad::default()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:41:19
|
LL | type Output = Bad;
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:43:23
|
= note: `-D clippy::use-self` implied by `-D warnings`
LL | fn mul(self, rhs: Bad) -> Bad {
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to previous error
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:43:31
|
LL | fn mul(self, rhs: Bad) -> Bad {
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 14 previous errors