@@ -698,24 +698,6 @@ impl<'a> Parser<'a> {
698
698
}
699
699
}
700
700
701
- pub fn check_contextual_keyword ( & mut self , ident : Ident ) -> bool {
702
- self . expected_tokens . push ( TokenType :: Token ( token:: Ident ( ident) ) ) ;
703
- if let token:: Ident ( ref cur_ident) = self . token {
704
- cur_ident. name == ident. name
705
- } else {
706
- false
707
- }
708
- }
709
-
710
- pub fn eat_contextual_keyword ( & mut self , ident : Ident ) -> bool {
711
- if self . check_contextual_keyword ( ident) {
712
- self . bump ( ) ;
713
- true
714
- } else {
715
- false
716
- }
717
- }
718
-
719
701
/// If the given word is not a keyword, signal an error.
720
702
/// If the next token is not the given word, signal an error.
721
703
/// Otherwise, eat it.
@@ -3755,6 +3737,28 @@ impl<'a> Parser<'a> {
3755
3737
self . look_ahead ( 1 , |t| t. is_ident ( ) && !t. is_any_keyword ( ) )
3756
3738
}
3757
3739
3740
+ fn is_defaultness ( & self ) -> bool {
3741
+ // `pub` is included for better error messages
3742
+ self . token . is_keyword ( keywords:: Default ) &&
3743
+ self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Impl ) ||
3744
+ t. is_keyword ( keywords:: Const ) ||
3745
+ t. is_keyword ( keywords:: Fn ) ||
3746
+ t. is_keyword ( keywords:: Unsafe ) ||
3747
+ t. is_keyword ( keywords:: Extern ) ||
3748
+ t. is_keyword ( keywords:: Type ) ||
3749
+ t. is_keyword ( keywords:: Pub ) )
3750
+ }
3751
+
3752
+ fn eat_defaultness ( & mut self ) -> bool {
3753
+ let is_defaultness = self . is_defaultness ( ) ;
3754
+ if is_defaultness {
3755
+ self . bump ( )
3756
+ } else {
3757
+ self . expected_tokens . push ( TokenType :: Keyword ( keywords:: Default ) ) ;
3758
+ }
3759
+ is_defaultness
3760
+ }
3761
+
3758
3762
fn eat_macro_def ( & mut self , attrs : & [ Attribute ] , vis : & Visibility )
3759
3763
-> PResult < ' a , Option < P < Item > > > {
3760
3764
let lo = self . span ;
@@ -5229,7 +5233,7 @@ impl<'a> Parser<'a> {
5229
5233
5230
5234
/// Parse defaultness: DEFAULT or nothing
5231
5235
fn parse_defaultness ( & mut self ) -> PResult < ' a , Defaultness > {
5232
- if self . eat_contextual_keyword ( keywords :: Default . ident ( ) ) {
5236
+ if self . eat_defaultness ( ) {
5233
5237
Ok ( Defaultness :: Default )
5234
5238
} else {
5235
5239
Ok ( Defaultness :: Final )
0 commit comments