-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dead_code lint does not trigger for tuple structs with unread fields #92790
Comments
This has nothing to do with the fn main() {
let _ = Example { u: 0 };
}
struct Example {
u: u8,
}
but
gives no warning. |
@FabianWolff oh dear. Thanks! I've updated the title and original post; sorry for the false ping. |
Not a regression AFAIK, but seems like worth prioritizing. |
I agree. I did a quick test across Rust 1.{0,10,20,30,40,50}.0 and none of them reported the lint. |
Thanks for checking! |
This behavior does indeed date back to the very beginning of the detection of dead struct fields (commit 0271224 in 2014). The culprit is line 621 in rust/compiler/rustc_passes/src/dead.rs Lines 618 to 625 in 72e74d7
Commenting out this line with the above tuple struct example gives:
I can open a PR for this, or is there a reason anyone here can think of why dead tuple struct fields shouldn't get a warning? @rustbot claim |
I can't think of one, so opening a PR seems good. |
FWIW, I find the example with |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-medium |
One thought is that deleting a dead tuple field may be non-trivial, if it is not the last field. E.g., imagine if someone got:
You can't simply delete the dead field. You have to also renumber all the uses of |
… r=estebank Warn about dead tuple struct fields Continuation of rust-lang#92972. Fixes rust-lang#92790. The language team has already commented on this in rust-lang#92972 (comment); I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (rust-lang#92972 (comment)), so error messages look like this: ``` error: field is never read: `1` --> $DIR/tuple-struct-field.rs:6:21 | LL | struct Wrapper(i32, [u8; LEN], String); | ^^^^^^^^^ | help: change the field to unit type to suppress this warning while preserving the field numbering | LL | struct Wrapper(i32, (), String); | ~~ ``` r? `@joshtriplett`
Thank you @FabianWolff ! |
This code:
Produces this warning:
However, switching to a tuple struct:
Does not report a warning.
Original report misleadingly focusing on
Debug
produces
However, switching to a tuple struct:
does not produce the warning.
/cc @FabianWolff
/cc #85200; #84647; #88900
Meta
Rustc 1.57.0 and 1.60.0-nightly (2022-01-10 89b9f7b)
The text was updated successfully, but these errors were encountered: