Open
Description
Code
#[derive(PartialEq)]
struct MyStruct {
x: i32,
y: i32, // no unused field warning, unfortunately
}
struct MyStruct2 {
x: i32,
y: i32, // warning today
}
pub fn use_struct() {
let ms = MyStruct { x: 1, y: 2 };
let _ = ms.x;
let ms = MyStruct2 { x: 1, y: 2 };
let _ = ms.x;
}
Current output
warning: field `y` is never read
--> src/lib.rs:9:5
|
7 | struct MyStruct2 {
| --------- field in this struct
8 | x: i32,
9 | y: i32, // warning today
| ^
|
= note: `#[warn(dead_code)]` on by default
Desired output
A warning for both MyStruct and MyStruct2.
Rationale and extra context
This was originally discussed on #84647 and #85200, although the conclusion there was to only exclude Debug and Clone.
However, it's really common to derive PartialEq on a type, especially when writing tests.
This means that adding tests can subtly stop this warning from catching issues. As far as I can see, there isn't a way to opt-in to stricter behaviour with either rustc or clippy here. There's no equivalent of must_use
for struct fields, for example.
This issue was the root of a nasty bug for me. Would you be open to making this diagnostic fire for more automatically derived traits?
Other cases
Rust Version
Reproduced on rustc 1.83 on the playground.
Anything else?
No response