@@ -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,18 @@ 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+
37583752 fn eat_macro_def ( & mut self , attrs : & [ Attribute ] , vis : & Visibility )
37593753 -> PResult < ' a , Option < P < Item > > > {
37603754 let lo = self . span ;
@@ -5229,7 +5223,8 @@ impl<'a> Parser<'a> {
52295223
52305224 /// Parse defaultness: DEFAULT or nothing
52315225 fn parse_defaultness ( & mut self ) -> PResult < ' a , Defaultness > {
5232- if self . eat_contextual_keyword ( keywords:: Default . ident ( ) ) {
5226+ if self . is_defaultness ( ) {
5227+ self . bump ( ) ;
52335228 Ok ( Defaultness :: Default )
52345229 } else {
52355230 Ok ( Defaultness :: Final )
0 commit comments