File tree 3 files changed +14
-1
lines changed
3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ pub enum InstanceDef<'tcx> {
101
101
// because the signature of `<{async fn} as FnMut>::call_mut` is:
102
102
// `fn(&mut self, args: A) -> <Self as FnOnce>::Output`, that is to say
103
103
// that it returns the `FnOnce`-flavored coroutine but takes the closure
104
- // by ref (and similarly for `Fn::call`).
104
+ // by mut ref (and similarly for `Fn::call`).
105
105
receiver_by_ref : bool ,
106
106
} ,
107
107
Original file line number Diff line number Diff line change @@ -2461,6 +2461,10 @@ impl<'tcx> Ty<'tcx> {
2461
2461
/// `AsyncFn`/`AsyncFnMut`/`AsyncFnOnce`, we only need to distinguish two coroutine
2462
2462
/// bodies: by-ref and by-value.
2463
2463
///
2464
+ /// See the definition of `AsyncFn` and `AsyncFnMut` and the `CallRefFuture`
2465
+ /// associated type for why we don't distinguish [`ty::ClosureKind::Fn`] and
2466
+ /// [`ty::ClosureKind::FnMut`] for the purpose of the generated MIR bodies.
2467
+ ///
2464
2468
/// This method should be used when constructing a `Coroutine` out of a
2465
2469
/// `CoroutineClosure`, when the `Coroutine`'s `kind` field is being populated
2466
2470
/// directly from the `CoroutineClosure`'s `kind`.
Original file line number Diff line number Diff line change @@ -1023,7 +1023,16 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
1023
1023
bug ! ( ) ;
1024
1024
} ;
1025
1025
1026
+ // We use `*mut Self` here because we only need to emit an ABI-compatible shim body,
1027
+ // rather than match the signature exactly.
1028
+ //
1029
+ // The self type here is a coroutine-closure, not a coroutine, and we never read from
1030
+ // it because it never has any captures, because this is only true in the Fn/FnMut
1031
+ // implementation, not the AsyncFn/AsyncFnMut implementation, which is implemented only
1032
+ // if the coroutine-closure has no captures.
1026
1033
if receiver_by_ref {
1034
+ // Triple-check that there's no captures here.
1035
+ assert_eq ! ( args. as_coroutine_closure( ) . tupled_upvars_ty( ) , tcx. types. unit) ;
1027
1036
self_ty = Ty :: new_mut_ptr ( tcx, self_ty) ;
1028
1037
}
1029
1038
You can’t perform that action at this time.
0 commit comments