@@ -115,6 +115,12 @@ macro_rules! maybe_recover_from_interpolated_ty_qpath {
115
115
} ;
116
116
}
117
117
118
+ #[ derive( Clone , Copy ) ]
119
+ pub enum Recovery {
120
+ Allowed ,
121
+ Forbidden ,
122
+ }
123
+
118
124
#[ derive( Clone ) ]
119
125
pub struct Parser < ' a > {
120
126
pub sess : & ' a ParseSess ,
@@ -152,12 +158,15 @@ pub struct Parser<'a> {
152
158
/// This allows us to recover when the user forget to add braces around
153
159
/// multiple statements in the closure body.
154
160
pub current_closure : Option < ClosureSpans > ,
161
+ /// Whether the parser is allowed to recover and parse invalid code successfully (and emit a diagnostic as a side effect).
162
+ /// This is disabled when parsing macro arguments, see #103534
163
+ pub recovery : Recovery ,
155
164
}
156
165
157
- // This type is used a lot, e.g. it's cloned when matching many declarative macro rules. Make sure
166
+ // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals . Make sure
158
167
// it doesn't unintentionally get bigger.
159
168
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
160
- rustc_data_structures:: static_assert_size!( Parser <' _>, 328 ) ;
169
+ rustc_data_structures:: static_assert_size!( Parser <' _>, 336 ) ;
161
170
162
171
/// Stores span information about a closure.
163
172
#[ derive( Clone ) ]
@@ -483,6 +492,7 @@ impl<'a> Parser<'a> {
483
492
inner_attr_ranges : Default :: default ( ) ,
484
493
} ,
485
494
current_closure : None ,
495
+ recovery : Recovery :: Allowed ,
486
496
} ;
487
497
488
498
// Make parser point to the first token.
@@ -491,6 +501,15 @@ impl<'a> Parser<'a> {
491
501
parser
492
502
}
493
503
504
+ pub fn forbid_recovery ( mut self ) -> Self {
505
+ self . recovery = Recovery :: Forbidden ;
506
+ self
507
+ }
508
+
509
+ fn may_recover ( & self ) -> bool {
510
+ matches ! ( self . recovery, Recovery :: Allowed )
511
+ }
512
+
494
513
pub fn unexpected < T > ( & mut self ) -> PResult < ' a , T > {
495
514
match self . expect_one_of ( & [ ] , & [ ] ) {
496
515
Err ( e) => Err ( e) ,
0 commit comments