@@ -521,7 +521,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
521
521
522
522
/// Desugar `<expr>.await` into:
523
523
/// ```rust
524
- /// match <expr> {
524
+ /// match ::std::future::IntoFuture::into_future( <expr>) {
525
525
/// mut pinned => loop {
526
526
/// match ::std::future::poll_with_tls_context(unsafe {
527
527
/// <::std::pin::Pin>::new_unchecked(&mut pinned)
@@ -645,11 +645,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
645
645
// mut pinned => loop { ... }
646
646
let pinned_arm = self . arm ( pinned_pat, loop_expr) ;
647
647
648
- // match <expr> {
648
+ // `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
649
+ let into_future_span = self . mark_span_with_reason (
650
+ DesugaringKind :: Await ,
651
+ await_span,
652
+ self . allow_into_future . clone ( ) ,
653
+ ) ;
654
+ let expr = self . lower_expr_mut ( expr) ;
655
+ let into_future_expr = self . expr_call_std_path (
656
+ into_future_span,
657
+ & [ sym:: future, sym:: IntoFuture , sym:: into_future] ,
658
+ arena_vec ! [ self ; expr] ,
659
+ ) ;
660
+
661
+ // match <into_future_expr> {
649
662
// mut pinned => loop { .. }
650
663
// }
651
- let expr = self . lower_expr ( expr) ;
652
- hir:: ExprKind :: Match ( expr, arena_vec ! [ self ; pinned_arm] , hir:: MatchSource :: AwaitDesugar )
664
+ hir:: ExprKind :: Match (
665
+ into_future_expr,
666
+ arena_vec ! [ self ; pinned_arm] ,
667
+ hir:: MatchSource :: AwaitDesugar ,
668
+ )
653
669
}
654
670
655
671
fn lower_expr_closure (
0 commit comments