1
Fork 0

Auto merge of #87026 - FabianWolff:issue-86948, r=estebank

Allow labeled loops as value expressions for `break`

Fixes #86948. This is currently allowed:
```rust
return 'label: loop { break 'label 42; };
break ('label: loop { break 'label 42; });
break 1 + 'label: loop { break 'label 42; };
break 'outer 'inner: loop { break 'inner 42; };
```
But not this:
```rust
break 'label: loop { break 'label 42; };
```
I have fixed this, so that the above now parses as an unlabeled break with a labeled loop as its value expression.
This commit is contained in:
bors 2021-08-04 07:17:25 +00:00
commit 49ca3d9796
6 changed files with 157 additions and 21 deletions

View file

@ -750,6 +750,14 @@ pub trait LintContext: Sized {
db.note(&format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`"));
}
}
BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => {
db.multipart_suggestion(
"wrap this expression in parentheses",
vec![(span.shrink_to_lo(), "(".to_string()),
(span.shrink_to_hi(), ")".to_string())],
Applicability::MachineApplicable
);
}
}
// Rewrap `db`, and pass control to the user.
decorate(LintDiagnosticBuilder::new(db));