Skip to content

Commit 7486176

Browse files
committed
Give items related to issue 33140 a more meaningful name
1 parent fee0e66 commit 7486176

File tree

6 files changed

+49
-44
lines changed

6 files changed

+49
-44
lines changed

compiler/rustc_middle/src/query/mod.rs

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

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

853855
/// 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
@@ -1494,14 +1494,14 @@ pub enum ImplOverlapKind {
14941494
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
14951495
marker: bool,
14961496
},
1497-
/// These impls are allowed to overlap, but that raises
1498-
/// an issue #33140 future-compatibility warning.
1497+
/// These impls are allowed to overlap, but that raises an
1498+
/// issue #33140 future-compatibility warning (tracked in #56484).
14991499
///
15001500
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
15011501
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
15021502
///
1503-
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
1504-
/// that difference, making what reduces to the following set of impls:
1503+
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied on
1504+
/// that difference, doing what reduces to the following set of impls:
15051505
///
15061506
/// ```compile_fail,(E0119)
15071507
/// trait Trait {}
@@ -1526,7 +1526,7 @@ pub enum ImplOverlapKind {
15261526
/// 4. Neither of the impls can have any where-clauses.
15271527
///
15281528
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
1529-
Issue33140,
1529+
FutureCompatOrderDepTraitObjects,
15301530
}
15311531

15321532
/// Useful source information about where a desugared associated type for an
@@ -1721,27 +1721,26 @@ impl<'tcx> TyCtxt<'tcx> {
17211721
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
17221722
};
17231723

1724-
let is_marker_overlap = {
1725-
let is_marker_impl =
1726-
|trait_ref: TraitRef<'_>| -> bool { self.trait_def(trait_ref.def_id).is_marker };
1727-
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2)
1728-
};
1724+
let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
1725+
let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
17291726

17301727
if is_marker_overlap {
1731-
Some(ImplOverlapKind::Permitted { marker: true })
1732-
} else {
1733-
if let Some(self_ty1) = self.issue33140_self_ty(def_id1) {
1734-
if let Some(self_ty2) = self.issue33140_self_ty(def_id2) {
1735-
if self_ty1 == self_ty2 {
1736-
return Some(ImplOverlapKind::Issue33140);
1737-
} else {
1738-
debug!("found {self_ty1:?} != {self_ty2:?}");
1739-
}
1740-
}
1741-
}
1728+
return Some(ImplOverlapKind::Permitted { marker: true });
1729+
}
17421730

1743-
None
1731+
if let Some(self_ty1) =
1732+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_exploit(def_id1)
1733+
&& let Some(self_ty2) =
1734+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_exploit(def_id2)
1735+
{
1736+
if self_ty1 == self_ty2 {
1737+
return Some(ImplOverlapKind::FutureCompatOrderDepTraitObjects);
1738+
} else {
1739+
debug!("found {self_ty1:?} != {self_ty2:?}");
1740+
}
17441741
}
1742+
1743+
None
17451744
}
17461745

17471746
/// 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
@@ -10,7 +10,7 @@ pub use rustc_middle::traits::specialization_graph::*;
1010

1111
#[derive(Copy, Clone, Debug)]
1212
pub enum FutureCompatOverlapErrorKind {
13-
Issue33140,
13+
OrderDepTraitObjects,
1414
LeakCheck,
1515
}
1616

@@ -149,10 +149,10 @@ impl<'tcx> Children {
149149
{
150150
match overlap_kind {
151151
ty::ImplOverlapKind::Permitted { marker: _ } => {}
152-
ty::ImplOverlapKind::Issue33140 => {
152+
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
153153
*last_lint_mut = Some(FutureCompatOverlapError {
154154
error: create_overlap_error(overlap),
155-
kind: FutureCompatOverlapErrorKind::Issue33140,
155+
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
156156
});
157157
}
158158
}

compiler/rustc_ty_utils/src/ty.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -243,37 +243,41 @@ 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);
249+
/// See [`ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects`] for more details.
250+
#[instrument(level = "debug", skip_all)]
251+
fn self_ty_of_trait_impl_enabling_order_dep_trait_object_exploit(
252+
tcx: TyCtxt<'_>,
253+
def_id: DefId,
254+
) -> Option<EarlyBinder<Ty<'_>>> {
255+
debug!(?def_id);
251256

252-
let impl_ = tcx
253-
.impl_trait_header(def_id)
254-
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
257+
let impl_ =
258+
tcx.impl_trait_header(def_id).unwrap_or_else(|| bug!("called on inherent impl {def_id:?}"));
255259

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

259263
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive
260264
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
261265

262266
// Check whether these impls would be ok for a marker trait.
263267
if !is_marker_like {
264-
debug!("issue33140_self_ty - not marker-like!");
268+
debug!("not marker-like!");
265269
return None;
266270
}
267271

268272
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
269273
if trait_ref.args.len() != 1 {
270-
debug!("issue33140_self_ty - impl has args!");
274+
debug!("impl has args!");
271275
return None;
272276
}
273277

274278
let predicates = tcx.predicates_of(def_id);
275279
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
276-
debug!("issue33140_self_ty - impl has predicates {:?}!", predicates);
280+
debug!(?predicates, "impl has predicates!");
277281
return None;
278282
}
279283

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

286290
if self_ty_matches {
287-
debug!("issue33140_self_ty - MATCHES!");
291+
debug!("MATCHES!");
288292
Some(EarlyBinder::bind(self_ty))
289293
} else {
290-
debug!("issue33140_self_ty - non-matching self type");
294+
debug!("non-matching self type");
291295
None
292296
}
293297
}
@@ -351,7 +355,7 @@ pub(crate) fn provide(providers: &mut Providers) {
351355
adt_sized_constraint,
352356
param_env,
353357
param_env_reveal_all_normalized,
354-
issue33140_self_ty,
358+
self_ty_of_trait_impl_enabling_order_dep_trait_object_exploit,
355359
defaultness,
356360
unsizing_params_for_adt,
357361
..*providers

0 commit comments

Comments
 (0)