diff options
| author | Eric Holk <ericholk@microsoft.com> | 2021-11-09 10:08:38 -0800 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2021-11-22 14:57:27 -0800 |
| commit | dfa0db59610811529c08c6866712ddefe0e14196 (patch) | |
| tree | ca1527690b2f4fc904b81845ab73e8cb0b565466 /compiler/rustc_ast_lowering/src | |
| parent | 936f2600b6c903b04387f74ed5cbce88bb06d243 (diff) | |
| download | rust-dfa0db59610811529c08c6866712ddefe0e14196.tar.gz rust-dfa0db59610811529c08c6866712ddefe0e14196.zip | |
Reintroduce `into_future` in `.await` desugaring
This is a reintroduction of the remaining parts from https://github.com/rust-lang/rust/pull/65244 that have not been relanded yet. Issues GH-67644, GH-67982
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 2 |
2 files changed, 23 insertions, 5 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index a0a63620c08..8f3bf5d6341 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -593,7 +593,7 @@ impl<'hir> LoweringContext<'_, 'hir> { /// Desugar `<expr>.await` into: /// ```rust - /// match <expr> { + /// match ::std::future::IntoFuture::into_future(<expr>) { /// mut pinned => loop { /// match unsafe { ::std::future::Future::poll( /// <::std::pin::Pin>::new_unchecked(&mut pinned), @@ -629,7 +629,7 @@ impl<'hir> LoweringContext<'_, 'hir> { await_span, self.allow_gen_future.clone(), ); - let expr = self.lower_expr(expr); + let expr = self.lower_expr_mut(expr); let pinned_ident = Ident::with_dummy_span(sym::pinned); let (pinned_pat, pinned_pat_hid) = @@ -746,10 +746,26 @@ impl<'hir> LoweringContext<'_, 'hir> { // mut pinned => loop { ... } let pinned_arm = self.arm(pinned_pat, loop_expr); - // match <expr> { - // mut pinned => loop { .. } + // `match ::std::future::IntoFuture::into_future(<expr>) { ... }` + let into_future_span = self.mark_span_with_reason( + DesugaringKind::Await, + await_span, + self.allow_into_future.clone(), + ); + //let expr = self.lower_expr_mut(expr); + let into_future_expr = self.expr_call_lang_item_fn( + into_future_span, + hir::LangItem::IntoFutureIntoFuture, + arena_vec![self; expr], + ); + + // match <into_future_expr> { // mut pinned => loop { .. } // } - hir::ExprKind::Match(expr, arena_vec![self; pinned_arm], hir::MatchSource::AwaitDesugar) + hir::ExprKind::Match( + into_future_expr, + arena_vec![self; pinned_arm], + hir::MatchSource::AwaitDesugar, + ) } fn lower_expr_closure( diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 2b3a538772e..f5aafda9297 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -162,6 +162,7 @@ struct LoweringContext<'a, 'hir: 'a> { allow_try_trait: Option<Lrc<[Symbol]>>, allow_gen_future: Option<Lrc<[Symbol]>>, + allow_into_future: Option<Lrc<[Symbol]>>, } pub trait ResolverAstLowering { @@ -320,6 +321,7 @@ pub fn lower_crate<'a, 'hir>( in_scope_lifetimes: Vec::new(), allow_try_trait: Some([sym::try_trait_v2][..].into()), allow_gen_future: Some([sym::gen_future][..].into()), + allow_into_future: Some([sym::into_future][..].into()), } .lower_crate(krate) } |
