@@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashSet;
4
4
use rustc_errors:: { self , PResult , Applicability , DiagnosticBuilder , Handler , pluralize} ;
5
5
use rustc_error_codes:: * ;
6
6
use 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 } ;
8
8
use syntax:: token:: { self , TokenKind , token_can_begin_expr} ;
9
9
use syntax:: print:: pprust;
10
10
use syntax:: ptr:: P ;
@@ -970,21 +970,32 @@ impl<'a> Parser<'a> {
970
970
971
971
/// Consumes alternative await syntaxes like `await!(<expr>)`, `await <expr>`,
972
972
/// `await? <expr>`, `await(<expr>)`, and `await { <expr> }`.
973
- pub ( super ) fn parse_incorrect_await_syntax (
973
+ pub ( super ) fn recover_incorrect_await_syntax (
974
974
& mut self ,
975
975
lo : Span ,
976
976
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 {
979
980
// 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
+ }
987
997
998
+ fn recover_await_prefix ( & mut self , await_sp : Span ) -> PResult < ' a , ( Span , P < Expr > , bool ) > {
988
999
let is_question = self . eat ( & token:: Question ) ; // Handle `await? <expr>`.
989
1000
let expr = if self . token == token:: OpenDelim ( token:: Brace ) {
990
1001
// Handle `await { <expr> }`.
@@ -1002,8 +1013,7 @@ impl<'a> Parser<'a> {
1002
1013
err. span_label ( await_sp, "while parsing this incorrect await expression" ) ;
1003
1014
err
1004
1015
} ) ?;
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) )
1007
1017
}
1008
1018
1009
1019
fn error_on_incorrect_await ( & self , lo : Span , hi : Span , expr : & Expr , is_question : bool ) -> Span {
0 commit comments