Auto merge of #3869 - taiki-e:use_self, r=flip1995
Fix `use_self` false positive on nested functions Related to https://github.com/rust-lang/rust-clippy/pull/3640 The current `use_self` warns the following code. ```rust #![warn(clippy::use_self)] struct Foo {} impl Foo { fn bar() { fn baz() -> Foo { //^ warning: unnecessary structure name repetition Foo {} //^ warning: unnecessary structure name repetition } } } ```
This commit is contained in:
commit
8fc0a738e3
@ -248,7 +248,8 @@ fn visit_item(&mut self, item: &'tcx Item) {
|
||||
| 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 @@ fn bar() -> Bar {
|
||||
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