@@ -547,6 +547,7 @@ impl<'a> Parser<'a> {
547
547
}
548
548
549
549
#[ inline]
550
+ #[ must_use]
550
551
fn check_noexpect ( & self , tok : & TokenKind ) -> bool {
551
552
self . token == * tok
552
553
}
@@ -556,6 +557,7 @@ impl<'a> Parser<'a> {
556
557
/// the main purpose of this function is to reduce the cluttering of the suggestions list
557
558
/// which using the normal eat method could introduce in some cases.
558
559
#[ inline]
560
+ #[ must_use]
559
561
fn eat_noexpect ( & mut self , tok : & TokenKind ) -> bool {
560
562
let is_present = self . check_noexpect ( tok) ;
561
563
if is_present {
@@ -566,6 +568,7 @@ impl<'a> Parser<'a> {
566
568
567
569
/// Consumes a token 'tok' if it exists. Returns whether the given token was present.
568
570
#[ inline]
571
+ #[ must_use]
569
572
pub fn eat ( & mut self , tok : & TokenKind ) -> bool {
570
573
let is_present = self . check ( tok) ;
571
574
if is_present {
@@ -577,12 +580,14 @@ impl<'a> Parser<'a> {
577
580
/// If the next token is the given keyword, returns `true` without eating it.
578
581
/// An expectation is also added for diagnostics purposes.
579
582
#[ inline]
583
+ #[ must_use]
580
584
fn check_keyword ( & mut self , kw : Symbol ) -> bool {
581
585
self . expected_tokens . push ( TokenType :: Keyword ( kw) ) ;
582
586
self . token . is_keyword ( kw)
583
587
}
584
588
585
589
#[ inline]
590
+ #[ must_use]
586
591
fn check_keyword_case ( & mut self , kw : Symbol , case : Case ) -> bool {
587
592
if self . check_keyword ( kw) {
588
593
return true ;
@@ -602,6 +607,7 @@ impl<'a> Parser<'a> {
602
607
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
603
608
// Public for rustc_builtin_macros and rustfmt usage.
604
609
#[ inline]
610
+ #[ must_use]
605
611
pub fn eat_keyword ( & mut self , kw : Symbol ) -> bool {
606
612
if self . check_keyword ( kw) {
607
613
self . bump ( ) ;
@@ -615,6 +621,7 @@ impl<'a> Parser<'a> {
615
621
/// If the case differs (and is ignored) an error is issued.
616
622
/// This is useful for recovery.
617
623
#[ inline]
624
+ #[ must_use]
618
625
fn eat_keyword_case ( & mut self , kw : Symbol , case : Case ) -> bool {
619
626
if self . eat_keyword ( kw) {
620
627
return true ;
@@ -636,6 +643,7 @@ impl<'a> Parser<'a> {
636
643
/// Otherwise, returns `false`. No expectation is added.
637
644
// Public for rustc_builtin_macros usage.
638
645
#[ inline]
646
+ #[ must_use]
639
647
pub fn eat_keyword_noexpect ( & mut self , kw : Symbol ) -> bool {
640
648
if self . token . is_keyword ( kw) {
641
649
self . bump ( ) ;
@@ -648,7 +656,7 @@ impl<'a> Parser<'a> {
648
656
/// If the given word is not a keyword, signals an error.
649
657
/// If the next token is not the given word, signals an error.
650
658
/// Otherwise, eats it.
651
- fn expect_keyword ( & mut self , kw : Symbol ) -> PResult < ' a , ( ) > {
659
+ pub fn expect_keyword ( & mut self , kw : Symbol ) -> PResult < ' a , ( ) > {
652
660
if !self . eat_keyword ( kw) { self . unexpected ( ) } else { Ok ( ( ) ) }
653
661
}
654
662
@@ -1025,8 +1033,11 @@ impl<'a> Parser<'a> {
1025
1033
f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1026
1034
) -> PResult < ' a , ( ThinVec < T > , Trailing ) > {
1027
1035
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
+ ) ;
1030
1041
}
1031
1042
Ok ( ( val, trailing) )
1032
1043
}
@@ -1250,7 +1261,7 @@ impl<'a> Parser<'a> {
1250
1261
if pat {
1251
1262
self . psess . gated_spans . gate ( sym:: inline_const_pat, span) ;
1252
1263
}
1253
- self . eat_keyword ( kw:: Const ) ;
1264
+ self . expect_keyword ( kw:: Const ) ? ;
1254
1265
let ( attrs, blk) = self . parse_inner_attrs_and_block ( ) ?;
1255
1266
let anon_const = AnonConst {
1256
1267
id : DUMMY_NODE_ID ,
0 commit comments