diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 17078141a..5ec809f1b 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -246,7 +246,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { | ItemKind::Static(..) | ItemKind::Enum(..) | ItemKind::Struct(..) - | ItemKind::Union(..) => { + | ItemKind::Union(..) + | ItemKind::Impl(..) => { // Don't check statements that shadow `Self` or where `Self` can't be used }, _ => walk_item(self, item), diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index f3bd4a050..464dd8143 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -250,6 +250,14 @@ mod nesting { struct Bar { foo: Foo, // Foo != Self } + + impl Bar { + fn bar() -> Bar { + Bar { + foo: Foo{}, + } + } + } } } @@ -258,7 +266,7 @@ mod nesting { } impl Enum { fn method() { - use self::Enum::*; + use self::Enum::*; // Issue 3425 static STATIC: Enum = Enum::A; // Can't use Self as type } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 6c5dbf911..a388579c9 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -150,5 +150,17 @@ LL | Foo {} LL | use_self_expand!(); // Should lint in local macros | ------------------- in this macro invocation -error: aborting due to 24 previous errors +error: unnecessary structure name repetition + --> $DIR/use_self.rs:255:29 + | +LL | fn bar() -> Bar { + | ^^^ help: use the applicable keyword: `Self` + +error: unnecessary structure name repetition + --> $DIR/use_self.rs:256:21 + | +LL | Bar { + | ^^^ help: use the applicable keyword: `Self` + +error: aborting due to 26 previous errors