From 351688db78823cc53e88bc22cbe35c2342daf80a Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Mon, 7 Jan 2019 14:11:53 +0100 Subject: [PATCH] Improve tests and exclude nested impls --- clippy_lints/src/use_self.rs | 3 ++- tests/ui/use_self.rs | 10 +++++++++- tests/ui/use_self.stderr | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 17078141af11..5ec809f1b76c 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 f3bd4a05005b..464dd8143292 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 6c5dbf9111d6..a388579c9a3a 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