diff options
| author | Michael Goulet <michael@errs.io> | 2024-02-28 20:25:25 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-03-19 16:59:24 -0400 |
| commit | f1fef64e19909487ff2640bce58ce49fcfb4b85d (patch) | |
| tree | 7281d36cff4865852e3d9c6193ba6689204ab033 /compiler/rustc_ty_utils/src | |
| parent | 05116c5c30dea6895fb65fe31b6f2dd0f1198b51 (diff) | |
| download | rust-f1fef64e19909487ff2640bce58ce49fcfb4b85d.tar.gz rust-f1fef64e19909487ff2640bce58ce49fcfb4b85d.zip | |
Fix ABI for FnMut/Fn impls for async closures
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/abi.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 7d54083fbd5..baf4de768c5 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -118,11 +118,18 @@ fn fn_sig_for_fn_abi<'tcx>( // a separate def-id for these bodies. let mut coroutine_kind = args.as_coroutine_closure().kind(); - if let InstanceDef::ConstructCoroutineInClosureShim { .. } = instance.def { - coroutine_kind = ty::ClosureKind::FnOnce; - } + let env_ty = + if let InstanceDef::ConstructCoroutineInClosureShim { receiver_by_ref, .. } = + instance.def + { + coroutine_kind = ty::ClosureKind::FnOnce; - let env_ty = tcx.closure_env_ty(coroutine_ty, coroutine_kind, env_region); + // Implementations of `FnMut` and `Fn` for coroutine-closures + // still take their receiver by ref. + if receiver_by_ref { Ty::new_mut_ptr(tcx, coroutine_ty) } else { coroutine_ty } + } else { + tcx.closure_env_ty(coroutine_ty, coroutine_kind, env_region) + }; let sig = sig.skip_binder(); ty::Binder::bind_with_vars( diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index c2ea89f4c29..a8f9afb87dd 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -282,6 +282,7 @@ fn resolve_associated_item<'tcx>( Some(Instance { def: ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id, + receiver_by_ref: target_kind != ty::ClosureKind::FnOnce, }, args, }) @@ -304,6 +305,7 @@ fn resolve_associated_item<'tcx>( Some(Instance { def: ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id, + receiver_by_ref: false, }, args, }) |
