Closed
Description
Given the following code: [playground]
#[derive(Default)]
struct T {}
struct U {}
The current output is:
warning: struct `U` is never constructed
--> src/lib.rs:4:8
|
4 | struct U {}
| ^
|
= note: `#[warn(dead_code)]` on by default
Ideally the output should look like:
warning: struct `T` is never constructed
--> src/lib.rs:2:8
|
2 | struct T {}
| ^
|
= note: `#[warn(dead_code)]` on by default
warning: struct `U` is never constructed
--> src/lib.rs:4:8
|
4 | struct U {}
| ^
After the derive, the code looks roughly like
struct T {}
#[automatically_derived]
impl Default for T {
#[inline]
fn default() -> T { T {} }
}
struct U {}
As the default implementation is both 1) itself unused and 2) #[automatically_derived]
, ideally it should not count as a use for suppressing the dead_code
lint on T
.
The derived implementations for Clone
, Debug
, PartialEq
, and Hash
also show this behavior.
I seem to recall a previous change to #[automatically_derived]
to change the interaction between the unused code lint and derived implementations, but could not find it offhand.
Activity
matthiaskrgr commentedon Jul 4, 2022
Probably a duplicate of #47851
CAD97 commentedon Jul 4, 2022
Definitely related but maybe not a duplicate; #47851 is about explicit impls whereas this is a subset for just
#[automatically_derived]
impls.compiler-errors commentedon Jul 4, 2022
I thought the dead code lint (or other lints?) actually mentioned they didn't do this explicitly. Like, "this lint ignores automatic derives" or something.
compiler-errors commentedon Jul 4, 2022
Ah, unused field lint does:
Auto merge of rust-lang#126302 - mu001999-contrib:ignore/default, r=m…
Rollup merge of rust-lang#126302 - mu001999-contrib:ignore/default, r…
Unrolled build for rust-lang#126302