dead_code lint does not trigger for tuple structs with unread fields · Issue #92790 · rust-lang/rust (original) (raw)

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)