diff options
| author | Michael Goulet <michael@errs.io> | 2024-02-05 19:59:05 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-02-06 20:52:13 +0000 |
| commit | b8c93f1223695217cbabc1f3f1e428c358bb4e7a (patch) | |
| tree | 26e652c7a756bc99db9b2c1c95bf03c3e72b531d /compiler/rustc_ty_utils/src/instance.rs | |
| parent | 08af64e96be28c3680d6e8c96d437a560d3a9ae3 (diff) | |
| download | rust-b8c93f1223695217cbabc1f3f1e428c358bb4e7a.tar.gz rust-b8c93f1223695217cbabc1f3f1e428c358bb4e7a.zip | |
Coroutine closures implement regular Fn traits, when possible
Diffstat (limited to 'compiler/rustc_ty_utils/src/instance.rs')
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index bcc7c98ed69..eae80199ce5 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -278,6 +278,24 @@ fn resolve_associated_item<'tcx>( def: ty::InstanceDef::FnPtrShim(trait_item_id, rcvr_args.type_at(0)), args: rcvr_args, }), + ty::CoroutineClosure(coroutine_closure_def_id, args) => { + // When a coroutine-closure implements the `Fn` traits, then it + // always dispatches to the `FnOnce` implementation. This is to + // ensure that the `closure_kind` of the resulting closure is in + // sync with the built-in trait implementations (since all of the + // implementations return `FnOnce::Output`). + if ty::ClosureKind::FnOnce == args.as_coroutine_closure().kind() { + Some(Instance::new(coroutine_closure_def_id, args)) + } else { + Some(Instance { + def: ty::InstanceDef::ConstructCoroutineInClosureShim { + coroutine_closure_def_id, + target_kind: ty::ClosureKind::FnOnce, + }, + args, + }) + } + } _ => bug!( "no built-in definition for `{trait_ref}::{}` for non-fn type", tcx.item_name(trait_item_id) |
