diff options
| author | bors <bors@rust-lang.org> | 2014-08-30 09:01:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-30 09:01:20 +0000 |
| commit | 43c26e6041b811b322f49933e8d0f9455cb7ea2b (patch) | |
| tree | 1d6a7a8293538c92f5883659ab872d550a790690 /src/libsyntax/parse/parser.rs | |
| parent | c8e86e977f5f95bd2f533c12ebf8107fb6f21a0f (diff) | |
| parent | e76db8ebc2955ce19605a9c73d2b26b977406803 (diff) | |
| download | rust-43c26e6041b811b322f49933e8d0f9455cb7ea2b.tar.gz rust-43c26e6041b811b322f49933e8d0f9455cb7ea2b.zip | |
auto merge of #16190 : Pythoner6/rust/labeled-while-loop, r=alexcrichton
Fixes #12643 > Say! > I like labelled breaks/continues! I will use them with a `for` loop. And I will use with a `loop` loop. Say! I will use them ANYWHERE! … _even_ in a `while` loop. Because they're now supported there.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 37bda15ac2c..60f24401152 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2094,19 +2094,22 @@ impl<'a> Parser<'a> { return self.parse_for_expr(None); } if self.eat_keyword(keywords::While) { - return self.parse_while_expr(); + return self.parse_while_expr(None); } if Parser::token_is_lifetime(&self.token) { let lifetime = self.get_lifetime(); self.bump(); self.expect(&token::COLON); + if self.eat_keyword(keywords::While) { + return self.parse_while_expr(Some(lifetime)) + } if self.eat_keyword(keywords::For) { return self.parse_for_expr(Some(lifetime)) } if self.eat_keyword(keywords::Loop) { return self.parse_loop_expr(Some(lifetime)) } - self.fatal("expected `for` or `loop` after a label") + self.fatal("expected `while`, `for`, or `loop` after a label") } if self.eat_keyword(keywords::Loop) { return self.parse_loop_expr(None); @@ -2762,12 +2765,12 @@ impl<'a> Parser<'a> { self.mk_expr(lo, hi, ExprForLoop(pat, expr, loop_block, opt_ident)) } - pub fn parse_while_expr(&mut self) -> Gc<Expr> { + pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> Gc<Expr> { let lo = self.last_span.lo; let cond = self.parse_expr_res(RESTRICT_NO_STRUCT_LITERAL); let body = self.parse_block(); let hi = body.span.hi; - return self.mk_expr(lo, hi, ExprWhile(cond, body)); + return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident)); } pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::Ident>) -> Gc<Expr> { |
