From 2e812e10f4ece10d90ae3315aba16b88c5e870eb Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 2 May 2016 18:22:03 +0200 Subject: 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). --- src/libsyntax/parse/parser.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') 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, + pub fn parse_for_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { // Parse: `for in ` @@ -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, + pub fn parse_while_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { 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, + pub fn parse_while_let_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { 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, + pub fn parse_loop_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { let (iattrs, body) = self.parse_inner_attrs_and_block()?; -- cgit 1.4.1-3-g733a5