about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-06-05 11:00:22 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-06-06 14:04:02 +0300
commit4c5d773b4d529c6263f682513ea34ce644a8179b (patch)
tree2d207a75d803063e4ee7a87ca55fb68af3bfe088 /src/libsyntax
parent5e693531ffa55cfb0cececdf5d7203a6d400e828 (diff)
downloadrust-4c5d773b4d529c6263f682513ea34ce644a8179b.tar.gz
rust-4c5d773b4d529c6263f682513ea34ce644a8179b.zip
syntax: Remove duplicate span from `token::Lifetime`
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs4
-rw-r--r--src/libsyntax/mut_visit.rs1
-rw-r--r--src/libsyntax/parse/lexer/mod.rs14
-rw-r--r--src/libsyntax/parse/parser.rs7
-rw-r--r--src/libsyntax/parse/token.rs43
5 files changed, 36 insertions, 33 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 7127acabb44..f93b548c501 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -431,8 +431,8 @@ pub fn parse_failure_msg(tok: TokenKind) -> String {
 fn token_name_eq(t1: &TokenKind, t2: &TokenKind) -> bool {
     if let (Some((id1, is_raw1)), Some((id2, is_raw2))) = (t1.ident(), t2.ident()) {
         id1.name == id2.name && is_raw1 == is_raw2
-    } else if let (Some(id1), Some(id2)) = (t1.lifetime(), t2.lifetime()) {
-        id1.name == id2.name
+    } else if let (Some(name1), Some(name2)) = (t1.lifetime_name(), t2.lifetime_name()) {
+        name1 == name2
     } else {
         *t1 == *t2
     }
diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs
index ad6d3f71c65..3bb36605299 100644
--- a/src/libsyntax/mut_visit.rs
+++ b/src/libsyntax/mut_visit.rs
@@ -599,7 +599,6 @@ pub fn noop_visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &m
 pub fn noop_visit_token<T: MutVisitor>(t: &mut TokenKind, vis: &mut T) {
     match t {
         token::Ident(id, _is_raw) => vis.visit_ident(id),
-        token::Lifetime(id) => vis.visit_ident(id),
         token::Interpolated(nt) => {
             let mut nt = Lrc::make_mut(nt);
             vis.visit_interpolated(&mut nt);
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 47428c9a14c..da8c6f5ac22 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -1041,13 +1041,6 @@ impl<'a> StringReader<'a> {
                         return Ok(TokenKind::lit(token::Char, symbol, None));
                     }
 
-                    // Include the leading `'` in the real identifier, for macro
-                    // expansion purposes. See #12512 for the gory details of why
-                    // this is necessary.
-                    let ident = self.with_str_from(start_with_quote, |lifetime_name| {
-                        self.mk_ident(lifetime_name)
-                    });
-
                     if starts_with_number {
                         // this is a recovered lifetime written `'1`, error but accept it
                         self.err_span_(
@@ -1057,7 +1050,10 @@ impl<'a> StringReader<'a> {
                         );
                     }
 
-                    return Ok(token::Lifetime(ident));
+                    // Include the leading `'` in the real identifier, for macro
+                    // expansion purposes. See #12512 for the gory details of why
+                    // this is necessary.
+                    return Ok(token::Lifetime(self.name_from(start_with_quote)));
                 }
                 let msg = "unterminated character literal";
                 let symbol = self.scan_single_quoted_string(start_with_quote, msg);
@@ -1690,7 +1686,7 @@ mod tests {
             let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
             let sh = mk_sess(sm.clone());
             assert_eq!(setup(&sm, &sh, "'abc".to_string()).next_token(),
-                       token::Lifetime(Ident::from_str("'abc")));
+                       token::Lifetime(Symbol::intern("'abc")));
         })
     }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 7dd92f022e1..362f81d02a0 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2652,7 +2652,7 @@ impl<'a> Parser<'a> {
                 // and lifetime tokens, so the former are never encountered during normal parsing.
                 match **nt {
                     token::NtIdent(ident, is_raw) => Token::new(token::Ident(ident, is_raw), ident.span),
-                    token::NtLifetime(ident) => Token::new(token::Lifetime(ident), ident.span),
+                    token::NtLifetime(ident) => Token::new(token::Lifetime(ident.name), ident.span),
                     _ => return,
                 }
             }
@@ -3922,9 +3922,8 @@ impl<'a> Parser<'a> {
                 // Parse &pat / &mut pat
                 self.expect_and()?;
                 let mutbl = self.parse_mutability();
-                if let token::Lifetime(ident) = self.token.kind {
-                    let mut err = self.fatal(&format!("unexpected lifetime `{}` in pattern",
-                                                      ident));
+                if let token::Lifetime(name) = self.token.kind {
+                    let mut err = self.fatal(&format!("unexpected lifetime `{}` in pattern", name));
                     err.span_label(self.span, "unexpected lifetime");
                     return Err(err);
                 }
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 559e0524a4b..81c93a4179e 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -12,7 +12,7 @@ use crate::symbol::kw;
 use crate::syntax::parse::parse_stream_from_source_str;
 use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
 
-use syntax_pos::symbol::{self, Symbol};
+use syntax_pos::symbol::Symbol;
 use syntax_pos::{self, Span, FileName, DUMMY_SP};
 use log::info;
 
@@ -211,7 +211,7 @@ pub enum TokenKind {
 
     /* Name components */
     Ident(ast::Ident, /* is_raw */ bool),
-    Lifetime(ast::Ident),
+    Lifetime(ast::Name),
 
     Interpolated(Lrc<Nonterminal>),
 
@@ -364,7 +364,23 @@ impl TokenKind {
             _            => false,
         }
     }
+}
+
+impl Token {
+    /// Returns a lifetime identifier if this token is a lifetime.
+    pub fn lifetime(&self) -> Option<ast::Ident> {
+        match self.kind {
+            Lifetime(name) => Some(ast::Ident::new(name, self.span)),
+            Interpolated(ref nt) => match **nt {
+                NtLifetime(ident) => Some(ident),
+                _ => None,
+            },
+            _ => None,
+        }
+    }
+}
 
+impl TokenKind {
     /// Returns an identifier if this token is an identifier.
     pub fn ident(&self) -> Option<(ast::Ident, /* is_raw */ bool)> {
         match *self {
@@ -376,12 +392,12 @@ impl TokenKind {
             _ => None,
         }
     }
-    /// Returns a lifetime identifier if this token is a lifetime.
-    pub fn lifetime(&self) -> Option<ast::Ident> {
+    /// Returns a lifetime name if this token is a lifetime.
+    pub fn lifetime_name(&self) -> Option<ast::Name> {
         match *self {
-            Lifetime(ident) => Some(ident),
+            Lifetime(name) => Some(name),
             Interpolated(ref nt) => match **nt {
-                NtLifetime(ident) => Some(ident),
+                NtLifetime(ident) => Some(ident.name),
                 _ => None,
             },
             _ => None,
@@ -393,7 +409,7 @@ impl TokenKind {
     }
     /// Returns `true` if the token is a lifetime.
     crate fn is_lifetime(&self) -> bool {
-        self.lifetime().is_some()
+        self.lifetime_name().is_some()
     }
 
     /// Returns `true` if the token is a identifier whose name is the given
@@ -521,13 +537,7 @@ impl TokenKind {
                 _ => return None,
             },
             SingleQuote => match joint {
-                Ident(ident, false) => {
-                    let name = Symbol::intern(&format!("'{}", ident));
-                    Lifetime(symbol::Ident {
-                        name,
-                        span: ident.span,
-                    })
-                }
+                Ident(ident, false) => Lifetime(Symbol::intern(&format!("'{}", ident))),
                 _ => return None,
             },
 
@@ -597,7 +607,7 @@ impl TokenKind {
 
             (&Literal(a), &Literal(b)) => a == b,
 
-            (&Lifetime(a), &Lifetime(b)) => a.name == b.name,
+            (&Lifetime(a), &Lifetime(b)) => a == b,
             (&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
                                                        a.name == kw::DollarCrate ||
                                                        c.name == kw::DollarCrate),
@@ -732,8 +742,7 @@ impl Nonterminal {
                 Some(TokenTree::token(ident.span, token).into())
             }
             Nonterminal::NtLifetime(ident) => {
-                let token = Lifetime(ident);
-                Some(TokenTree::token(ident.span, token).into())
+                Some(TokenTree::token(ident.span, Lifetime(ident.name)).into())
             }
             Nonterminal::NtTT(ref tt) => {
                 Some(tt.clone().into())