Closed
Description
Summary
false positive with derivable_impl
if
Default
is implemented manually to a struct havingBox<dyn Trait>
field, and- A type being used in the
Default
implementation implementsDefault
Lint Name
derivable_impl
Reproducer
I tried this code:
pub trait T {}
#[derive(Default)]
pub struct S {}
impl T for S {}
pub struct Outer {
pub inner: Box<dyn T>,
}
impl Default for Outer {
fn default() -> Self {
Outer {
inner: Box::<S>::default(),
}
}
}
I saw this happen:
warning: this `impl` can be derived
--> src/lib.rs:11:1
|
11 | / impl Default for Outer {
12 | | fn default() -> Self {
13 | | Outer {
14 | | inner: Box::<S>::default(),
15 | | }
16 | | }
17 | | }
| |_^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
= note: `#[warn(clippy::derivable_impls)]` on by default
= help: remove the manual implementation...
help: ...and instead derive it
|
7 | #[derive(Default)]
|
I expected to see this happen: derivable_impl
is not invoked.
Version
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: aarch64-apple-darwin
release: 1.66.0
LLVM version: 15.0.2
Additional Labels
No response