I find the unreachable_statement to be a more informative lint (than irrefutable_pattern), and which would only appear if the if let construction were misused.
I've always had the following rule of mind:
if let $pattern = $expression $then_block $( else $else_block )?
// is equivalent to:
match $expression {
$pattern => $then_block,
_ => ($( $else_block )?),
}
which works for refutable patterns.
But when the if let construction is used with an irrefutable pattern, the above replacement does not apply, and instead unsugars to:
match $expression {
$irrefutable_pattern => $then_block,
}
i.e. the whole else $else_block does not make any sense here;
compiler-wise it could be seen as:
TL,DR: it should either trigger unreachable_code or unreachable_pattern (I prefer the latter, given the weird if true { ... } else { ... }-not-triggering-unreachable_code-lint current situation)
I don’t know if this is the right place, as this probably is not directly related to this specific release, but the new features made me try this bit of code, which doesn’t compile (and requires the quite useless if which will produce the warning instead). Is that expected? Shouldn’t let also accept a pattern, same as if let?
enum Creature {
Crab(String),
Lobster(String),
Person(String),
}
fn main() {
let state = Creature::Crab("Ferris".to_string());
let Creature::Crab(name) | Creature::Person(name) | Creature::Lobster(name) = state;
}