@@ -529,7 +529,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
529
529
530
530
/// Desugar `<expr>.await` into:
531
531
/// ```rust
532
- /// match <expr> {
532
+ /// match ::std::future::IntoFuture::into_future( <expr>) {
533
533
/// mut pinned => loop {
534
534
/// match ::std::future::poll_with_tls_context(unsafe {
535
535
/// <::std::pin::Pin>::new_unchecked(&mut pinned)
@@ -653,11 +653,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
653
653
// mut pinned => loop { ... }
654
654
let pinned_arm = self . arm ( pinned_pat, loop_expr) ;
655
655
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> {
657
670
// mut pinned => loop { .. }
658
671
// }
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
+ )
661
677
}
662
678
663
679
fn lower_expr_closure (
0 commit comments