diff options
| author | bors <bors@rust-lang.org> | 2021-12-03 19:29:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-12-03 19:29:21 +0000 |
| commit | 532d2b14c05f9bc20b2d27cbb5f4550d28343a36 (patch) | |
| tree | f5cd6b242f405ec86b164ecfe8faf283d064ea75 /compiler/rustc_ast_lowering/src | |
| parent | ff2439b7b9bafcfdff86b7847128014699df8442 (diff) | |
| parent | 3268bf1d31227d0422c90b2259e67ba12ed19e3f (diff) | |
| download | rust-532d2b14c05f9bc20b2d27cbb5f4550d28343a36.tar.gz rust-532d2b14c05f9bc20b2d27cbb5f4550d28343a36.zip | |
Auto merge of #90737 - eholk:intofuture, r=tmandry
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. This isn't quite ready to merge yet. The last attempt was reverting due to performance regressions, so we need to make sure this does not introduce those issues again. Issues #67644, #67982 /cc `@yoshuawuyts`
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 2 |
2 files changed, 22 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 9c579209fe5..c9578c2f50f 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> { + // `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 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 2a246a99a70..1a4f0a26f2b 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) } |
