Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9596dc2

Browse files
committed
parse_labeled_expr: simplify
1 parent 3dbade6 commit 9596dc2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,24 +1069,22 @@ impl<'a> Parser<'a> {
10691069

10701070
fn parse_labeled_expr(&mut self, label: Label, attrs: AttrVec) -> PResult<'a, P<Expr>> {
10711071
let lo = label.ident.span;
1072+
let label = Some(label);
10721073
self.expect(&token::Colon)?;
10731074
if self.eat_keyword(kw::While) {
1074-
return self.parse_while_expr(Some(label), lo, attrs);
1075-
}
1076-
if self.eat_keyword(kw::For) {
1077-
return self.parse_for_expr(Some(label), lo, attrs);
1078-
}
1079-
if self.eat_keyword(kw::Loop) {
1080-
return self.parse_loop_expr(Some(label), lo, attrs);
1081-
}
1082-
if self.token == token::OpenDelim(token::Brace) {
1083-
return self.parse_block_expr(Some(label), lo, BlockCheckMode::Default, attrs);
1075+
self.parse_while_expr(label, lo, attrs)
1076+
} else if self.eat_keyword(kw::For) {
1077+
self.parse_for_expr(label, lo, attrs)
1078+
} else if self.eat_keyword(kw::Loop) {
1079+
self.parse_loop_expr(label, lo, attrs)
1080+
} else if self.check(&token::OpenDelim(token::Brace)) {
1081+
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
1082+
} else {
1083+
let msg = "expected `while`, `for`, `loop` or `{` after a label";
1084+
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
1085+
// Continue as an expression in an effort to recover on `'label: non_block_expr`.
1086+
self.parse_expr()
10841087
}
1085-
1086-
let msg = "expected `while`, `for`, `loop` or `{` after a label";
1087-
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
1088-
// Continue as an expression in an effort to recover on `'label: non_block_expr`.
1089-
self.parse_expr()
10901088
}
10911089

10921090
/// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.

0 commit comments

Comments
 (0)