@@ -72,14 +72,22 @@ impl<'a> Parser<'a> {
72
72
73
73
Ok ( Some ( if self . token . is_keyword ( kw:: Let ) {
74
74
self . parse_local_mk ( lo, attrs, capture_semi, force_collect) ?
75
- } else if self . is_kw_followed_by_ident ( kw:: Mut ) {
76
- self . recover_stmt_local ( lo, attrs, InvalidVariableDeclarationSub :: MissingLet ) ?
77
- } else if self . is_kw_followed_by_ident ( kw:: Auto ) {
75
+ } else if self . is_kw_followed_by_ident ( kw:: Mut ) && self . may_recover ( ) {
76
+ self . recover_stmt_local_after_let ( lo, attrs, InvalidVariableDeclarationSub :: MissingLet ) ?
77
+ } else if self . is_kw_followed_by_ident ( kw:: Auto ) && self . may_recover ( ) {
78
78
self . bump ( ) ; // `auto`
79
- self . recover_stmt_local ( lo, attrs, InvalidVariableDeclarationSub :: UseLetNotAuto ) ?
80
- } else if self . is_kw_followed_by_ident ( sym:: var) {
79
+ self . recover_stmt_local_after_let (
80
+ lo,
81
+ attrs,
82
+ InvalidVariableDeclarationSub :: UseLetNotAuto ,
83
+ ) ?
84
+ } else if self . is_kw_followed_by_ident ( sym:: var) && self . may_recover ( ) {
81
85
self . bump ( ) ; // `var`
82
- self . recover_stmt_local ( lo, attrs, InvalidVariableDeclarationSub :: UseLetNotVar ) ?
86
+ self . recover_stmt_local_after_let (
87
+ lo,
88
+ attrs,
89
+ InvalidVariableDeclarationSub :: UseLetNotVar ,
90
+ ) ?
83
91
} else if self . check_path ( ) && !self . token . is_qpath_start ( ) && !self . is_path_start_item ( ) {
84
92
// We have avoided contextual keywords like `union`, items with `crate` visibility,
85
93
// or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
@@ -213,13 +221,21 @@ impl<'a> Parser<'a> {
213
221
}
214
222
}
215
223
216
- fn recover_stmt_local (
224
+ fn recover_stmt_local_after_let (
217
225
& mut self ,
218
226
lo : Span ,
219
227
attrs : AttrWrapper ,
220
228
subdiagnostic : fn ( Span ) -> InvalidVariableDeclarationSub ,
221
229
) -> PResult < ' a , Stmt > {
222
- let stmt = self . recover_local_after_let ( lo, attrs) ?;
230
+ let stmt =
231
+ self . collect_tokens_trailing_token ( attrs, ForceCollect :: Yes , |this, attrs| {
232
+ let local = this. parse_local ( attrs) ?;
233
+ // FIXME - maybe capture semicolon in recovery?
234
+ Ok ( (
235
+ this. mk_stmt ( lo. to ( this. prev_token . span ) , StmtKind :: Local ( local) ) ,
236
+ TrailingToken :: None ,
237
+ ) )
238
+ } ) ?;
223
239
self . sess . emit_err ( InvalidVariableDeclaration { span : lo, sub : subdiagnostic ( lo) } ) ;
224
240
Ok ( stmt)
225
241
}
@@ -243,17 +259,6 @@ impl<'a> Parser<'a> {
243
259
} )
244
260
}
245
261
246
- fn recover_local_after_let ( & mut self , lo : Span , attrs : AttrWrapper ) -> PResult < ' a , Stmt > {
247
- self . collect_tokens_trailing_token ( attrs, ForceCollect :: No , |this, attrs| {
248
- let local = this. parse_local ( attrs) ?;
249
- // FIXME - maybe capture semicolon in recovery?
250
- Ok ( (
251
- this. mk_stmt ( lo. to ( this. prev_token . span ) , StmtKind :: Local ( local) ) ,
252
- TrailingToken :: None ,
253
- ) )
254
- } )
255
- }
256
-
257
262
/// Parses a local variable declaration.
258
263
fn parse_local ( & mut self , attrs : AttrVec ) -> PResult < ' a , P < Local > > {
259
264
let lo = self . prev_token . span ;
0 commit comments