@@ -72,20 +72,23 @@ impl<'a> Parser<'a> {
7272 lo,
7373 attrs,
7474 errors:: InvalidVariableDeclarationSub :: MissingLet ,
75+ force_collect,
7576 ) ?
7677 } else if self . is_kw_followed_by_ident ( kw:: Auto ) && self . may_recover ( ) {
7778 self . bump ( ) ; // `auto`
7879 self . recover_stmt_local_after_let (
7980 lo,
8081 attrs,
8182 errors:: InvalidVariableDeclarationSub :: UseLetNotAuto ,
83+ force_collect,
8284 ) ?
8385 } else if self . is_kw_followed_by_ident ( sym:: var) && self . may_recover ( ) {
8486 self . bump ( ) ; // `var`
8587 self . recover_stmt_local_after_let (
8688 lo,
8789 attrs,
8890 errors:: InvalidVariableDeclarationSub :: UseLetNotVar ,
91+ force_collect,
8992 ) ?
9093 } else if self . check_path ( )
9194 && !self . token . is_qpath_start ( )
@@ -96,17 +99,17 @@ impl<'a> Parser<'a> {
9699 // or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
97100 // that starts like a path (1 token), but it fact not a path.
98101 // 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) ;
102112 }
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- } ,
110113 }
111114 } else if let Some ( item) = self . parse_item_common (
112115 attrs. clone ( ) ,
@@ -123,12 +126,13 @@ impl<'a> Parser<'a> {
123126 self . mk_stmt ( lo, StmtKind :: Empty )
124127 } else if self . token != token:: CloseDelim ( Delimiter :: Brace ) {
125128 // 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+ ) ?;
132136 if matches ! ( e. kind, ExprKind :: Assign ( ..) ) && self . eat_keyword ( kw:: Else ) {
133137 let bl = self . parse_block ( ) ?;
134138 // Destructuring assignment ... else.
@@ -231,13 +235,13 @@ impl<'a> Parser<'a> {
231235 lo : Span ,
232236 attrs : AttrWrapper ,
233237 subdiagnostic : fn ( Span ) -> errors:: InvalidVariableDeclarationSub ,
238+ force_collect : ForceCollect ,
234239 ) -> 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+ } ) ?;
241245 self . dcx ( )
242246 . emit_err ( errors:: InvalidVariableDeclaration { span : lo, sub : subdiagnostic ( lo) } ) ;
243247 Ok ( stmt)
0 commit comments