There’s still an unfortunate ‘sour-spot’ (what’s the opposite of a sweet spot?) where you want to do a complicated match that you don’t want to write twice, but you want easy access to the failing cases. Let’s use something nice and complex like syn::Expr, and assume I only care about the syn::ExprWhile case. Then it’s much nicer to do this:
let Expr::ExprWhile(ExprWhile {
ref attrs,
ref cond,
ref body,
..
}) = expr else match {
Expr::ExprWhileLet(_) | Expr::ExprLoop(_) =>
bail!("use normal while loops!"),
other => bail!("Expected a loop, got {:?}", other),
};
Than it is to try and extract out the bindings in a normal if let or match and return them. For reference, I think the equivalent of the above is:
let (attrs, cond, body) = match expr {
Expr::ExprWhile(ExprWhile {
ref attrs,
ref cond,
ref body,
..
} => (attrs, cond, body),
Expr::ExprWhileLet(_) | Expr::ExprLoop(_) =>
bail!("use normal while loops!"),
other => bail!("Expected a loop, got {:?}", other),
};
Which I hope you agree would get annoying to maintain if you wanted to change the match.