diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs index 4aad2c0f68a..40d7a34a8b0 100644 --- a/src/librustc_parse/lib.rs +++ b/src/librustc_parse/lib.rs @@ -172,6 +172,7 @@ fn maybe_source_file_to_parser( parser.unclosed_delims = unclosed_delims; if parser.token == token::Eof && parser.token.span.is_dummy() { parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt()); + assert!(parser.unnormalized_token.is_none()); } Ok(parser) diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index d7b8d9778f0..5dc50a0cf2f 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1400,8 +1400,9 @@ fn eat_semi_for_macro_if_needed(&mut self, args: &MacArgs) { } fn report_invalid_macro_expansion_item(&self, args: &MacArgs) { + let span = args.span().expect("undelimited macro call"); let mut err = self.struct_span_err( - self.prev_span, + span, "macros that expand to items must be delimited with braces or followed by a semicolon", ); if self.unclosed_delims.is_empty() { @@ -1416,14 +1417,14 @@ fn report_invalid_macro_expansion_item(&self, args: &MacArgs) { ); } else { err.span_suggestion( - self.prev_span, + span, "change the delimiters to curly braces", " { /* items */ }".to_string(), Applicability::HasPlaceholders, ); } err.span_suggestion( - self.prev_span.shrink_to_hi(), + span.shrink_to_hi(), "add a semicolon", ';'.to_string(), Applicability::MaybeIncorrect, diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 4f96d33b83f..e04cfa37468 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -95,7 +95,7 @@ pub struct Parser<'a> { /// The current non-normalized token if it's different from `token`. /// Preferable use is through the `unnormalized_token()` getter. /// Use span from this token if you need to concatenate it with some neighbouring spans. - unnormalized_token: Option, + pub unnormalized_token: Option, /// The previous normalized token. /// Use span from this token if you need an isolated span. prev_token: Token, @@ -1096,15 +1096,15 @@ pub fn parse_token_tree(&mut self) -> TokenTree { &mut self.token_cursor.frame, self.token_cursor.stack.pop().unwrap(), ); - self.token.span = frame.span.entire(); + self.token = Token::new(TokenKind::CloseDelim(frame.delim), frame.span.close); + self.unnormalized_token = None; self.bump(); TokenTree::Delimited(frame.span, frame.delim, frame.tree_cursor.stream.into()) } token::CloseDelim(_) | token::Eof => unreachable!(), _ => { - let token = self.token.clone(); self.bump(); - TokenTree::Token(token) + TokenTree::Token(self.prev_token.clone()) } } }