Open quadrupleslap opened 7 years ago
I think the underlying problem here is that we continue to reason about the enum variant after passing to external code (e.g., C code).
Hey there! I've been wanting to get my feet wet with rustc, figured I'd start to see if I can fix this issue.
From what I can see, there's several options that would mitigate this issue:
For the last option, this'd mean the following:
use helpers::Animal;
#[forbid(dead_code)]
mod helpers {
#[repr(u32)]
pub enum Animal {
Cat = 0, // Used: constructed
Dog = 1, // Used: as pattern
Frog = 2 // Error: variant is never used
}
}
fn main() {
let animal = Animal::Cat;
match animal {
Animal::Dog => println!("Woof!"),
_ => println!("Something else.")
}
}
For the last option, we would additionally need to figure out whether we want this to apply to just enums or also ADTs with associated data.
Edit: The last option would also solve #56750.
It looks like the dead code lint is too eager, and doesn't consider two signs that the variants are used:
Playground
Expected: A clean build (I think.)
What I got: