Q: Why do match expression need parenthesis for ops to the right but not left?
Rust Internals [Unofficial]
April 8, 2026
This is probably a somewhat stupid question, but why does match (or if for that mapneed a statement form at all? Why can't it just be expression whose value is discarded if used with a ;?
Do things like
let foo;
match bar {
Some(_) => foo = 1;
None => foo = 0;
}
// foo is now initialized
not work with expressions? I suppose I've never tried, but I don't immediately see a strong reason they couldn't.
EDIT: sorry I've realized I just answered my own question, it's so that they can used without a ; that they have a statement form, I got tripped up by the context.
Discussion in the ATmosphere