fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>)Expand description
Async desugaring uses an unsafe binder type ResumeTy to circumvert borrow-checking.
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<'_>.
The actual should be &mut Context<'_>. This performs the substitution:
- create a new local
_rof typeResumeTy; - assign
ResumeTy(transmute::<&mut Context<'_>, NonNull<Context<'_>>>(_2))to that local; - let all the code use
_rinstead of_2.
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 coroutine body only knows about &mut Context<'_>.