Function rustc_mir_transform::generator::transform_async_context
source · fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>)Expand description
Transforms the body of the generator applying the following transforms:
- Eliminates all the
get_contextcalls that async lowering created. - Replace all
LocalResumeTytypes with&mut Context<'_>(context_mut_ref).
The Locals that have their types replaced are:
- The
resumeargument itself. - The argument to
get_context. - The yielded value of a
yield.
The ResumeTy hides a &mut Context<'_> behind an unsafe raw pointer, and the
get_context function is being used to convert that back to a &mut Context<'_>.
Ideally the async lowering would not use the ResumeTy/get_context indirection,
but rather directly use &mut Context<'_>, however that would currently
lead to higher-kinded lifetime errors.
See https://github.com/rust-lang/rust/issues/105501.
The async lowering step and the type / lifetime inference / checking are
still using the ResumeTy indirection for the time being, and that indirection
is removed here. After this transform, the generator body only knows about &mut Context<'_>.