-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anthony Huang
committed
Jun 29, 2021
1 parent
c9ae73e
commit 2481835
Showing
3 changed files
with
65 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,50 @@ | ||
#![warn(clippy::self_named_constructor)] | ||
|
||
struct Foo {} | ||
struct Q; | ||
|
||
impl Foo { | ||
pub fn foo() -> Foo { | ||
Foo {} | ||
impl Q { | ||
pub fn q() -> Q { | ||
Q | ||
} | ||
|
||
fn r() -> R { | ||
R | ||
} | ||
} | ||
|
||
struct Bar {} | ||
struct R; | ||
|
||
impl Bar { | ||
pub fn new() -> Bar { | ||
Bar {} | ||
impl R { | ||
pub fn new() -> R { | ||
R | ||
} | ||
} | ||
|
||
struct FooBar {} | ||
struct V; | ||
|
||
impl FooBar { | ||
pub fn foobar() -> FooBar { | ||
FooBar {} | ||
impl V { | ||
pub fn v() -> R { | ||
R | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Default {} | ||
struct U; | ||
|
||
trait T { | ||
type Item; | ||
} | ||
|
||
impl Foo { | ||
fn bar() -> Bar { | ||
Bar {} | ||
impl T for U { | ||
type Item = Self; | ||
} | ||
|
||
impl U { | ||
pub fn u() -> impl T<Item = Self> { | ||
U | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Default; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,32 @@ | ||
error: constructor `foo` has the same name as the type | ||
error: constructor `q` has the same name as the type | ||
--> $DIR/self_named_constructor.rs:6:5 | ||
| | ||
LL | / pub fn foo() -> Foo { | ||
LL | | Foo {} | ||
LL | / pub fn q() -> Q { | ||
LL | | Q | ||
LL | | } | ||
| |_____^ | ||
| | ||
= note: `-D clippy::self-named-constructor` implied by `-D warnings` | ||
help: consider renaming `foo()` to `new()` | ||
help: consider renaming `q()` to `new()` | ||
--> $DIR/self_named_constructor.rs:6:5 | ||
| | ||
LL | / pub fn foo() -> Foo { | ||
LL | | Foo {} | ||
LL | | } | ||
| |_____^ | ||
|
||
error: constructor `foobar` has the same name as the type | ||
--> $DIR/self_named_constructor.rs:22:5 | ||
| | ||
LL | / pub fn foobar() -> FooBar { | ||
LL | | FooBar {} | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: consider renaming `foobar()` to `new()` | ||
--> $DIR/self_named_constructor.rs:22:5 | ||
| | ||
LL | / pub fn foobar() -> FooBar { | ||
LL | | FooBar {} | ||
LL | / pub fn q() -> Q { | ||
LL | | Q | ||
LL | | } | ||
| |_____^ | ||
|
||
error: constructor `default` has the same name as the type | ||
--> $DIR/self_named_constructor.rs:27:10 | ||
--> $DIR/self_named_constructor.rs:47:10 | ||
| | ||
LL | #[derive(Default)] | ||
| ^^^^^^^ | ||
| | ||
help: consider renaming `default()` to `new()` | ||
--> $DIR/self_named_constructor.rs:27:10 | ||
--> $DIR/self_named_constructor.rs:47:10 | ||
| | ||
LL | #[derive(Default)] | ||
| ^^^^^^^ | ||
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 2 previous errors | ||
|