rust-lang / rust-lang/rust-clippy
dead_code lint is triggered when a field is only used in Debug impls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I upgraded our project from 1.56.1 to 1.58.1 and got a lot of new warnings about dead code because fields are never read. It seems that the fields in question are used only in Debug impls. This is still a usage so the lint should not trigger.
Lint Name
dead_code
Reproducer
I tried this code:
#[derive(Debug)]
struct Foo {
a: &'static str,
}
fn main() {
let foo = Foo { a: "hello" };
println!("{:?}", foo);
}
I saw this happen:
warning: field is never read: `a`
--> src/main.rs:4:5
|
4 | a: &'static str,
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
I expected this to happen:
No warnings.
Version
rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied Rust reproducer with the affected compiler versions and inspect how dead_code handles fields used only by Debug implementations. Add a regression test for the derive(Debug) case and verify that it produces no dead_code warning while unrelated unused fields remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100