Skip to content
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 is triggered when a field is only used in Debug impls #8353

Open
peterjoel opened this issue Jan 26, 2022 · 2 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@peterjoel
Copy link

peterjoel commented Jan 26, 2022

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

@peterjoel peterjoel added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 26, 2022
@PatchMixolydic
Copy link
Contributor

This was also reported in the rustc repo (the dead_code lint is handled by rustc) in rust-lang/rust#88900. This appears to have been an intentional (albeit contentious) change made in rust-lang/rust#85200.

@samueltardieu
Copy link
Contributor

Should this issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants