- Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This code:
fn main() { let _ = Example { u: 0 }; } struct Example { u: u8, }
Produces this warning:
warning: field is never read: `u` --> src/main.rs:6:5 | 6 | u: u8, | ^^^^^ |
However, switching to a tuple struct:
fn main() { let _ = Example(0); } struct Example(u8);
Does not report a warning.
Original report misleadingly focusing on Debug
fn main() { dbg!(Example { a: 0 }); } #[derive(Debug)] struct Example { a: u8, }
produces
warning: field is never read: `a` --> src/main.rs:7:5 | 7 | a: u8, | ^^^^^ | = note: `#[warn(dead_code)]` on by default
However, switching to a tuple struct:
fn main() { dbg!(Example(0)); } #[derive(Debug)] struct Example(u8);
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)
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.