about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorMasaki Hara <ackie.h.gmai@gmail.com>2017-05-31 19:24:01 +0900
committerMasaki Hara <ackie.h.gmai@gmail.com>2017-05-31 19:24:01 +0900
commit54edfee71a7d2a8f710c578be75c0537a430eaaf (patch)
tree5b27adcc0f2d522fbec89b4a6eb35d073322cccb /src/libsyntax/parse
parentf89d8d184490ecb3cf91f7b6bb7296d649f931ba (diff)
downloadrust-54edfee71a7d2a8f710c578be75c0537a430eaaf.tar.gz
rust-54edfee71a7d2a8f710c578be75c0537a430eaaf.zip
Parse macros named "default" correctly.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 8d7c8c5248b..63fe33b8754 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -698,24 +698,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    pub fn check_contextual_keyword(&mut self, ident: Ident) -> bool {
-        self.expected_tokens.push(TokenType::Token(token::Ident(ident)));
-        if let token::Ident(ref cur_ident) = self.token {
-            cur_ident.name == ident.name
-        } else {
-            false
-        }
-    }
-
-    pub fn eat_contextual_keyword(&mut self, ident: Ident) -> bool {
-        if self.check_contextual_keyword(ident) {
-            self.bump();
-            true
-        } else {
-            false
-        }
-    }
-
     /// If the given word is not a keyword, signal an error.
     /// If the next token is not the given word, signal an error.
     /// Otherwise, eat it.
@@ -3755,6 +3737,18 @@ impl<'a> Parser<'a> {
         self.look_ahead(1, |t| t.is_ident() && !t.is_any_keyword())
     }
 
+    fn is_defaultness(&self) -> bool {
+        // `pub` is included for better error messages
+        self.token.is_keyword(keywords::Default) &&
+        self.look_ahead(1, |t| t.is_keyword(keywords::Impl) ||
+                        t.is_keyword(keywords::Const) ||
+                        t.is_keyword(keywords::Fn) ||
+                        t.is_keyword(keywords::Unsafe) ||
+                        t.is_keyword(keywords::Extern) ||
+                        t.is_keyword(keywords::Type) ||
+                        t.is_keyword(keywords::Pub))
+    }
+
     fn eat_macro_def(&mut self, attrs: &[Attribute], vis: &Visibility)
                      -> PResult<'a, Option<P<Item>>> {
         let lo = self.span;
@@ -5229,7 +5223,8 @@ impl<'a> Parser<'a> {
 
     /// Parse defaultness: DEFAULT or nothing
     fn parse_defaultness(&mut self) -> PResult<'a, Defaultness> {
-        if self.eat_contextual_keyword(keywords::Default.ident()) {
+        if self.is_defaultness() {
+            self.bump();
             Ok(Defaultness::Default)
         } else {
             Ok(Defaultness::Final)