@@ -72,20 +72,23 @@ impl<'a> Parser<'a> {
72
72
lo,
73
73
attrs,
74
74
errors:: InvalidVariableDeclarationSub :: MissingLet ,
75
+ force_collect,
75
76
) ?
76
77
} else if self . is_kw_followed_by_ident ( kw:: Auto ) && self . may_recover ( ) {
77
78
self . bump ( ) ; // `auto`
78
79
self . recover_stmt_local_after_let (
79
80
lo,
80
81
attrs,
81
82
errors:: InvalidVariableDeclarationSub :: UseLetNotAuto ,
83
+ force_collect,
82
84
) ?
83
85
} else if self . is_kw_followed_by_ident ( sym:: var) && self . may_recover ( ) {
84
86
self . bump ( ) ; // `var`
85
87
self . recover_stmt_local_after_let (
86
88
lo,
87
89
attrs,
88
90
errors:: InvalidVariableDeclarationSub :: UseLetNotVar ,
91
+ force_collect,
89
92
) ?
90
93
} else if self . check_path ( )
91
94
&& !self . token . is_qpath_start ( )
@@ -96,17 +99,17 @@ impl<'a> Parser<'a> {
96
99
// or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
97
100
// that starts like a path (1 token), but it fact not a path.
98
101
// Also, we avoid stealing syntax from `parse_item_`.
99
- match force_collect {
100
- ForceCollect :: Yes => {
101
- self . collect_tokens_no_attrs ( |this| this. parse_stmt_path_start ( lo, attrs) ) ?
102
+ let stmt = self . collect_tokens_trailing_token (
103
+ AttrWrapper :: empty ( ) ,
104
+ force_collect,
105
+ |this, _empty_attrs| Ok ( ( this. parse_stmt_path_start ( lo, attrs) ?, false ) ) ,
106
+ ) ;
107
+ match stmt {
108
+ Ok ( stmt) => stmt,
109
+ Err ( mut err) => {
110
+ self . suggest_add_missing_let_for_stmt ( & mut err) ;
111
+ return Err ( err) ;
102
112
}
103
- ForceCollect :: No => match self . parse_stmt_path_start ( lo, attrs) {
104
- Ok ( stmt) => stmt,
105
- Err ( mut err) => {
106
- self . suggest_add_missing_let_for_stmt ( & mut err) ;
107
- return Err ( err) ;
108
- }
109
- } ,
110
113
}
111
114
} else if let Some ( item) = self . parse_item_common (
112
115
attrs. clone ( ) ,
@@ -123,12 +126,13 @@ impl<'a> Parser<'a> {
123
126
self . mk_stmt ( lo, StmtKind :: Empty )
124
127
} else if self . token != token:: CloseDelim ( Delimiter :: Brace ) {
125
128
// Remainder are line-expr stmts.
126
- let e = match force_collect {
127
- ForceCollect :: Yes => self . collect_tokens_no_attrs ( |this| {
128
- this. parse_expr_res ( Restrictions :: STMT_EXPR , attrs)
129
- } ) ?,
130
- ForceCollect :: No => self . parse_expr_res ( Restrictions :: STMT_EXPR , attrs) ?,
131
- } ;
129
+ let e = self . collect_tokens_trailing_token (
130
+ AttrWrapper :: empty ( ) ,
131
+ force_collect,
132
+ |this, _empty_attrs| {
133
+ Ok ( ( this. parse_expr_res ( Restrictions :: STMT_EXPR , attrs) ?, false ) )
134
+ } ,
135
+ ) ?;
132
136
if matches ! ( e. kind, ExprKind :: Assign ( ..) ) && self . eat_keyword ( kw:: Else ) {
133
137
let bl = self . parse_block ( ) ?;
134
138
// Destructuring assignment ... else.
@@ -231,13 +235,13 @@ impl<'a> Parser<'a> {
231
235
lo : Span ,
232
236
attrs : AttrWrapper ,
233
237
subdiagnostic : fn ( Span ) -> errors:: InvalidVariableDeclarationSub ,
238
+ force_collect : ForceCollect ,
234
239
) -> PResult < ' a , Stmt > {
235
- let stmt =
236
- self . collect_tokens_trailing_token ( attrs, ForceCollect :: Yes , |this, attrs| {
237
- let local = this. parse_local ( attrs) ?;
238
- // FIXME - maybe capture semicolon in recovery?
239
- Ok ( ( this. mk_stmt ( lo. to ( this. prev_token . span ) , StmtKind :: Let ( local) ) , false ) )
240
- } ) ?;
240
+ let stmt = self . collect_tokens_trailing_token ( attrs, force_collect, |this, attrs| {
241
+ let local = this. parse_local ( attrs) ?;
242
+ // FIXME - maybe capture semicolon in recovery?
243
+ Ok ( ( this. mk_stmt ( lo. to ( this. prev_token . span ) , StmtKind :: Let ( local) ) , false ) )
244
+ } ) ?;
241
245
self . dcx ( )
242
246
. emit_err ( errors:: InvalidVariableDeclaration { span : lo, sub : subdiagnostic ( lo) } ) ;
243
247
Ok ( stmt)
0 commit comments