Closed
Description
The new_without_default
lint (indirectly) points at an impl block containing the new()
method and suggests something to insert. However because the name is "fully qualified" if you insert the suggested impl Default
alongside the impl block, it will not compile.
I tried this code:
pub mod submod {
pub struct Foo<T> {
_bar: *mut T,
}
impl<T> Foo<T> {
pub fn new() -> Self {
todo!()
}
}
}
I expected to see this happen:
warning: you should consider adding a `Default` implementation for `submod::Foo<T>`
--> src/lib.rs:7:9
|
7 | / pub fn new() -> Self {
8 | | todo!()
9 | | }
| |_________^
|
= note: `#[warn(clippy::new_without_default)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try this
|
6 | impl<T> Default for Foo<T> {
7 | fn default() -> Self {
8 | Self::new()
9 | }
10| }
11|
...
Instead, this happened (specifically note the qualified submod::Foo
in the suggested impl):
warning: you should consider adding a `Default` implementation for `submod::Foo<T>`
--> src/lib.rs:7:9
|
7 | / pub fn new() -> Self {
8 | | todo!()
9 | | }
| |_________^
|
= note: `#[warn(clippy::new_without_default)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try this
|
6 | impl<T> Default for submod::Foo<T> {
7 | fn default() -> Self {
8 | Self::new()
9 | }
10| }
11|
...
Meta
cargo clippy -V
: clippy 0.1.54 (5c02926 2021-05-11)rustc -Vv
:
rustc 1.54.0-nightly (5c02926 2021-05-11)
binary: rustc
commit-hash: 5c02926
commit-date: 2021-05-11
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1
<!-- TRIAGEBOT_START -->
<!-- TRIAGEBOT_ASSIGN_START -->
<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"xFrednet"}$$TRIAGEBOT_ASSIGN_DATA_END -->
<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->