mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Auto merge of #5033 - JohnTitor:split-use-self, r=flip1995
Split up `use_self` ui test Part of #2038 changelog: none
This commit is contained in:
commit
05cb0df748
6 changed files with 342 additions and 332 deletions
|
@ -69,117 +69,6 @@ mod lifetimes {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::boxed_local)]
|
||||
mod traits {
|
||||
|
||||
use std::ops::Mul;
|
||||
|
||||
trait SelfTrait {
|
||||
fn refs(p1: &Self) -> &Self;
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self;
|
||||
fn nested(p1: Box<Self>, p2: (&u8, &Self));
|
||||
fn vals(r: Self) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bad;
|
||||
|
||||
impl SelfTrait for Bad {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Bad {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Bad {
|
||||
fn clone(&self) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Good;
|
||||
|
||||
impl SelfTrait for Good {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Good {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
trait NameTrait {
|
||||
fn refs(p1: &u8) -> &u8;
|
||||
fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
|
||||
fn mut_refs(p1: &mut u8) -> &mut u8;
|
||||
fn nested(p1: Box<u8>, p2: (&u8, &u8));
|
||||
fn vals(p1: u8) -> u8;
|
||||
}
|
||||
|
||||
// Using `Self` instead of the type name is OK
|
||||
impl NameTrait for u8 {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue2894 {
|
||||
trait IntoBytes {
|
||||
fn into_bytes(&self) -> Vec<u8>;
|
||||
|
|
|
@ -69,117 +69,6 @@ mod lifetimes {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::boxed_local)]
|
||||
mod traits {
|
||||
|
||||
use std::ops::Mul;
|
||||
|
||||
trait SelfTrait {
|
||||
fn refs(p1: &Self) -> &Self;
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self;
|
||||
fn nested(p1: Box<Self>, p2: (&u8, &Self));
|
||||
fn vals(r: Self) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bad;
|
||||
|
||||
impl SelfTrait for Bad {
|
||||
fn refs(p1: &Bad) -> &Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Bad) -> &mut Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
|
||||
|
||||
fn vals(_: Bad) -> Bad {
|
||||
Bad::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Bad {
|
||||
type Output = Bad;
|
||||
|
||||
fn mul(self, rhs: Bad) -> Bad {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Bad {
|
||||
fn clone(&self) -> Self {
|
||||
Bad
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Good;
|
||||
|
||||
impl SelfTrait for Good {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Good {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
trait NameTrait {
|
||||
fn refs(p1: &u8) -> &u8;
|
||||
fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
|
||||
fn mut_refs(p1: &mut u8) -> &mut u8;
|
||||
fn nested(p1: Box<u8>, p2: (&u8, &u8));
|
||||
fn vals(p1: u8) -> u8;
|
||||
}
|
||||
|
||||
// Using `Self` instead of the type name is OK
|
||||
impl NameTrait for u8 {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue2894 {
|
||||
trait IntoBytes {
|
||||
fn into_bytes(&self) -> Vec<u8>;
|
||||
|
|
|
@ -37,109 +37,19 @@ LL | Foo::new()
|
|||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:89:22
|
||||
|
|
||||
LL | fn refs(p1: &Bad) -> &Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:89:31
|
||||
|
|
||||
LL | fn refs(p1: &Bad) -> &Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:93:37
|
||||
|
|
||||
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.rs:93:53
|
||||
|
|
||||
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.rs:97:30
|
||||
|
|
||||
LL | fn mut_refs(p1: &mut Bad) -> &mut Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:97:43
|
||||
|
|
||||
LL | fn mut_refs(p1: &mut Bad) -> &mut Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:101:28
|
||||
|
|
||||
LL | fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:101:46
|
||||
|
|
||||
LL | fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:103:20
|
||||
|
|
||||
LL | fn vals(_: Bad) -> Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:103:28
|
||||
|
|
||||
LL | fn vals(_: Bad) -> Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:104:13
|
||||
|
|
||||
LL | Bad::default()
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:109:23
|
||||
|
|
||||
LL | type Output = Bad;
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:111:27
|
||||
|
|
||||
LL | fn mul(self, rhs: Bad) -> Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:111:35
|
||||
|
|
||||
LL | fn mul(self, rhs: Bad) -> Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:118:13
|
||||
|
|
||||
LL | Bad
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:200:56
|
||||
--> $DIR/use_self.rs:89:56
|
||||
|
|
||||
LL | fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:215:13
|
||||
--> $DIR/use_self.rs:104:13
|
||||
|
|
||||
LL | TS(0)
|
||||
| ^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:223:25
|
||||
--> $DIR/use_self.rs:112:25
|
||||
|
|
||||
LL | fn new() -> Foo {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
@ -148,7 +58,7 @@ LL | use_self_expand!(); // Should lint in local macros
|
|||
| ------------------- in this macro invocation
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:224:17
|
||||
--> $DIR/use_self.rs:113:17
|
||||
|
|
||||
LL | Foo {}
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
@ -157,94 +67,94 @@ LL | use_self_expand!(); // Should lint in local macros
|
|||
| ------------------- in this macro invocation
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:259: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:260:13
|
||||
--> $DIR/use_self.rs:149:13
|
||||
|
|
||||
LL | Foo {}
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:247: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:248:21
|
||||
--> $DIR/use_self.rs:137:21
|
||||
|
|
||||
LL | Bar { foo: Foo {} }
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:277:21
|
||||
--> $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:278: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:279: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:310:13
|
||||
--> $DIR/use_self.rs:199:13
|
||||
|
|
||||
LL | nested::A::fun_1();
|
||||
| ^^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:311:13
|
||||
--> $DIR/use_self.rs:200:13
|
||||
|
|
||||
LL | nested::A::A;
|
||||
| ^^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:313:13
|
||||
--> $DIR/use_self.rs:202:13
|
||||
|
|
||||
LL | nested::A {};
|
||||
| ^^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:332:13
|
||||
--> $DIR/use_self.rs:221:13
|
||||
|
|
||||
LL | TestStruct::from_something()
|
||||
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:346:25
|
||||
--> $DIR/use_self.rs:235:25
|
||||
|
|
||||
LL | async fn g() -> S {
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:347:13
|
||||
--> $DIR/use_self.rs:236:13
|
||||
|
|
||||
LL | S {}
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:351:16
|
||||
--> $DIR/use_self.rs:240:16
|
||||
|
|
||||
LL | &p[S::A..S::B]
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:351:22
|
||||
--> $DIR/use_self.rs:240:22
|
||||
|
|
||||
LL | &p[S::A..S::B]
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: aborting due to 40 previous errors
|
||||
error: aborting due to 25 previous errors
|
||||
|
||||
|
|
114
tests/ui/use_self_trait.fixed
Normal file
114
tests/ui/use_self_trait.fixed
Normal file
|
@ -0,0 +1,114 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::use_self)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::should_implement_trait, clippy::boxed_local)]
|
||||
|
||||
use std::ops::Mul;
|
||||
|
||||
trait SelfTrait {
|
||||
fn refs(p1: &Self) -> &Self;
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self;
|
||||
fn nested(p1: Box<Self>, p2: (&u8, &Self));
|
||||
fn vals(r: Self) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bad;
|
||||
|
||||
impl SelfTrait for Bad {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Bad {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Bad {
|
||||
fn clone(&self) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Good;
|
||||
|
||||
impl SelfTrait for Good {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Good {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
trait NameTrait {
|
||||
fn refs(p1: &u8) -> &u8;
|
||||
fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
|
||||
fn mut_refs(p1: &mut u8) -> &mut u8;
|
||||
fn nested(p1: Box<u8>, p2: (&u8, &u8));
|
||||
fn vals(p1: u8) -> u8;
|
||||
}
|
||||
|
||||
// Using `Self` instead of the type name is OK
|
||||
impl NameTrait for u8 {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
114
tests/ui/use_self_trait.rs
Normal file
114
tests/ui/use_self_trait.rs
Normal file
|
@ -0,0 +1,114 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::use_self)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::should_implement_trait, clippy::boxed_local)]
|
||||
|
||||
use std::ops::Mul;
|
||||
|
||||
trait SelfTrait {
|
||||
fn refs(p1: &Self) -> &Self;
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self;
|
||||
fn nested(p1: Box<Self>, p2: (&u8, &Self));
|
||||
fn vals(r: Self) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bad;
|
||||
|
||||
impl SelfTrait for Bad {
|
||||
fn refs(p1: &Bad) -> &Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Bad) -> &mut Bad {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
|
||||
|
||||
fn vals(_: Bad) -> Bad {
|
||||
Bad::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Bad {
|
||||
type Output = Bad;
|
||||
|
||||
fn mul(self, rhs: Bad) -> Bad {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Bad {
|
||||
fn clone(&self) -> Self {
|
||||
Bad
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Good;
|
||||
|
||||
impl SelfTrait for Good {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Good {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
rhs
|
||||
}
|
||||
}
|
||||
|
||||
trait NameTrait {
|
||||
fn refs(p1: &u8) -> &u8;
|
||||
fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
|
||||
fn mut_refs(p1: &mut u8) -> &mut u8;
|
||||
fn nested(p1: Box<u8>, p2: (&u8, &u8));
|
||||
fn vals(p1: u8) -> u8;
|
||||
}
|
||||
|
||||
// Using `Self` instead of the type name is OK
|
||||
impl NameTrait for u8 {
|
||||
fn refs(p1: &Self) -> &Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn mut_refs(p1: &mut Self) -> &mut Self {
|
||||
p1
|
||||
}
|
||||
|
||||
fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
|
||||
|
||||
fn vals(_: Self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
94
tests/ui/use_self_trait.stderr
Normal file
94
tests/ui/use_self_trait.stderr
Normal file
|
@ -0,0 +1,94 @@
|
|||
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
|
||||
|
|
||||
LL | fn mul(self, rhs: Bad) -> Bad {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
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: unnecessary structure name repetition
|
||||
--> $DIR/use_self_trait.rs:50:9
|
||||
|
|
||||
LL | Bad
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
Loading…
Reference in a new issue