@@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashSet;
44use rustc_errors:: { self , PResult , Applicability , DiagnosticBuilder , Handler , pluralize} ;
55use rustc_error_codes:: * ;
66use syntax:: ast:: { self , Param , BinOpKind , BindingMode , BlockCheckMode , Expr , ExprKind , Ident , Item } ;
7- use syntax:: ast:: { ItemKind , Mutability , Pat , PatKind , PathSegment , QSelf , Ty , TyKind } ;
7+ use syntax:: ast:: { ItemKind , Mutability , Pat , PatKind , PathSegment , QSelf , Ty , TyKind , Attribute } ;
88use syntax:: token:: { self , TokenKind , token_can_begin_expr} ;
99use syntax:: print:: pprust;
1010use syntax:: ptr:: P ;
@@ -970,21 +970,32 @@ impl<'a> Parser<'a> {
970970
971971 /// Consumes alternative await syntaxes like `await!(<expr>)`, `await <expr>`,
972972 /// `await? <expr>`, `await(<expr>)`, and `await { <expr> }`.
973- pub ( super ) fn parse_incorrect_await_syntax (
973+ pub ( super ) fn recover_incorrect_await_syntax (
974974 & mut self ,
975975 lo : Span ,
976976 await_sp : Span ,
977- ) -> PResult < ' a , ( Span , ExprKind ) > {
978- if self . token == token:: Not {
977+ attrs : ThinVec < Attribute > ,
978+ ) -> PResult < ' a , P < Expr > > {
979+ let ( hi, expr, is_question) = if self . token == token:: Not {
979980 // Handle `await!(<expr>)`.
980- self . expect ( & token:: Not ) ?;
981- self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
982- let expr = self . parse_expr ( ) ?;
983- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
984- let sp = self . error_on_incorrect_await ( lo, self . prev_span , & expr, false ) ;
985- return Ok ( ( sp, ExprKind :: Await ( expr) ) )
986- }
981+ self . recover_await_macro ( ) ?
982+ } else {
983+ self . recover_await_prefix ( await_sp) ?
984+ } ;
985+ let sp = self . error_on_incorrect_await ( lo, hi, & expr, is_question) ;
986+ let expr = self . mk_expr ( lo. to ( sp) , ExprKind :: Await ( expr) , attrs) ;
987+ self . maybe_recover_from_bad_qpath ( expr, true )
988+ }
989+
990+ fn recover_await_macro ( & mut self ) -> PResult < ' a , ( Span , P < Expr > , bool ) > {
991+ self . expect ( & token:: Not ) ?;
992+ self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
993+ let expr = self . parse_expr ( ) ?;
994+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
995+ Ok ( ( self . prev_span , expr, false ) )
996+ }
987997
998+ fn recover_await_prefix ( & mut self , await_sp : Span ) -> PResult < ' a , ( Span , P < Expr > , bool ) > {
988999 let is_question = self . eat ( & token:: Question ) ; // Handle `await? <expr>`.
9891000 let expr = if self . token == token:: OpenDelim ( token:: Brace ) {
9901001 // Handle `await { <expr> }`.
@@ -1002,8 +1013,7 @@ impl<'a> Parser<'a> {
10021013 err. span_label ( await_sp, "while parsing this incorrect await expression" ) ;
10031014 err
10041015 } ) ?;
1005- let sp = self . error_on_incorrect_await ( lo, expr. span , & expr, is_question) ;
1006- Ok ( ( sp, ExprKind :: Await ( expr) ) )
1016+ Ok ( ( expr. span , expr, is_question) )
10071017 }
10081018
10091019 fn error_on_incorrect_await ( & self , lo : Span , hi : Span , expr : & Expr , is_question : bool ) -> Span {
0 commit comments