Fix use_self false positive on nested functions

This commit is contained in:
Taiki Endo 2019-03-11 23:24:49 +09:00
parent 1cdac4a9c7
commit 187ce4c5ab
4 changed files with 38 additions and 5 deletions

View file

@ -248,7 +248,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
| ItemKind::Enum(..)
| ItemKind::Struct(..)
| ItemKind::Union(..)
| ItemKind::Impl(..) => {
| ItemKind::Impl(..)
| ItemKind::Fn(..) => {
// Don't check statements that shadow `Self` or where `Self` can't be used
},
_ => walk_item(self, item),

View file

@ -249,6 +249,16 @@ mod nesting {
Self { foo: Foo {} }
}
}
// Can't use Self here
fn baz() -> Foo {
Foo {}
}
}
// Should lint here
fn baz() -> Self {
Self {}
}
}

View file

@ -249,6 +249,16 @@ mod nesting {
Bar { foo: Foo {} }
}
}
// Can't use Self here
fn baz() -> Foo {
Foo {}
}
}
// Should lint here
fn baz() -> Foo {
Foo {}
}
}

View file

@ -150,6 +150,18 @@ LL | Foo {}
LL | use_self_expand!(); // Should lint in local macros
| ------------------- in this macro invocation
error: unnecessary structure name repetition
--> $DIR/use_self.rs:260:21
|
LL | fn baz() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:261:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:248:29
|
@ -163,22 +175,22 @@ LL | Bar { foo: Foo {} }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:293:13
--> $DIR/use_self.rs:303:13
|
LL | nested::A::fun_1();
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:294:13
--> $DIR/use_self.rs:304:13
|
LL | nested::A::A;
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:296:13
--> $DIR/use_self.rs:306:13
|
LL | nested::A {};
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: aborting due to 29 previous errors
error: aborting due to 31 previous errors