@@ -314,6 +314,17 @@ struct IncorrectUseOfAwait {
314
314
span : Span ,
315
315
}
316
316
317
+ #[ derive( SessionDiagnostic ) ]
318
+ #[ error( slug = "parser-incorrect-await" ) ]
319
+ struct IncorrectAwait {
320
+ #[ primary_span]
321
+ span : Span ,
322
+ #[ suggestion( code = "{expr}.await{question_mark}" ) ]
323
+ sugg_span : ( Span , Applicability ) ,
324
+ expr : String ,
325
+ question_mark : & ' static str ,
326
+ }
327
+
317
328
// SnapshotParser is used to create a snapshot of the parser
318
329
// without causing duplicate errors being emitted when the `Parser`
319
330
// is dropped.
@@ -1643,18 +1654,20 @@ impl<'a> Parser<'a> {
1643
1654
}
1644
1655
1645
1656
fn error_on_incorrect_await ( & self , lo : Span , hi : Span , expr : & Expr , is_question : bool ) -> Span {
1646
- let expr_str =
1647
- self . span_to_snippet ( expr. span ) . unwrap_or_else ( |_| pprust:: expr_to_string ( & expr) ) ;
1648
- let suggestion = format ! ( "{}.await{}" , expr_str, if is_question { "?" } else { "" } ) ;
1649
- let sp = lo. to ( hi) ;
1650
- let app = match expr. kind {
1657
+ let span = lo. to ( hi) ;
1658
+ let applicability = match expr. kind {
1651
1659
ExprKind :: Try ( _) => Applicability :: MaybeIncorrect , // `await <expr>?`
1652
1660
_ => Applicability :: MachineApplicable ,
1653
1661
} ;
1654
- self . struct_span_err ( sp, "incorrect use of `await`" )
1655
- . span_suggestion ( sp, "`await` is a postfix operation" , suggestion, app)
1656
- . emit ( ) ;
1657
- sp
1662
+
1663
+ self . sess . emit_err ( IncorrectAwait {
1664
+ span,
1665
+ sugg_span : ( span, applicability) ,
1666
+ expr : self . span_to_snippet ( expr. span ) . unwrap_or_else ( |_| pprust:: expr_to_string ( & expr) ) ,
1667
+ question_mark : if is_question { "?" } else { "" } ,
1668
+ } ) ;
1669
+
1670
+ span
1658
1671
}
1659
1672
1660
1673
/// If encountering `future.await()`, consumes and emits an error.
0 commit comments