Closed as not planned
Description
Consider the following code (playground):
enum E {
A(usize),
B(usize),
}
impl E {
fn as_usize(&self) -> usize {
match *self {
E::A(a) => a,
E::B(b) => b,
}
}
}
fn main() {
let _ = E::B(1); // ignore warn(dead_code) on the B variant
let e = E::A(1);
match e {
E::A(x) => x,
x => x.as_usize(),
};
}
This code gives no warnings. However, the as_usize()
method is entirely useless, because the match can be rewritten to be more specific:
match e {
E::A(x) => x,
E::B(x) => x,
};
The compiler should give a warning in such a case.