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

warn(dead_code) incorrectly on derive(Debug) #135422

Closed
yonilerner opened this issue Jan 13, 2025 · 2 comments
Closed

warn(dead_code) incorrectly on derive(Debug) #135422

yonilerner opened this issue Jan 13, 2025 · 2 comments

Comments

@yonilerner
Copy link

I tried this code:

#[derive(Debug)]
enum Foo {
    Bar(String)
}

fn main() {
    let foo = Foo::Bar("hi".to_string());
    println!("{:?}", foo);
}

I expected to see this happen: The code should output Bar("hi") with no compiler warnings.

Instead, this happened: The code does output Bar("hi"), but there is the following compiler warning:

warning: field `0` is never read
 --> src/main.rs:3:9
  |
3 |     Bar(String)
  |     --- ^^^^^^
  |     |
  |     field in this variant
  |
  = note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
3 |     Bar(())
  |         ~~

warning: `playground` (bin "playground") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.83s
     Running `target/debug/playground`

Meta

Heres a playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9b6d2f66e6c8037781a45025529fdb14

At the current moment of testing, playground is using:
1.86.0-nightly (2025-01-11 eb54a50)

@yonilerner yonilerner added the C-bug Category: This is a bug. label Jan 13, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 13, 2025
@theemathas
Copy link
Contributor

Not a bug. The error message you posted contains this explanation:

note: Foo has a derived impl for the trait Debug, but this is intentionally ignored during dead code analysis

@jieyouxu
Copy link
Member

This is indeed intentional and a duplicate of #88900.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2025
@jieyouxu jieyouxu removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants