diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-06-05 23:34:11 +0400 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-06-05 23:34:11 +0400 |
| commit | f06f05174581702e822f1d866a06e0a6a22d0b3d (patch) | |
| tree | 9bb3bda5e3325f221387b858fcd580b898acb435 /compiler/rustc_parse/src/parser | |
| parent | c6e5bb32fbb3d0a85189e56086726c183f68ad0c (diff) | |
| download | rust-f06f05174581702e822f1d866a06e0a6a22d0b3d.tar.gz rust-f06f05174581702e822f1d866a06e0a6a22d0b3d.zip | |
Suggest removing label in `'label: non_block_expr`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 0d252c3d465..0bc71de90ff 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1557,6 +1557,8 @@ impl<'a> Parser<'a> { // Continue as an expression in an effort to recover on `'label: non_block_expr`. let expr = self.parse_expr().map(|expr| { + let span = expr.span; + let found_labeled_breaks = { struct FindLabeledBreaksVisitor(bool); @@ -1573,13 +1575,22 @@ impl<'a> Parser<'a> { vis.0 }; - // Suggestion involves adding a (as of time of writing this, unstable) labeled block - // so if the label is not used, just return the unmodified expression + // Suggestion involves adding a (as of time of writing this, unstable) labeled block. + // + // If there are no breaks that may use this label, suggest removing the label and + // recover to the unmodified expression. if !found_labeled_breaks { + let msg = "consider removing the label"; + err.span_suggestion_verbose( + lo.until(span), + msg, + "", + Applicability::MachineApplicable, + ); + return expr; } - let span = expr.span; let sugg_msg = "consider enclosing expression in a block"; let suggestions = vec