1
Fork 0

Give items related to issue 33140 a more meaningful name

This commit is contained in:
León Orell Valerian Liehr 2024-04-25 01:58:41 +02:00
parent 20aa2d81e3
commit 9e739b723b
No known key found for this signature in database
GPG key ID: D17A07215F68E713
6 changed files with 49 additions and 46 deletions

View file

@ -243,37 +243,39 @@ fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamE
tcx.param_env(def_id).with_reveal_all_normalized(tcx)
}
/// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`.
/// If the given trait impl enables exploiting the former order dependence of trait objects,
/// returns its self type; otherwise, returns `None`.
///
/// See [`ty::ImplOverlapKind::Issue33140`] for more details.
fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'_>>> {
debug!("issue33140_self_ty({:?})", def_id);
let impl_ = tcx
.impl_trait_header(def_id)
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
/// See [`ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects`] for more details.
#[instrument(level = "debug", skip(tcx))]
fn self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> Option<EarlyBinder<Ty<'_>>> {
let impl_ =
tcx.impl_trait_header(def_id).unwrap_or_else(|| bug!("called on inherent impl {def_id:?}"));
let trait_ref = impl_.trait_ref.skip_binder();
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);
debug!(?trait_ref);
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
// Check whether these impls would be ok for a marker trait.
if !is_marker_like {
debug!("issue33140_self_ty - not marker-like!");
debug!("not marker-like!");
return None;
}
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
if trait_ref.args.len() != 1 {
debug!("issue33140_self_ty - impl has args!");
debug!("impl has args!");
return None;
}
let predicates = tcx.predicates_of(def_id);
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
debug!("issue33140_self_ty - impl has predicates {:?}!", predicates);
debug!(?predicates, "impl has predicates!");
return None;
}
@ -284,10 +286,10 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
};
if self_ty_matches {
debug!("issue33140_self_ty - MATCHES!");
debug!("MATCHES!");
Some(EarlyBinder::bind(self_ty))
} else {
debug!("issue33140_self_ty - non-matching self type");
debug!("non-matching self type");
None
}
}
@ -351,7 +353,7 @@ pub(crate) fn provide(providers: &mut Providers) {
adt_sized_constraint,
param_env,
param_env_reveal_all_normalized,
issue33140_self_ty,
self_ty_of_trait_impl_enabling_order_dep_trait_object_hack,
defaultness,
unsizing_params_for_adt,
..*providers