@@ -56,9 +56,9 @@ use std::ops;
5656
5757pub ( super ) use by_move_body:: coroutine_by_move_body_def_id;
5858use drop:: {
59- cleanup_async_drops , create_coroutine_drop_shim, create_coroutine_drop_shim_async,
60- create_coroutine_drop_shim_proxy_async, elaborate_coroutine_drops, expand_async_drops ,
61- has_expandable_async_drops , insert_clean_drop,
59+ create_coroutine_drop_shim, create_coroutine_drop_shim_async,
60+ create_coroutine_drop_shim_proxy_async, elaborate_coroutine_drops, has_async_drops ,
61+ insert_clean_drop,
6262} ;
6363use itertools:: izip;
6464use rustc_abi:: { FieldIdx , VariantIdx } ;
@@ -70,7 +70,6 @@ use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet};
7070use rustc_index:: { Idx , IndexVec , indexvec} ;
7171use rustc_middle:: mir:: visit:: { MutVisitor , MutatingUseContext , PlaceContext , Visitor } ;
7272use rustc_middle:: mir:: * ;
73- use rustc_middle:: ty:: util:: Discr ;
7473use rustc_middle:: ty:: {
7574 self , CoroutineArgs , CoroutineArgsExt , GenericArgsRef , InstanceKind , Ty , TyCtxt , TypingMode ,
7675} ;
@@ -82,8 +81,8 @@ use rustc_mir_dataflow::impls::{
8281use rustc_mir_dataflow:: {
8382 Analysis , Results , ResultsCursor , ResultsVisitor , visit_reachable_results,
8483} ;
84+ use rustc_span:: Span ;
8585use rustc_span:: def_id:: { DefId , LocalDefId } ;
86- use rustc_span:: { DUMMY_SP , Span , dummy_spanned} ;
8786use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
8887use rustc_trait_selection:: infer:: TyCtxtInferExt as _;
8988use rustc_trait_selection:: traits:: { ObligationCause , ObligationCauseCode , ObligationCtxt } ;
@@ -169,7 +168,7 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx
169168}
170169
171170const SELF_ARG : Local = Local :: arg ( 0 ) ;
172- const CTX_ARG : Local = Local :: arg ( 1 ) ;
171+ pub ( crate ) const CTX_ARG : Local = Local :: arg ( 1 ) ;
173172
174173/// A `yield` point in the coroutine.
175174struct SuspensionPoint < ' tcx > {
@@ -585,7 +584,7 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
585584/// still using the `ResumeTy` indirection for the time being, and that indirection
586585/// is removed here. After this transform, the coroutine body only knows about `&mut Context<'_>`.
587586#[ tracing:: instrument( level = "trace" , skip( tcx, body) , ret) ]
588- fn transform_async_context < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) -> Ty < ' tcx > {
587+ fn transform_async_context < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
589588 let context_mut_ref = Ty :: new_task_context ( tcx) ;
590589
591590 // replace the type of the `resume` argument
@@ -615,7 +614,6 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> Ty
615614 _ => { }
616615 }
617616 }
618- context_mut_ref
619617}
620618
621619fn eliminate_get_context_call < ' tcx > ( bb_data : & mut BasicBlockData < ' tcx > ) -> Local {
@@ -1522,24 +1520,12 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
15221520 // (finally in open_drop_for_tuple) before async drop expansion.
15231521 // Async drops, produced by this drop elaboration, will be expanded,
15241522 // and corresponding futures kept in layout.
1525- let has_async_drops = matches ! (
1526- coroutine_kind,
1527- CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _)
1528- ) && has_expandable_async_drops ( tcx, body, coroutine_ty) ;
1523+ let coroutine_is_async = coroutine_kind. is_async_desugaring ( ) ;
1524+ let has_async_drops = has_async_drops ( body) ;
15291525
15301526 // Replace all occurrences of `ResumeTy` with `&mut Context<'_>` within async bodies.
1531- if matches ! (
1532- coroutine_kind,
1533- CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _)
1534- ) {
1535- let context_mut_ref = transform_async_context ( tcx, body) ;
1536- expand_async_drops ( tcx, body, context_mut_ref, coroutine_kind, coroutine_ty) ;
1537-
1538- if let Some ( dumper) = MirDumper :: new ( tcx, "coroutine_async_drop_expand" , body) {
1539- dumper. dump_mir ( body) ;
1540- }
1541- } else {
1542- cleanup_async_drops ( body) ;
1527+ if coroutine_is_async {
1528+ transform_async_context ( tcx, body) ;
15431529 }
15441530
15451531 let always_live_locals = always_storage_live_locals ( body) ;
0 commit comments