Skip to content

Commit 351688d

Browse files
committed
Improve tests and exclude nested impls
1 parent 7230768 commit 351688d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

clippy_lints/src/use_self.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
246246
| ItemKind::Static(..)
247247
| ItemKind::Enum(..)
248248
| ItemKind::Struct(..)
249-
| ItemKind::Union(..) => {
249+
| ItemKind::Union(..)
250+
| ItemKind::Impl(..) => {
250251
// Don't check statements that shadow `Self` or where `Self` can't be used
251252
},
252253
_ => walk_item(self, item),

tests/ui/use_self.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ mod nesting {
250250
struct Bar {
251251
foo: Foo, // Foo != Self
252252
}
253+
254+
impl Bar {
255+
fn bar() -> Bar {
256+
Bar {
257+
foo: Foo{},
258+
}
259+
}
260+
}
253261
}
254262
}
255263

@@ -258,7 +266,7 @@ mod nesting {
258266
}
259267
impl Enum {
260268
fn method() {
261-
use self::Enum::*;
269+
use self::Enum::*; // Issue 3425
262270
static STATIC: Enum = Enum::A; // Can't use Self as type
263271
}
264272
}

tests/ui/use_self.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,17 @@ LL | Foo {}
150150
LL | use_self_expand!(); // Should lint in local macros
151151
| ------------------- in this macro invocation
152152

153-
error: aborting due to 24 previous errors
153+
error: unnecessary structure name repetition
154+
--> $DIR/use_self.rs:255:29
155+
|
156+
LL | fn bar() -> Bar {
157+
| ^^^ help: use the applicable keyword: `Self`
158+
159+
error: unnecessary structure name repetition
160+
--> $DIR/use_self.rs:256:21
161+
|
162+
LL | Bar {
163+
| ^^^ help: use the applicable keyword: `Self`
164+
165+
error: aborting due to 26 previous errors
154166

0 commit comments

Comments
 (0)