Label `if` and `match` statements

Hello, are there any reasons to not allow code like this?

'label: if let Some(_) = ... {
    break 'label;
}

Or

'label: match ... {
    _ => break 'label;
}

Instead you either need to wrap it in the additional block or restructure the code. If we already support labels, why not do it comprehensively?

Isn't this one allowed already?

5 Likes

Indeed

I continue to think that this not being allowed is a feature

While I think that label-break-value is an important thing for Rust to have, I also think that its frequency and prevalence should be low, at which point the extra block is a good thing to emphasize that something unusual is being used and its cost also isn't a major issue because it's rare.

If you really need a label-break-value, add the block. It's fine.

(Or, at least, if you want to convince me that this should be allowed, you're going to need a whole bunch of real examples where the label-break-value is both the right way to write it and the extra braces are a substantial problem -- not just a synthetic example that's so cut back that it doesn't actually need the break at all.)

11 Likes