Closed
Description
This code should compile without warnings:
enum Enum {
Variant { field: usize }
}
impl Enum {
fn read_field(self) -> usize {
match self {
// Enum::Variant { field } => field
Self::Variant { field } => field
}
}
}
fn main() {
let e = Enum::Variant { field: 42 };
println!("{}", e.read_field());
}
However, it produces the following one:
warning: field is never used: `field`
--> src/main.rs:2:15
|
2 | Variant { field: usize }
| ^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
If we switch the pattern within match
to the one that's commented out, the warning is gone.