External Publication
Visit Post

Q: Why do match expression need parenthesis for ops to the right but not left?

Rust Internals [Unofficial] April 2, 2026
Source

Quick question for my understanding, why is:

    num_apples * match num_apples.cmp(&40) {
        Ordering::Greater => 1u8 ,
        _ => 2u8,
    }

ok, but this is not ok:

     match num_apples.cmp(&40) {
        Ordering::Greater => 1u8 ,
        _ => 2u8,
    } * num_apples

the lack of ; means this should be an expression and the type of the first expression is known at compile so Mul should work, but it doesn't.

Discussion in the ATmosphere

Loading comments...