Give items related to issue 33140 a more meaningful name
This commit is contained in:
parent
20aa2d81e3
commit
9e739b723b
6 changed files with 49 additions and 46 deletions
|
@ -847,8 +847,10 @@ rustc_queries! {
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
||||||
query issue33140_self_ty(key: DefId) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
|
query self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
|
||||||
desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
|
key: DefId
|
||||||
|
) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
|
||||||
|
desc { |tcx| "computing self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maps a `DefId` of a type to a list of its inherent impls.
|
/// Maps a `DefId` of a type to a list of its inherent impls.
|
||||||
|
|
|
@ -1503,14 +1503,14 @@ pub enum ImplOverlapKind {
|
||||||
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
|
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
|
||||||
marker: bool,
|
marker: bool,
|
||||||
},
|
},
|
||||||
/// These impls are allowed to overlap, but that raises
|
/// These impls are allowed to overlap, but that raises an
|
||||||
/// an issue #33140 future-compatibility warning.
|
/// issue #33140 future-compatibility warning (tracked in #56484).
|
||||||
///
|
///
|
||||||
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
|
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
|
||||||
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
|
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
|
||||||
///
|
///
|
||||||
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
|
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied on
|
||||||
/// that difference, making what reduces to the following set of impls:
|
/// that difference, doing what reduces to the following set of impls:
|
||||||
///
|
///
|
||||||
/// ```compile_fail,(E0119)
|
/// ```compile_fail,(E0119)
|
||||||
/// trait Trait {}
|
/// trait Trait {}
|
||||||
|
@ -1535,7 +1535,7 @@ pub enum ImplOverlapKind {
|
||||||
/// 4. Neither of the impls can have any where-clauses.
|
/// 4. Neither of the impls can have any where-clauses.
|
||||||
///
|
///
|
||||||
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
|
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
|
||||||
Issue33140,
|
FutureCompatOrderDepTraitObjects,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Useful source information about where a desugared associated type for an
|
/// Useful source information about where a desugared associated type for an
|
||||||
|
@ -1730,28 +1730,27 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
|
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_marker_overlap = {
|
let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
|
||||||
let is_marker_impl =
|
let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
|
||||||
|trait_ref: TraitRef<'_>| -> bool { self.trait_def(trait_ref.def_id).is_marker };
|
|
||||||
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2)
|
|
||||||
};
|
|
||||||
|
|
||||||
if is_marker_overlap {
|
if is_marker_overlap {
|
||||||
Some(ImplOverlapKind::Permitted { marker: true })
|
return Some(ImplOverlapKind::Permitted { marker: true });
|
||||||
} else {
|
}
|
||||||
if let Some(self_ty1) = self.issue33140_self_ty(def_id1) {
|
|
||||||
if let Some(self_ty2) = self.issue33140_self_ty(def_id2) {
|
if let Some(self_ty1) =
|
||||||
|
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id1)
|
||||||
|
&& let Some(self_ty2) =
|
||||||
|
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id2)
|
||||||
|
{
|
||||||
if self_ty1 == self_ty2 {
|
if self_ty1 == self_ty2 {
|
||||||
return Some(ImplOverlapKind::Issue33140);
|
return Some(ImplOverlapKind::FutureCompatOrderDepTraitObjects);
|
||||||
} else {
|
} else {
|
||||||
debug!("found {self_ty1:?} != {self_ty2:?}");
|
debug!("found {self_ty1:?} != {self_ty2:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `ty::VariantDef` if `res` refers to a struct,
|
/// Returns `ty::VariantDef` if `res` refers to a struct,
|
||||||
/// or variant or their constructors, panics otherwise.
|
/// or variant or their constructors, panics otherwise.
|
||||||
|
|
|
@ -2001,7 +2001,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||||
// any associated items and there are no where-clauses.
|
// any associated items and there are no where-clauses.
|
||||||
//
|
//
|
||||||
// We can just arbitrarily drop one of the impls.
|
// We can just arbitrarily drop one of the impls.
|
||||||
Some(ty::ImplOverlapKind::Issue33140) => {
|
Some(ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects) => {
|
||||||
assert_eq!(other.evaluation, victim.evaluation);
|
assert_eq!(other.evaluation, victim.evaluation);
|
||||||
DropVictim::Yes
|
DropVictim::Yes
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,7 +453,7 @@ fn report_conflicting_impls<'tcx>(
|
||||||
overlap.trait_ref.print_trait_sugared(),
|
overlap.trait_ref.print_trait_sugared(),
|
||||||
overlap.self_ty.map_or_else(String::new, |ty| format!(" for type `{ty}`")),
|
overlap.self_ty.map_or_else(String::new, |ty| format!(" for type `{ty}`")),
|
||||||
match used_to_be_allowed {
|
match used_to_be_allowed {
|
||||||
Some(FutureCompatOverlapErrorKind::Issue33140) => ": (E0119)",
|
Some(FutureCompatOverlapErrorKind::OrderDepTraitObjects) => ": (E0119)",
|
||||||
_ => "",
|
_ => "",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -480,7 +480,7 @@ fn report_conflicting_impls<'tcx>(
|
||||||
}
|
}
|
||||||
Some(kind) => {
|
Some(kind) => {
|
||||||
let lint = match kind {
|
let lint = match kind {
|
||||||
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
|
FutureCompatOverlapErrorKind::OrderDepTraitObjects => ORDER_DEPENDENT_TRAIT_OBJECTS,
|
||||||
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
|
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
|
||||||
};
|
};
|
||||||
tcx.node_span_lint(
|
tcx.node_span_lint(
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub use rustc_middle::traits::specialization_graph::*;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum FutureCompatOverlapErrorKind {
|
pub enum FutureCompatOverlapErrorKind {
|
||||||
Issue33140,
|
OrderDepTraitObjects,
|
||||||
LeakCheck,
|
LeakCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +150,10 @@ impl<'tcx> Children {
|
||||||
{
|
{
|
||||||
match overlap_kind {
|
match overlap_kind {
|
||||||
ty::ImplOverlapKind::Permitted { marker: _ } => {}
|
ty::ImplOverlapKind::Permitted { marker: _ } => {}
|
||||||
ty::ImplOverlapKind::Issue33140 => {
|
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
|
||||||
*last_lint_mut = Some(FutureCompatOverlapError {
|
*last_lint_mut = Some(FutureCompatOverlapError {
|
||||||
error: create_overlap_error(overlap),
|
error: create_overlap_error(overlap),
|
||||||
kind: FutureCompatOverlapErrorKind::Issue33140,
|
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
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.
|
/// See [`ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects`] for more details.
|
||||||
fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'_>>> {
|
#[instrument(level = "debug", skip(tcx))]
|
||||||
debug!("issue33140_self_ty({:?})", def_id);
|
fn self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
let impl_ = tcx
|
def_id: DefId,
|
||||||
.impl_trait_header(def_id)
|
) -> Option<EarlyBinder<Ty<'_>>> {
|
||||||
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
|
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();
|
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
|
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive
|
||||||
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
|
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
|
||||||
|
|
||||||
// Check whether these impls would be ok for a marker trait.
|
// Check whether these impls would be ok for a marker trait.
|
||||||
if !is_marker_like {
|
if !is_marker_like {
|
||||||
debug!("issue33140_self_ty - not marker-like!");
|
debug!("not marker-like!");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
|
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
|
||||||
if trait_ref.args.len() != 1 {
|
if trait_ref.args.len() != 1 {
|
||||||
debug!("issue33140_self_ty - impl has args!");
|
debug!("impl has args!");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let predicates = tcx.predicates_of(def_id);
|
let predicates = tcx.predicates_of(def_id);
|
||||||
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
|
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
|
||||||
debug!("issue33140_self_ty - impl has predicates {:?}!", predicates);
|
debug!(?predicates, "impl has predicates!");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,10 +286,10 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
|
||||||
};
|
};
|
||||||
|
|
||||||
if self_ty_matches {
|
if self_ty_matches {
|
||||||
debug!("issue33140_self_ty - MATCHES!");
|
debug!("MATCHES!");
|
||||||
Some(EarlyBinder::bind(self_ty))
|
Some(EarlyBinder::bind(self_ty))
|
||||||
} else {
|
} else {
|
||||||
debug!("issue33140_self_ty - non-matching self type");
|
debug!("non-matching self type");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +353,7 @@ pub(crate) fn provide(providers: &mut Providers) {
|
||||||
adt_sized_constraint,
|
adt_sized_constraint,
|
||||||
param_env,
|
param_env,
|
||||||
param_env_reveal_all_normalized,
|
param_env_reveal_all_normalized,
|
||||||
issue33140_self_ty,
|
self_ty_of_trait_impl_enabling_order_dep_trait_object_hack,
|
||||||
defaultness,
|
defaultness,
|
||||||
unsizing_params_for_adt,
|
unsizing_params_for_adt,
|
||||||
..*providers
|
..*providers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue