mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Fix use_self
false positive on nested functions
This commit is contained in:
parent
1cdac4a9c7
commit
187ce4c5ab
@ -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),
|
||||
|
@ -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 {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user