Closed
Description
Here's a short example:
enum Enum {
Variant {field: u32},
OtherVariant,
}
fn main() {
let whatever = Enum::Variant{field:0};
if let Enum::Variant {field} = whatever {
// field left unused
}
}
This produces the warning:
warning: unused variable: `field`
--> src/main.rs:8:25
|
8 | if let Enum::Variant {field} = whatever {
| ^^^^^
|
= note: #[warn(unused_variables)] on by default
= note: to avoid this warning, consider using `_field` instead
But changing it to _field
is an error because that's not the name of the field. The warning should probably suggest to use Enum::Variant {..}
instead.
This also occurs in explicit match statements and irrefutable let patterns – probably anywhere you can bind a field of a struct-like variant.