diff options
| author | Georg Brandl <georg@python.org> | 2016-05-02 18:22:03 +0200 |
|---|---|---|
| committer | Georg Brandl <g.brandl@fz-juelich.de> | 2016-05-24 14:22:14 +0200 |
| commit | 2e812e10f4ece10d90ae3315aba16b88c5e870eb (patch) | |
| tree | 1830b86f86bf0bee4561763cbe4b1a4f183e1a3d /src/libsyntax/parse/parser.rs | |
| parent | dd6e8d45e183861d44ed91a99f0a50403b2776a3 (diff) | |
| download | rust-2e812e10f4ece10d90ae3315aba16b88c5e870eb.tar.gz rust-2e812e10f4ece10d90ae3315aba16b88c5e870eb.zip | |
syntax/hir: give loop labels a span
This makes the "shadowing labels" warning *not* print the entire loop as a span, but only the lifetime. Also makes #31719 go away, but does not fix its root cause (the span of the expanded loop is still wonky, but not used anymore).
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fc62cee92fd..b616b9db9c3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2283,18 +2283,19 @@ impl<'a> Parser<'a> { return self.parse_while_expr(None, lo, attrs); } if self.token.is_lifetime() { - let lifetime = self.get_lifetime(); + let label = Spanned { node: self.get_lifetime(), + span: self.span }; let lo = self.span.lo; self.bump(); self.expect(&token::Colon)?; if self.eat_keyword(keywords::While) { - return self.parse_while_expr(Some(lifetime), lo, attrs) + return self.parse_while_expr(Some(label), lo, attrs) } if self.eat_keyword(keywords::For) { - return self.parse_for_expr(Some(lifetime), lo, attrs) + return self.parse_for_expr(Some(label), lo, attrs) } if self.eat_keyword(keywords::Loop) { - return self.parse_loop_expr(Some(lifetime), lo, attrs) + return self.parse_loop_expr(Some(label), lo, attrs) } return Err(self.fatal("expected `while`, `for`, or `loop` after a label")) } @@ -3264,7 +3265,7 @@ impl<'a> Parser<'a> { } /// Parse a 'for' .. 'in' expression ('for' token already eaten) - pub fn parse_for_expr(&mut self, opt_ident: Option<ast::Ident>, + pub fn parse_for_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { // Parse: `for <src_pat> in <src_expr> <src_loop_block>` @@ -3283,7 +3284,7 @@ impl<'a> Parser<'a> { } /// Parse a 'while' or 'while let' expression ('while' token already eaten) - pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>, + pub fn parse_while_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { if self.token.is_keyword(keywords::Let) { @@ -3298,7 +3299,7 @@ impl<'a> Parser<'a> { } /// Parse a 'while let' expression ('while' token already eaten) - pub fn parse_while_let_expr(&mut self, opt_ident: Option<ast::Ident>, + pub fn parse_while_let_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { self.expect_keyword(keywords::Let)?; @@ -3312,7 +3313,7 @@ impl<'a> Parser<'a> { } // parse `loop {...}`, `loop` token already eaten - pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::Ident>, + pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { let (iattrs, body) = self.parse_inner_attrs_and_block()?; |
