@@ -529,7 +529,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
529529
530530 /// Desugar `<expr>.await` into:
531531 /// ```rust
532- /// match <expr> {
532+ /// match ::std::future::IntoFuture::into_future( <expr>) {
533533 /// mut pinned => loop {
534534 /// match ::std::future::poll_with_tls_context(unsafe {
535535 /// <::std::pin::Pin>::new_unchecked(&mut pinned)
@@ -653,11 +653,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
653653 // mut pinned => loop { ... }
654654 let pinned_arm = self . arm ( pinned_pat, loop_expr) ;
655655
656- // match <expr> {
656+ // `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
657+ let into_future_span = self . mark_span_with_reason (
658+ DesugaringKind :: Await ,
659+ await_span,
660+ self . allow_into_future . clone ( ) ,
661+ ) ;
662+ let expr = self . lower_expr_mut ( expr) ;
663+ let into_future_expr = self . expr_call_std_path (
664+ into_future_span,
665+ & [ sym:: future, sym:: IntoFuture , sym:: into_future] ,
666+ arena_vec ! [ self ; expr] ,
667+ ) ;
668+
669+ // match <into_future_expr> {
657670 // mut pinned => loop { .. }
658671 // }
659- let expr = self . lower_expr ( expr) ;
660- hir:: ExprKind :: Match ( expr, arena_vec ! [ self ; pinned_arm] , hir:: MatchSource :: AwaitDesugar )
672+ hir:: ExprKind :: Match (
673+ into_future_expr,
674+ arena_vec ! [ self ; pinned_arm] ,
675+ hir:: MatchSource :: AwaitDesugar ,
676+ )
661677 }
662678
663679 fn lower_expr_closure (
0 commit comments