Closed as duplicate of#88900
Description
Code
fn main() -> Result<(), Error> {
let _ = "x".parse::<usize>().map_err(Error::Int)?;
Ok(())
}
#[derive(Debug)]
enum Error {
Int(std::num::ParseIntError),
}
Current output
$ cargo r
Compiling non-dead-code v0.1.0 (/home/marijn/Code/Rust/non-dead-code)
warning: field `0` is never read
--> src/main.rs:8:9
|
8 | Int(std::num::ParseIntError),
| --- ^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
= note: `Error` 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
|
8 | Int(()),
| ~~
warning: `non-dead-code` (bin "non-dead-code") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
Running `/home/marijn/Code/Rust/non-dead-code/target/debug/non-dead-code`
Error: Int(ParseIntError { kind: InvalidDigit })
Desired output
$ cargo r
Compiling non-dead-code v0.1.0 (/home/marijn/Code/Rust/non-dead-code)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
Running `/home/marijn/Code/Rust/non-dead-code/target/debug/non-dead-code`
Error: Int(ParseIntError { kind: InvalidDigit })
Rationale and extra context
I am really confused why the compiler should think that this code is dead, as the output from running it shows that it is live, and replacing the field as suggested leads to less informative output when running.
Other cases
Rust Version
rustc 1.83.0-nightly (90b35a623 2024-11-26) (gentoo)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.5
Anything else?
No response