about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2020-02-16 21:36:50 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2020-02-17 22:12:39 +0300
commited2fd28d385c1cc9b2ab3e91513b4d2ffc612671 (patch)
tree8e6d69200b1221240312eee982fc4492267decd4 /src/librustc_parse/parser
parentd33b3562e5e888eaffd2f8f1af08ca2afdbe542c (diff)
downloadrust-ed2fd28d385c1cc9b2ab3e91513b4d2ffc612671.tar.gz
rust-ed2fd28d385c1cc9b2ab3e91513b4d2ffc612671.zip
parser: Set previous and unnormalized tokens in couple more places
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/item.rs7
-rw-r--r--src/librustc_parse/parser/mod.rs8
2 files changed, 8 insertions, 7 deletions
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 @@ impl<'a> Parser<'a> {
     }
 
     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 @@ impl<'a> Parser<'a> {
             );
         } 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<Token>,
+    pub unnormalized_token: Option<Token>,
     /// The previous normalized token.
     /// Use span from this token if you need an isolated span.
     prev_token: Token,
@@ -1096,15 +1096,15 @@ impl<'a> Parser<'a> {
                     &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())
             }
         }
     }