diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_ty_utils/src/instance.rs | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ty_utils/src/instance.rs')
-rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 2eaeca73d..0a6c11809 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -8,6 +8,8 @@ use rustc_span::sym; use rustc_trait_selection::traits; use traits::{translate_substs, Reveal}; +use crate::errors::UnexpectedFnPtrAssociatedItem; + fn resolve_instance<'tcx>( tcx: TyCtxt<'tcx>, key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>, @@ -243,7 +245,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 +273,21 @@ 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.emit_fatal(UnexpectedFnPtrAssociatedItem { + span: tcx.def_span(trait_item_id), + }) + } } else { None } |