about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorMatt Peterson <ricochet1k@gmail.com>2017-12-30 21:47:45 -0500
committerMatt Peterson <ricochet1k@gmail.com>2017-12-30 21:47:45 -0500
commit8b4bdc2f3f753e0d0b00ecc892a813e9786621e9 (patch)
treefae8d9ab5c2d863b5b2b295f8fe90546ac56e94e /src/libsyntax/parse
parentf55242583cddf969c863ba8948682beb7d5bb99e (diff)
downloadrust-8b4bdc2f3f753e0d0b00ecc892a813e9786621e9.tar.gz
rust-8b4bdc2f3f753e0d0b00ecc892a813e9786621e9.zip
refactor lifetime out of is_lifetime
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs19
-rw-r--r--src/libsyntax/parse/token.rs20
2 files changed, 20 insertions, 19 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 7251af77dcc..eae558f002a 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2036,19 +2036,12 @@ impl<'a> Parser<'a> {
 
     /// Parse single lifetime 'a or panic.
     pub fn expect_lifetime(&mut self) -> Lifetime {
-        let lifetime = match self.token {
-            token::Lifetime(ident) =>
-                Lifetime { ident: ident, span: self.span, id: ast::DUMMY_NODE_ID },
-            token::Interpolated(ref nt) => match nt.0 {
-                token::NtLifetime(lifetime) =>
-                    lifetime,
-                _ => self.span_bug(self.span, "not a lifetime")
-            }
-            _ => self.span_bug(self.span, "not a lifetime")
-        };
-
-        self.bump();
-        lifetime
+        if let Some(lifetime) = self.token.lifetime(self.span) {
+            self.bump();
+            lifetime
+        } else {
+            self.span_bug(self.span, "not a lifetime")
+        }
     }
 
     /// Parse mutability (`mut` or nothing).
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 2d7ab938f7b..bd4f7f9853d 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -314,18 +314,26 @@ impl Token {
         false
     }
 
-    /// Returns `true` if the token is a lifetime.
-    pub fn is_lifetime(&self) -> bool {
+    /// Returns a lifetime with the span and a dummy id if it is a lifetime,
+    /// or the original lifetime if it is an interpolated lifetime, ignoring
+    /// the span.
+    pub fn lifetime(&self, span: Span) -> Option<ast::Lifetime> {
         match *self {
-            Lifetime(..) => true,
+            Lifetime(ident) =>
+                Some(ast::Lifetime { ident: ident, span: span, id: ast::DUMMY_NODE_ID }),
             Interpolated(ref nt) => match nt.0 {
-                NtLifetime(..) => true,
-                _ => false,
+                NtLifetime(lifetime) => Some(lifetime),
+                _ => None,
             },
-            _ => false,
+            _ => None,
         }
     }
 
+    /// Returns `true` if the token is a lifetime.
+    pub fn is_lifetime(&self) -> bool {
+        self.lifetime(syntax_pos::DUMMY_SP).is_some()
+    }
+
     /// Returns `true` if the token is either the `mut` or `const` keyword.
     pub fn is_mutability(&self) -> bool {
         self.is_keyword(keywords::Mut) ||