rustc_ast::util::classify

Function leading_labeled_expr

source
pub fn leading_labeled_expr(expr: &Expr) -> bool
Expand description

Returns whether the leftmost token of the given expression is the label of a labeled loop or block, such as in 'inner: loop { break 'inner 1 } + 1.

Such expressions are not allowed as the value of an unlabeled break.

'outer: {
    break 'inner: loop { break 'inner 1 } + 1;  // invalid syntax

    break 'outer 'inner: loop { break 'inner 1 } + 1;  // okay

    break ('inner: loop { break 'inner 1 } + 1);  // okay

    break ('inner: loop { break 'inner 1 }) + 1;  // okay
}