about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/parse')
-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
3 files changed, 34 insertions, 30 deletions
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())