diff options
| author | bors <bors@rust-lang.org> | 2023-03-28 12:50:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-28 12:50:01 +0000 |
| commit | bf57e8ada6dc62369d1cee7ab055fb4074bd2d10 (patch) | |
| tree | 21cb8bce941e422c139fe496537d8ab823fadccc /compiler/rustc_ty_utils/src | |
| parent | 60660371efe59dfc99644e9d709a1b71e25ae2ac (diff) | |
| parent | 5ae6caa0f04c686f0cc8a330f54390131148f899 (diff) | |
| download | rust-bf57e8ada6dc62369d1cee7ab055fb4074bd2d10.tar.gz rust-bf57e8ada6dc62369d1cee7ab055fb4074bd2d10.zip | |
Auto merge of #108080 - oli-obk:FnPtr-trait, r=lcnr
Add a builtin `FnPtr` trait that is implemented for all function pointers r? `@ghost` Rebased version of https://github.com/rust-lang/rust/pull/99531 (plus adjustments mentioned in the PR). If perf is happy with this version, I would like to land it, even if the diagnostics fix in 9df8e1befb5031a5bf9d8dfe25170620642d3c59 only works for `FnPtr` specifically, and does not generally improve blanket impls.
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 2eaeca73da7..ad70154c98e 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -243,7 +243,8 @@ fn resolve_associated_item<'tcx>( } } traits::ImplSource::Builtin(..) => { - if Some(trait_ref.def_id) == tcx.lang_items().clone_trait() { + let lang_items = tcx.lang_items(); + if Some(trait_ref.def_id) == lang_items.clone_trait() { // FIXME(eddyb) use lang items for methods instead of names. let name = tcx.item_name(trait_item_id); if name == sym::clone { @@ -270,6 +271,22 @@ fn resolve_associated_item<'tcx>( let substs = tcx.erase_regions(rcvr_substs); Some(ty::Instance::new(trait_item_id, substs)) } + } else if Some(trait_ref.def_id) == lang_items.fn_ptr_trait() { + if lang_items.fn_ptr_addr() == Some(trait_item_id) { + let self_ty = trait_ref.self_ty(); + if !matches!(self_ty.kind(), ty::FnPtr(..)) { + return Ok(None); + } + Some(Instance { + def: ty::InstanceDef::FnPtrAddrShim(trait_item_id, self_ty), + substs: rcvr_substs, + }) + } else { + tcx.sess.span_fatal( + tcx.def_span(trait_item_id), + "`FnPtrAddr` trait with unexpected assoc item", + ) + } } else { None } |
