@@ -547,6 +547,7 @@ impl<'a> Parser<'a> {
547547 }
548548
549549 #[ inline]
550+ #[ must_use]
550551 fn check_noexpect ( & self , tok : & TokenKind ) -> bool {
551552 self . token == * tok
552553 }
@@ -556,6 +557,7 @@ impl<'a> Parser<'a> {
556557 /// the main purpose of this function is to reduce the cluttering of the suggestions list
557558 /// which using the normal eat method could introduce in some cases.
558559 #[ inline]
560+ #[ must_use]
559561 fn eat_noexpect ( & mut self , tok : & TokenKind ) -> bool {
560562 let is_present = self . check_noexpect ( tok) ;
561563 if is_present {
@@ -566,6 +568,7 @@ impl<'a> Parser<'a> {
566568
567569 /// Consumes a token 'tok' if it exists. Returns whether the given token was present.
568570 #[ inline]
571+ #[ must_use]
569572 pub fn eat ( & mut self , tok : & TokenKind ) -> bool {
570573 let is_present = self . check ( tok) ;
571574 if is_present {
@@ -577,12 +580,14 @@ impl<'a> Parser<'a> {
577580 /// If the next token is the given keyword, returns `true` without eating it.
578581 /// An expectation is also added for diagnostics purposes.
579582 #[ inline]
583+ #[ must_use]
580584 fn check_keyword ( & mut self , kw : Symbol ) -> bool {
581585 self . expected_tokens . push ( TokenType :: Keyword ( kw) ) ;
582586 self . token . is_keyword ( kw)
583587 }
584588
585589 #[ inline]
590+ #[ must_use]
586591 fn check_keyword_case ( & mut self , kw : Symbol , case : Case ) -> bool {
587592 if self . check_keyword ( kw) {
588593 return true ;
@@ -602,6 +607,7 @@ impl<'a> Parser<'a> {
602607 /// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
603608 // Public for rustc_builtin_macros and rustfmt usage.
604609 #[ inline]
610+ #[ must_use]
605611 pub fn eat_keyword ( & mut self , kw : Symbol ) -> bool {
606612 if self . check_keyword ( kw) {
607613 self . bump ( ) ;
@@ -615,6 +621,7 @@ impl<'a> Parser<'a> {
615621 /// If the case differs (and is ignored) an error is issued.
616622 /// This is useful for recovery.
617623 #[ inline]
624+ #[ must_use]
618625 fn eat_keyword_case ( & mut self , kw : Symbol , case : Case ) -> bool {
619626 if self . eat_keyword ( kw) {
620627 return true ;
@@ -636,6 +643,7 @@ impl<'a> Parser<'a> {
636643 /// Otherwise, returns `false`. No expectation is added.
637644 // Public for rustc_builtin_macros usage.
638645 #[ inline]
646+ #[ must_use]
639647 pub fn eat_keyword_noexpect ( & mut self , kw : Symbol ) -> bool {
640648 if self . token . is_keyword ( kw) {
641649 self . bump ( ) ;
@@ -648,7 +656,7 @@ impl<'a> Parser<'a> {
648656 /// If the given word is not a keyword, signals an error.
649657 /// If the next token is not the given word, signals an error.
650658 /// Otherwise, eats it.
651- fn expect_keyword ( & mut self , kw : Symbol ) -> PResult < ' a , ( ) > {
659+ pub fn expect_keyword ( & mut self , kw : Symbol ) -> PResult < ' a , ( ) > {
652660 if !self . eat_keyword ( kw) { self . unexpected ( ) } else { Ok ( ( ) ) }
653661 }
654662
@@ -1025,8 +1033,11 @@ impl<'a> Parser<'a> {
10251033 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
10261034 ) -> PResult < ' a , ( ThinVec < T > , Trailing ) > {
10271035 let ( val, trailing, recovered) = self . parse_seq_to_before_end ( ket, sep, f) ?;
1028- if matches ! ( recovered, Recovered :: No ) {
1029- self . eat ( ket) ;
1036+ if matches ! ( recovered, Recovered :: No ) && !self . eat ( ket) {
1037+ self . dcx ( ) . span_delayed_bug (
1038+ self . token . span ,
1039+ "recovered but `parse_seq_to_before_end` did not give us the ket token" ,
1040+ ) ;
10301041 }
10311042 Ok ( ( val, trailing) )
10321043 }
@@ -1250,7 +1261,7 @@ impl<'a> Parser<'a> {
12501261 if pat {
12511262 self . psess . gated_spans . gate ( sym:: inline_const_pat, span) ;
12521263 }
1253- self . eat_keyword ( kw:: Const ) ;
1264+ self . expect_keyword ( kw:: Const ) ? ;
12541265 let ( attrs, blk) = self . parse_inner_attrs_and_block ( ) ?;
12551266 let anon_const = AnonConst {
12561267 id : DUMMY_NODE_ID ,
0 commit comments