diff options
| author | bors <bors@rust-lang.org> | 2017-05-31 21:14:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-31 21:14:02 +0000 |
| commit | e0cc22b4bae8007c59fbe58f2c104ecd743d746a (patch) | |
| tree | 8c4084d31f5b5c2cbc0d4fcf7d32fe9f3f6a932f /src/libsyntax/parse | |
| parent | fd7b44b78e39c71e5049a210a0c84a8931835cc3 (diff) | |
| parent | 7f286a8e38258402c6e8e564864ac0132fac2004 (diff) | |
| download | rust-e0cc22b4bae8007c59fbe58f2c104ecd743d746a.tar.gz rust-e0cc22b4bae8007c59fbe58f2c104ecd743d746a.zip | |
Auto merge of #42336 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 7 pull requests - Successful merges: #42126, #42196, #42252, #42277, #42315, #42329, #42330 - Failed merges:
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8d7c8c5248b..936a2e8b2e1 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,28 @@ 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_defaultness(&mut self) -> bool { + let is_defaultness = self.is_defaultness(); + if is_defaultness { + self.bump() + } else { + self.expected_tokens.push(TokenType::Keyword(keywords::Default)); + } + is_defaultness + } + fn eat_macro_def(&mut self, attrs: &[Attribute], vis: &Visibility) -> PResult<'a, Option<P<Item>>> { let lo = self.span; @@ -5229,7 +5233,7 @@ 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.eat_defaultness() { Ok(Defaultness::Default) } else { Ok(Defaultness::Final) |
