Skip to content

Commit 541858e

Browse files
Add a few more comments
1 parent f1fef64 commit 541858e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub enum InstanceDef<'tcx> {
101101
// because the signature of `<{async fn} as FnMut>::call_mut` is:
102102
// `fn(&mut self, args: A) -> <Self as FnOnce>::Output`, that is to say
103103
// 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`).
105105
receiver_by_ref: bool,
106106
},
107107

compiler/rustc_middle/src/ty/sty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,10 @@ impl<'tcx> Ty<'tcx> {
24612461
/// `AsyncFn`/`AsyncFnMut`/`AsyncFnOnce`, we only need to distinguish two coroutine
24622462
/// bodies: by-ref and by-value.
24632463
///
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+
///
24642468
/// This method should be used when constructing a `Coroutine` out of a
24652469
/// `CoroutineClosure`, when the `Coroutine`'s `kind` field is being populated
24662470
/// directly from the `CoroutineClosure`'s `kind`.

compiler/rustc_mir_transform/src/shim.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,16 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
10231023
bug!();
10241024
};
10251025

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.
10261033
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);
10271036
self_ty = Ty::new_mut_ptr(tcx, self_ty);
10281037
}
10291038

0 commit comments

Comments
 (0)