diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-05 01:47:15 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-10 08:32:34 +0100 |
| commit | 9596dc2a47861d73996a550cba7caf55b2737c17 (patch) | |
| tree | 84376a02fcdefcb5bf8fc0a75c11f5bcee8721b4 | |
| parent | 3dbade652ed8ebac70f903e01f51cd92c4e4302c (diff) | |
| download | rust-9596dc2a47861d73996a550cba7caf55b2737c17.tar.gz rust-9596dc2a47861d73996a550cba7caf55b2737c17.zip | |
parse_labeled_expr: simplify
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 16ea2773b20..e0e6fd5eed6 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1069,24 +1069,22 @@ impl<'a> Parser<'a> { fn parse_labeled_expr(&mut self, label: Label, attrs: AttrVec) -> PResult<'a, P<Expr>> { let lo = label.ident.span; + let label = Some(label); self.expect(&token::Colon)?; if self.eat_keyword(kw::While) { - return self.parse_while_expr(Some(label), lo, attrs); - } - if self.eat_keyword(kw::For) { - return self.parse_for_expr(Some(label), lo, attrs); - } - if self.eat_keyword(kw::Loop) { - return self.parse_loop_expr(Some(label), lo, attrs); - } - if self.token == token::OpenDelim(token::Brace) { - return self.parse_block_expr(Some(label), lo, BlockCheckMode::Default, attrs); + self.parse_while_expr(label, lo, attrs) + } else if self.eat_keyword(kw::For) { + self.parse_for_expr(label, lo, attrs) + } else if self.eat_keyword(kw::Loop) { + self.parse_loop_expr(label, lo, attrs) + } else if self.check(&token::OpenDelim(token::Brace)) { + self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs) + } else { + let msg = "expected `while`, `for`, `loop` or `{` after a label"; + self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit(); + // Continue as an expression in an effort to recover on `'label: non_block_expr`. + self.parse_expr() } - - let msg = "expected `while`, `for`, `loop` or `{` after a label"; - self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit(); - // Continue as an expression in an effort to recover on `'label: non_block_expr`. - self.parse_expr() } /// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead. |
