]> git.lizzy.rs Git - rust.git/commitdiff
Return a is_raw parameter from Token::ident rather than having separate methods.
authorLymia Aluysia <lymia@lymiahugs.com>
Sun, 18 Mar 2018 17:16:02 +0000 (12:16 -0500)
committerLymia Aluysia <lymia@lymiahugs.com>
Sun, 18 Mar 2018 17:16:02 +0000 (12:16 -0500)
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/ext/tt/quoted.rs
src/libsyntax/parse/token.rs

index 714b7ca981da054cd77fbe77ab94360ba5715053..8cb331c65da2871c5ffca5f7a7d178bff1a08c0b 100644 (file)
@@ -364,8 +364,8 @@ pub fn parse_failure_msg(tok: Token) -> String {
 
 /// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
 fn token_name_eq(t1: &Token, t2: &Token) -> bool {
-    if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
-        id1.name == id2.name && t1.is_raw_ident() == t2.is_raw_ident()
+    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 (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
         id1.name == id2.name
     } else {
index 11eb9b940aea53be68aec31d7eae1fb7f90efead..f324edeb1178ad49db4d4fc6e9f9cda20dc56be6 100644 (file)
@@ -200,7 +200,7 @@ pub fn parse(
                 let span = match trees.next() {
                     Some(tokenstream::TokenTree::Token(span, token::Colon)) => match trees.next() {
                         Some(tokenstream::TokenTree::Token(end_sp, ref tok)) => match tok.ident() {
-                            Some(kind) => {
+                            Some((kind, _)) => {
                                 let span = end_sp.with_lo(start_sp.lo());
                                 result.push(TokenTree::MetaVarDecl(span, ident, kind));
                                 continue;
@@ -289,7 +289,7 @@ fn parse_tree<I>(
             // `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` special
             // metavariable that names the crate of the invokation.
             Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
-                let ident = token.ident().unwrap();
+                let (ident, _) = token.ident().unwrap();
                 let span = ident_span.with_lo(span.lo());
                 if ident.name == keywords::Crate.name() {
                     let ident = ast::Ident {
index 6406651bcba8805bd4369e38bca08f53b6a409c2..4e7a282adc5842a38dda60abca5b4ce3e7bdabbe 100644 (file)
@@ -310,32 +310,17 @@ pub fn is_lit(&self) -> bool {
         }
     }
 
-    fn ident_common(&self, allow_raw: bool) -> Option<ast::Ident> {
+    pub fn ident(&self) -> Option<(ast::Ident, bool)> {
         match *self {
-            Ident(ident, is_raw) if !is_raw || allow_raw => Some(ident),
+            Ident(ident, is_raw) => Some((ident, is_raw)),
             Interpolated(ref nt) => match nt.0 {
-                NtIdent(ident, is_raw) if !is_raw || allow_raw => Some(ident.node),
+                NtIdent(ident, is_raw) => Some((ident.node, is_raw)),
                 _ => None,
             },
             _ => None,
         }
     }
 
-    pub fn nonraw_ident(&self) -> Option<ast::Ident> {
-        self.ident_common(false)
-    }
-
-    pub fn is_raw_ident(&self) -> bool {
-        match *self {
-            Ident(_, true) => true,
-            _ => false,
-        }
-    }
-
-    pub fn ident(&self) -> Option<ast::Ident> {
-        self.ident_common(true)
-    }
-
     /// Returns `true` if the token is an identifier.
     pub fn is_ident(&self) -> bool {
         self.ident().is_some()
@@ -404,37 +389,37 @@ pub fn is_path_start(&self) -> bool {
 
     /// Returns `true` if the token is a given keyword, `kw`.
     pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
-        self.nonraw_ident().map(|ident| ident.name == kw.name()).unwrap_or(false)
+        self.ident().map(|(ident, is_raw)| ident.name == kw.name() && !is_raw).unwrap_or(false)
     }
 
     pub fn is_path_segment_keyword(&self) -> bool {
-        match self.nonraw_ident() {
-            Some(id) => is_path_segment_keyword(id),
-            None => false,
+        match self.ident() {
+            Some((id, false)) => is_path_segment_keyword(id),
+            _ => false,
         }
     }
 
     // Returns true for reserved identifiers used internally for elided lifetimes,
     // unnamed method parameters, crate root module, error recovery etc.
     pub fn is_special_ident(&self) -> bool {
-        match self.nonraw_ident() {
-            Some(id) => is_special_ident(id),
+        match self.ident() {
+            Some((id, false)) => is_special_ident(id),
             _ => false,
         }
     }
 
     /// Returns `true` if the token is a keyword used in the language.
     pub fn is_used_keyword(&self) -> bool {
-        match self.nonraw_ident() {
-            Some(id) => is_used_keyword(id),
+        match self.ident() {
+            Some((id, false)) => is_used_keyword(id),
             _ => false,
         }
     }
 
     /// Returns `true` if the token is a keyword reserved for possible future use.
     pub fn is_unused_keyword(&self) -> bool {
-        match self.nonraw_ident() {
-            Some(id) => is_unused_keyword(id),
+        match self.ident() {
+            Some((id, false)) => is_unused_keyword(id),
             _ => false,
         }
     }
@@ -507,8 +492,8 @@ pub fn similar_tokens(&self) -> Option<Vec<Token>> {
 
     /// Returns `true` if the token is either a special identifier or a keyword.
     pub fn is_reserved_ident(&self) -> bool {
-        match self.nonraw_ident() {
-            Some(id) => is_reserved_ident(id),
+        match self.ident() {
+            Some((id, false)) => is_reserved_ident(id),
             _ => false,
         }
     }