Skip to content

dead_code lint does not trigger for tuple structs with unread fields #92790

@shepmaster

Description

@shepmaster

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.C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions