Skip to content

Commit 9e739b7

Browse files
committed
Give items related to issue 33140 a more meaningful name
1 parent 20aa2d8 commit 9e739b7

File tree

6 files changed

+48
-45
lines changed

6 files changed

+48
-45
lines changed

compiler/rustc_middle/src/query/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,10 @@ rustc_queries! {
847847
separate_provide_extern
848848
}
849849

850-
query issue33140_self_ty(key: DefId) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
851-
desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
850+
query self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
851+
key: DefId
852+
) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
853+
desc { |tcx| "computing self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
852854
}
853855

854856
/// Maps a `DefId` of a type to a list of its inherent impls.

compiler/rustc_middle/src/ty/mod.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -1503,14 +1503,14 @@ pub enum ImplOverlapKind {
15031503
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
15041504
marker: bool,
15051505
},
1506-
/// These impls are allowed to overlap, but that raises
1507-
/// an issue #33140 future-compatibility warning.
1506+
/// These impls are allowed to overlap, but that raises an
1507+
/// issue #33140 future-compatibility warning (tracked in #56484).
15081508
///
15091509
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
15101510
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
15111511
///
1512-
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
1513-
/// that difference, making what reduces to the following set of impls:
1512+
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied on
1513+
/// that difference, doing what reduces to the following set of impls:
15141514
///
15151515
/// ```compile_fail,(E0119)
15161516
/// trait Trait {}
@@ -1535,7 +1535,7 @@ pub enum ImplOverlapKind {
15351535
/// 4. Neither of the impls can have any where-clauses.
15361536
///
15371537
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
1538-
Issue33140,
1538+
FutureCompatOrderDepTraitObjects,
15391539
}
15401540

15411541
/// Useful source information about where a desugared associated type for an
@@ -1730,27 +1730,26 @@ impl<'tcx> TyCtxt<'tcx> {
17301730
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
17311731
};
17321732

1733-
let is_marker_overlap = {
1734-
let is_marker_impl =
1735-
|trait_ref: TraitRef<'_>| -> bool { self.trait_def(trait_ref.def_id).is_marker };
1736-
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2)
1737-
};
1733+
let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
1734+
let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
17381735

17391736
if is_marker_overlap {
1740-
Some(ImplOverlapKind::Permitted { marker: true })
1741-
} else {
1742-
if let Some(self_ty1) = self.issue33140_self_ty(def_id1) {
1743-
if let Some(self_ty2) = self.issue33140_self_ty(def_id2) {
1744-
if self_ty1 == self_ty2 {
1745-
return Some(ImplOverlapKind::Issue33140);
1746-
} else {
1747-
debug!("found {self_ty1:?} != {self_ty2:?}");
1748-
}
1749-
}
1750-
}
1737+
return Some(ImplOverlapKind::Permitted { marker: true });
1738+
}
17511739

1752-
None
1740+
if let Some(self_ty1) =
1741+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id1)
1742+
&& let Some(self_ty2) =
1743+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id2)
1744+
{
1745+
if self_ty1 == self_ty2 {
1746+
return Some(ImplOverlapKind::FutureCompatOrderDepTraitObjects);
1747+
} else {
1748+
debug!("found {self_ty1:?} != {self_ty2:?}");
1749+
}
17531750
}
1751+
1752+
None
17541753
}
17551754

17561755
/// Returns `ty::VariantDef` if `res` refers to a struct,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
20012001
// any associated items and there are no where-clauses.
20022002
//
20032003
// We can just arbitrarily drop one of the impls.
2004-
Some(ty::ImplOverlapKind::Issue33140) => {
2004+
Some(ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects) => {
20052005
assert_eq!(other.evaluation, victim.evaluation);
20062006
DropVictim::Yes
20072007
}

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ fn report_conflicting_impls<'tcx>(
453453
overlap.trait_ref.print_trait_sugared(),
454454
overlap.self_ty.map_or_else(String::new, |ty| format!(" for type `{ty}`")),
455455
match used_to_be_allowed {
456-
Some(FutureCompatOverlapErrorKind::Issue33140) => ": (E0119)",
456+
Some(FutureCompatOverlapErrorKind::OrderDepTraitObjects) => ": (E0119)",
457457
_ => "",
458458
}
459459
)
@@ -480,7 +480,7 @@ fn report_conflicting_impls<'tcx>(
480480
}
481481
Some(kind) => {
482482
let lint = match kind {
483-
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
483+
FutureCompatOverlapErrorKind::OrderDepTraitObjects => ORDER_DEPENDENT_TRAIT_OBJECTS,
484484
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
485485
};
486486
tcx.node_span_lint(

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use rustc_middle::traits::specialization_graph::*;
1111

1212
#[derive(Copy, Clone, Debug)]
1313
pub enum FutureCompatOverlapErrorKind {
14-
Issue33140,
14+
OrderDepTraitObjects,
1515
LeakCheck,
1616
}
1717

@@ -150,10 +150,10 @@ impl<'tcx> Children {
150150
{
151151
match overlap_kind {
152152
ty::ImplOverlapKind::Permitted { marker: _ } => {}
153-
ty::ImplOverlapKind::Issue33140 => {
153+
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
154154
*last_lint_mut = Some(FutureCompatOverlapError {
155155
error: create_overlap_error(overlap),
156-
kind: FutureCompatOverlapErrorKind::Issue33140,
156+
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
157157
});
158158
}
159159
}

compiler/rustc_ty_utils/src/ty.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -243,37 +243,39 @@ fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamE
243243
tcx.param_env(def_id).with_reveal_all_normalized(tcx)
244244
}
245245

246-
/// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`.
246+
/// If the given trait impl enables exploiting the former order dependence of trait objects,
247+
/// returns its self type; otherwise, returns `None`.
247248
///
248-
/// See [`ty::ImplOverlapKind::Issue33140`] for more details.
249-
fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'_>>> {
250-
debug!("issue33140_self_ty({:?})", def_id);
251-
252-
let impl_ = tcx
253-
.impl_trait_header(def_id)
254-
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
249+
/// See [`ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects`] for more details.
250+
#[instrument(level = "debug", skip(tcx))]
251+
fn self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
252+
tcx: TyCtxt<'_>,
253+
def_id: DefId,
254+
) -> Option<EarlyBinder<Ty<'_>>> {
255+
let impl_ =
256+
tcx.impl_trait_header(def_id).unwrap_or_else(|| bug!("called on inherent impl {def_id:?}"));
255257

256258
let trait_ref = impl_.trait_ref.skip_binder();
257-
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);
259+
debug!(?trait_ref);
258260

259261
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive
260262
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
261263

262264
// Check whether these impls would be ok for a marker trait.
263265
if !is_marker_like {
264-
debug!("issue33140_self_ty - not marker-like!");
266+
debug!("not marker-like!");
265267
return None;
266268
}
267269

268270
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
269271
if trait_ref.args.len() != 1 {
270-
debug!("issue33140_self_ty - impl has args!");
272+
debug!("impl has args!");
271273
return None;
272274
}
273275

274276
let predicates = tcx.predicates_of(def_id);
275277
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
276-
debug!("issue33140_self_ty - impl has predicates {:?}!", predicates);
278+
debug!(?predicates, "impl has predicates!");
277279
return None;
278280
}
279281

@@ -284,10 +286,10 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
284286
};
285287

286288
if self_ty_matches {
287-
debug!("issue33140_self_ty - MATCHES!");
289+
debug!("MATCHES!");
288290
Some(EarlyBinder::bind(self_ty))
289291
} else {
290-
debug!("issue33140_self_ty - non-matching self type");
292+
debug!("non-matching self type");
291293
None
292294
}
293295
}
@@ -351,7 +353,7 @@ pub(crate) fn provide(providers: &mut Providers) {
351353
adt_sized_constraint,
352354
param_env,
353355
param_env_reveal_all_normalized,
354-
issue33140_self_ty,
356+
self_ty_of_trait_impl_enabling_order_dep_trait_object_hack,
355357
defaultness,
356358
unsizing_params_for_adt,
357359
..*providers

0 commit comments

Comments
 (0)