Add a builtin FnPtr
trait
This commit is contained in:
parent
7a0600714a
commit
0c13565ca6
20 changed files with 310 additions and 27 deletions
|
@ -381,7 +381,8 @@ impl<'tcx> CodegenUnit<'tcx> {
|
|||
| InstanceDef::Virtual(..)
|
||||
| InstanceDef::ClosureOnceShim { .. }
|
||||
| InstanceDef::DropGlue(..)
|
||||
| InstanceDef::CloneShim(..) => None,
|
||||
| InstanceDef::CloneShim(..)
|
||||
| InstanceDef::FnPtrAddrShim(..) => None,
|
||||
}
|
||||
}
|
||||
MonoItem::Static(def_id) => def_id.as_local().map(Idx::index),
|
||||
|
|
|
@ -340,7 +340,8 @@ macro_rules! make_mir_visitor {
|
|||
|
||||
ty::InstanceDef::FnPtrShim(_def_id, ty) |
|
||||
ty::InstanceDef::DropGlue(_def_id, Some(ty)) |
|
||||
ty::InstanceDef::CloneShim(_def_id, ty) => {
|
||||
ty::InstanceDef::CloneShim(_def_id, ty) |
|
||||
ty::InstanceDef::FnPtrAddrShim(_def_id, ty) => {
|
||||
// FIXME(eddyb) use a better `TyContext` here.
|
||||
self.visit_ty($(& $mutability)? *ty, TyContext::Location(location));
|
||||
}
|
||||
|
|
|
@ -96,6 +96,13 @@ pub enum InstanceDef<'tcx> {
|
|||
///
|
||||
/// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl.
|
||||
CloneShim(DefId, Ty<'tcx>),
|
||||
|
||||
/// Compiler-generated `<T as FnPtr>::addr` implementation.
|
||||
///
|
||||
/// Automatically generated for all potentially higher-ranked `fn(I) -> R` types.
|
||||
///
|
||||
/// The `DefId` is for `FnPtr::addr`, the `Ty` is the type `T`.
|
||||
FnPtrAddrShim(DefId, Ty<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> Instance<'tcx> {
|
||||
|
@ -151,7 +158,8 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
| InstanceDef::Intrinsic(def_id)
|
||||
| InstanceDef::ClosureOnceShim { call_once: def_id, track_caller: _ }
|
||||
| InstanceDef::DropGlue(def_id, _)
|
||||
| InstanceDef::CloneShim(def_id, _) => def_id,
|
||||
| InstanceDef::CloneShim(def_id, _)
|
||||
| InstanceDef::FnPtrAddrShim(def_id, _) => def_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +175,8 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
| InstanceDef::Intrinsic(..)
|
||||
| InstanceDef::ClosureOnceShim { .. }
|
||||
| InstanceDef::DropGlue(..)
|
||||
| InstanceDef::CloneShim(..) => None,
|
||||
| InstanceDef::CloneShim(..)
|
||||
| InstanceDef::FnPtrAddrShim(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +191,8 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
| InstanceDef::Intrinsic(def_id)
|
||||
| InstanceDef::ClosureOnceShim { call_once: def_id, track_caller: _ }
|
||||
| InstanceDef::DropGlue(def_id, _)
|
||||
| InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::unknown(def_id),
|
||||
| InstanceDef::CloneShim(def_id, _)
|
||||
| InstanceDef::FnPtrAddrShim(def_id, _) => ty::WithOptConstParam::unknown(def_id),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,6 +278,7 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
pub fn has_polymorphic_mir_body(&self) -> bool {
|
||||
match *self {
|
||||
InstanceDef::CloneShim(..)
|
||||
| InstanceDef::FnPtrAddrShim(..)
|
||||
| InstanceDef::FnPtrShim(..)
|
||||
| InstanceDef::DropGlue(_, Some(_)) => false,
|
||||
InstanceDef::ClosureOnceShim { .. }
|
||||
|
@ -306,6 +317,7 @@ fn fmt_instance(
|
|||
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
|
||||
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
|
||||
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
|
||||
InstanceDef::FnPtrAddrShim(_, ty) => write!(f, " - shim({})", ty),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2284,12 +2284,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
def_id1: DefId,
|
||||
def_id2: DefId,
|
||||
) -> Option<ImplOverlapKind> {
|
||||
let impl_trait_ref1 = self.impl_trait_ref(def_id1);
|
||||
let impl_trait_ref2 = self.impl_trait_ref(def_id2);
|
||||
// If either trait impl references an error, they're allowed to overlap,
|
||||
// as one of them essentially doesn't exist.
|
||||
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.subst_identity().references_error())
|
||||
|| self
|
||||
.impl_trait_ref(def_id2)
|
||||
.map_or(false, |tr| tr.subst_identity().references_error())
|
||||
if impl_trait_ref1.map_or(false, |tr| tr.subst_identity().references_error())
|
||||
|| impl_trait_ref2.map_or(false, |tr| tr.subst_identity().references_error())
|
||||
{
|
||||
return Some(ImplOverlapKind::Permitted { marker: false });
|
||||
}
|
||||
|
@ -2317,11 +2317,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
};
|
||||
|
||||
let is_marker_overlap = {
|
||||
let is_marker_impl = |def_id: DefId| -> bool {
|
||||
let trait_ref = self.impl_trait_ref(def_id);
|
||||
let is_marker_impl = |trait_ref: Option<EarlyBinder<TraitRef<'_>>>| -> bool {
|
||||
trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker)
|
||||
};
|
||||
is_marker_impl(def_id1) && is_marker_impl(def_id2)
|
||||
is_marker_impl(impl_trait_ref1) && is_marker_impl(impl_trait_ref2)
|
||||
};
|
||||
|
||||
if is_marker_overlap {
|
||||
|
@ -2405,7 +2404,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
| ty::InstanceDef::Virtual(..)
|
||||
| ty::InstanceDef::ClosureOnceShim { .. }
|
||||
| ty::InstanceDef::DropGlue(..)
|
||||
| ty::InstanceDef::CloneShim(..) => self.mir_shims(instance),
|
||||
| ty::InstanceDef::CloneShim(..)
|
||||
| ty::InstanceDef::FnPtrAddrShim(..) => self.mir_shims(instance),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue