Merge pull request #1965 from montrivo/use_self
lint #1674: replace struct name with `Self` when applicable
This commit is contained in:
commit
d1eecbaa2f
4 changed files with 178 additions and 0 deletions
45
tests/ui/use_self.rs
Normal file
45
tests/ui/use_self.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
#![warn(use_self)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
||||
fn main() {}
|
||||
|
||||
mod use_self {
|
||||
struct Foo {}
|
||||
|
||||
impl Foo {
|
||||
fn new() -> Foo {
|
||||
Foo {}
|
||||
}
|
||||
fn test() -> Foo {
|
||||
Foo::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Foo {
|
||||
fn default() -> Foo {
|
||||
Foo::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod better {
|
||||
struct Foo {}
|
||||
|
||||
impl Foo {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn test() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Foo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
40
tests/ui/use_self.stderr
Normal file
40
tests/ui/use_self.stderr
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:13:21
|
||||
|
|
||||
13 | fn new() -> Foo {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
|
||||
= note: `-D use-self` implied by `-D warnings`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:14:13
|
||||
|
|
||||
14 | Foo {}
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:16:22
|
||||
|
|
||||
16 | fn test() -> Foo {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:17:13
|
||||
|
|
||||
17 | Foo::new()
|
||||
| ^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:22:25
|
||||
|
|
||||
22 | fn default() -> Foo {
|
||||
| ^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:23:13
|
||||
|
|
||||
23 | Foo::new()
|
||||
| ^^^^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue