@@ -698,24 +698,6 @@ impl<'a> Parser<'a> {
698698 }
699699 }
700700
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-
719701 /// If the given word is not a keyword, signal an error.
720702 /// If the next token is not the given word, signal an error.
721703 /// Otherwise, eat it.
@@ -3755,6 +3737,28 @@ impl<'a> Parser<'a> {
37553737 self . look_ahead ( 1 , |t| t. is_ident ( ) && !t. is_any_keyword ( ) )
37563738 }
37573739
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+
37583762 fn eat_macro_def ( & mut self , attrs : & [ Attribute ] , vis : & Visibility )
37593763 -> PResult < ' a , Option < P < Item > > > {
37603764 let lo = self . span ;
@@ -5229,7 +5233,7 @@ impl<'a> Parser<'a> {
52295233
52305234 /// Parse defaultness: DEFAULT or nothing
52315235 fn parse_defaultness ( & mut self ) -> PResult < ' a , Defaultness > {
5232- if self . eat_contextual_keyword ( keywords :: Default . ident ( ) ) {
5236+ if self . eat_defaultness ( ) {
52335237 Ok ( Defaultness :: Default )
52345238 } else {
52355239 Ok ( Defaultness :: Final )
0 commit comments