Skip to content

Commit 5a46f82

Browse files
authored
Rollup merge of #136968 - oli-obk:bye-bye, r=compiler-errors
Turn order dependent trait objects future incompat warning into a hard error fixes #56484 r? ``@ghost`` will FCP when we have a crater result
2 parents 84c2050 + 8f6b184 commit 5a46f82

File tree

13 files changed

+38
-330
lines changed

13 files changed

+38
-330
lines changed

Diff for: compiler/rustc_lint_defs/src/builtin.rs

-37
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ declare_lint_pass! {
7373
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
7474
NON_CONTIGUOUS_RANGE_ENDPOINTS,
7575
NON_EXHAUSTIVE_OMITTED_PATTERNS,
76-
ORDER_DEPENDENT_TRAIT_OBJECTS,
7776
OUT_OF_SCOPE_MACRO_CALLS,
7877
OVERLAPPING_RANGE_ENDPOINTS,
7978
PATTERNS_IN_FNS_WITHOUT_BODY,
@@ -1501,42 +1500,6 @@ declare_lint! {
15011500
};
15021501
}
15031502

1504-
declare_lint! {
1505-
/// The `order_dependent_trait_objects` lint detects a trait coherency
1506-
/// violation that would allow creating two trait impls for the same
1507-
/// dynamic trait object involving marker traits.
1508-
///
1509-
/// ### Example
1510-
///
1511-
/// ```rust,compile_fail
1512-
/// pub trait Trait {}
1513-
///
1514-
/// impl Trait for dyn Send + Sync { }
1515-
/// impl Trait for dyn Sync + Send { }
1516-
/// ```
1517-
///
1518-
/// {{produces}}
1519-
///
1520-
/// ### Explanation
1521-
///
1522-
/// A previous bug caused the compiler to interpret traits with different
1523-
/// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1524-
/// when they were intended to be treated the same. This allowed code to
1525-
/// define separate trait implementations when there should be a coherence
1526-
/// error. This is a [future-incompatible] lint to transition this to a
1527-
/// hard error in the future. See [issue #56484] for more details.
1528-
///
1529-
/// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1530-
/// [future-incompatible]: ../index.md#future-incompatible-lints
1531-
pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1532-
Deny,
1533-
"trait-object types were treated as different depending on marker-trait order",
1534-
@future_incompatible = FutureIncompatibleInfo {
1535-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
1536-
reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1537-
};
1538-
}
1539-
15401503
declare_lint! {
15411504
/// The `coherence_leak_check` lint detects conflicting implementations of
15421505
/// a trait that are only distinguished by the old leak-check code.

Diff for: compiler/rustc_middle/src/query/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,6 @@ rustc_queries! {
999999
separate_provide_extern
10001000
}
10011001

1002-
query self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
1003-
key: DefId
1004-
) -> Option<ty::EarlyBinder<'tcx, ty::Ty<'tcx>>> {
1005-
desc { |tcx| "computing self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
1006-
}
1007-
10081002
/// Maps a `DefId` of a type to a list of its inherent impls.
10091003
/// Contains implementations of methods that are inherent to a type.
10101004
/// Methods in these implementations don't need to be exported.

Diff for: compiler/rustc_middle/src/ty/mod.rs

+1-46
Original file line numberDiff line numberDiff line change
@@ -1414,39 +1414,6 @@ pub enum ImplOverlapKind {
14141414
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
14151415
marker: bool,
14161416
},
1417-
/// These impls are allowed to overlap, but that raises an
1418-
/// issue #33140 future-compatibility warning (tracked in #56484).
1419-
///
1420-
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
1421-
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
1422-
///
1423-
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied on
1424-
/// that difference, doing what reduces to the following set of impls:
1425-
///
1426-
/// ```compile_fail,(E0119)
1427-
/// trait Trait {}
1428-
/// impl Trait for dyn Send + Sync {}
1429-
/// impl Trait for dyn Sync + Send {}
1430-
/// ```
1431-
///
1432-
/// Obviously, once we made these types be identical, that code causes a coherence
1433-
/// error and a fairly big headache for us. However, luckily for us, the trait
1434-
/// `Trait` used in this case is basically a marker trait, and therefore having
1435-
/// overlapping impls for it is sound.
1436-
///
1437-
/// To handle this, we basically regard the trait as a marker trait, with an additional
1438-
/// future-compatibility warning. To avoid accidentally "stabilizing" this feature,
1439-
/// it has the following restrictions:
1440-
///
1441-
/// 1. The trait must indeed be a marker-like trait (i.e., no items), and must be
1442-
/// positive impls.
1443-
/// 2. The trait-ref of both impls must be equal.
1444-
/// 3. The trait-ref of both impls must be a trait object type consisting only of
1445-
/// marker traits.
1446-
/// 4. Neither of the impls can have any where-clauses.
1447-
///
1448-
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
1449-
FutureCompatOrderDepTraitObjects,
14501417
}
14511418

14521419
/// Useful source information about where a desugared associated type for an
@@ -1624,7 +1591,7 @@ impl<'tcx> TyCtxt<'tcx> {
16241591
})
16251592
}
16261593

1627-
/// Returns `true` if the impls are the same polarity and the trait either
1594+
/// Returns `Some` if the impls are the same polarity and the trait either
16281595
/// has no items or is annotated `#[marker]` and prevents item overrides.
16291596
#[instrument(level = "debug", skip(self), ret)]
16301597
pub fn impls_are_allowed_to_overlap(
@@ -1665,18 +1632,6 @@ impl<'tcx> TyCtxt<'tcx> {
16651632
return Some(ImplOverlapKind::Permitted { marker: true });
16661633
}
16671634

1668-
if let Some(self_ty1) =
1669-
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id1)
1670-
&& let Some(self_ty2) =
1671-
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id2)
1672-
{
1673-
if self_ty1 == self_ty2 {
1674-
return Some(ImplOverlapKind::FutureCompatOrderDepTraitObjects);
1675-
} else {
1676-
debug!("found {self_ty1:?} != {self_ty2:?}");
1677-
}
1678-
}
1679-
16801635
None
16811636
}
16821637

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -1925,9 +1925,9 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19251925
let mut impl_candidate = None;
19261926
for c in impls {
19271927
if let Some(prev) = impl_candidate.replace(c) {
1928-
if self.prefer_lhs_over_victim(has_non_region_infer, c, prev) {
1928+
if self.prefer_lhs_over_victim(has_non_region_infer, c, prev.0) {
19291929
// Ok, prefer `c` over the previous entry
1930-
} else if self.prefer_lhs_over_victim(has_non_region_infer, prev, c) {
1930+
} else if self.prefer_lhs_over_victim(has_non_region_infer, prev, c.0) {
19311931
// Ok, keep `prev` instead of the new entry
19321932
impl_candidate = Some(prev);
19331933
} else {
@@ -1986,7 +1986,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19861986
&self,
19871987
has_non_region_infer: bool,
19881988
(lhs, lhs_evaluation): (DefId, EvaluationResult),
1989-
(victim, victim_evaluation): (DefId, EvaluationResult),
1989+
victim: DefId,
19901990
) -> bool {
19911991
let tcx = self.tcx();
19921992
// See if we can toss out `victim` based on specialization.
@@ -2002,14 +2002,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
20022002
}
20032003

20042004
match tcx.impls_are_allowed_to_overlap(lhs, victim) {
2005-
// For #33140 the impl headers must be exactly equal, the trait must not have
2006-
// any associated items and there are no where-clauses.
2007-
//
2008-
// We can just arbitrarily drop one of the impls.
2009-
Some(ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects) => {
2010-
assert_eq!(lhs_evaluation, victim_evaluation);
2011-
true
2012-
}
20132005
// For candidates which already reference errors it doesn't really
20142006
// matter what we do 🤷
20152007
Some(ty::ImplOverlapKind::Permitted { marker: false }) => {

Diff for: compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::bug;
2020
use rustc_middle::query::LocalCrate;
2121
use rustc_middle::ty::print::PrintTraitRefExt as _;
2222
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode};
23-
use rustc_session::lint::builtin::{COHERENCE_LEAK_CHECK, ORDER_DEPENDENT_TRAIT_OBJECTS};
23+
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
2424
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, sym};
2525
use rustc_type_ir::solve::NoSolution;
2626
use specialization_graph::GraphExt;
@@ -557,13 +557,9 @@ fn report_conflicting_impls<'tcx>(
557557

558558
let msg = || {
559559
format!(
560-
"conflicting implementations of trait `{}`{}{}",
560+
"conflicting implementations of trait `{}`{}",
561561
overlap.trait_ref.print_trait_sugared(),
562562
overlap.self_ty.map_or_else(String::new, |ty| format!(" for type `{ty}`")),
563-
match used_to_be_allowed {
564-
Some(FutureCompatOverlapErrorKind::OrderDepTraitObjects) => ": (E0119)",
565-
_ => "",
566-
}
567563
)
568564
};
569565

@@ -588,7 +584,6 @@ fn report_conflicting_impls<'tcx>(
588584
}
589585
Some(kind) => {
590586
let lint = match kind {
591-
FutureCompatOverlapErrorKind::OrderDepTraitObjects => ORDER_DEPENDENT_TRAIT_OBJECTS,
592587
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
593588
};
594589
tcx.node_span_lint(lint, tcx.local_def_id_to_hir_id(impl_def_id), impl_span, |err| {

Diff for: compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::traits;
1212

1313
#[derive(Copy, Clone, Debug)]
1414
pub enum FutureCompatOverlapErrorKind {
15-
OrderDepTraitObjects,
1615
LeakCheck,
1716
}
1817

@@ -151,12 +150,6 @@ impl<'tcx> Children {
151150
{
152151
match overlap_kind {
153152
ty::ImplOverlapKind::Permitted { marker: _ } => {}
154-
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
155-
*last_lint_mut = Some(FutureCompatOverlapError {
156-
error: create_overlap_error(overlap),
157-
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
158-
});
159-
}
160153
}
161154

162155
return Ok((false, false));

Diff for: compiler/rustc_ty_utils/src/ty.rs

+2-56
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ use rustc_index::bit_set::DenseBitSet;
66
use rustc_middle::bug;
77
use rustc_middle::query::Providers;
88
use rustc_middle::ty::fold::fold_regions;
9-
use rustc_middle::ty::{
10-
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast,
11-
};
9+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast};
1210
use rustc_span::DUMMY_SP;
1311
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
1412
use rustc_trait_selection::traits;
15-
use tracing::{debug, instrument};
13+
use tracing::instrument;
1614

1715
#[instrument(level = "debug", skip(tcx), ret)]
1816
fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
@@ -260,57 +258,6 @@ fn param_env_normalized_for_post_analysis(tcx: TyCtxt<'_>, def_id: DefId) -> ty:
260258
typing_env.with_post_analysis_normalized(tcx).param_env
261259
}
262260

263-
/// If the given trait impl enables exploiting the former order dependence of trait objects,
264-
/// returns its self type; otherwise, returns `None`.
265-
///
266-
/// See [`ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects`] for more details.
267-
#[instrument(level = "debug", skip(tcx))]
268-
fn self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
269-
tcx: TyCtxt<'_>,
270-
def_id: DefId,
271-
) -> Option<EarlyBinder<'_, Ty<'_>>> {
272-
let impl_ =
273-
tcx.impl_trait_header(def_id).unwrap_or_else(|| bug!("called on inherent impl {def_id:?}"));
274-
275-
let trait_ref = impl_.trait_ref.skip_binder();
276-
debug!(?trait_ref);
277-
278-
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive
279-
&& tcx.associated_item_def_ids(trait_ref.def_id).is_empty();
280-
281-
// Check whether these impls would be ok for a marker trait.
282-
if !is_marker_like {
283-
debug!("not marker-like!");
284-
return None;
285-
}
286-
287-
// impl must be `impl Trait for dyn Marker1 + Marker2 + ...`
288-
if trait_ref.args.len() != 1 {
289-
debug!("impl has args!");
290-
return None;
291-
}
292-
293-
let predicates = tcx.predicates_of(def_id);
294-
if predicates.parent.is_some() || !predicates.predicates.is_empty() {
295-
debug!(?predicates, "impl has predicates!");
296-
return None;
297-
}
298-
299-
let self_ty = trait_ref.self_ty();
300-
let self_ty_matches = match self_ty.kind() {
301-
ty::Dynamic(data, re, _) if re.is_static() => data.principal().is_none(),
302-
_ => false,
303-
};
304-
305-
if self_ty_matches {
306-
debug!("MATCHES!");
307-
Some(EarlyBinder::bind(self_ty))
308-
} else {
309-
debug!("non-matching self type");
310-
None
311-
}
312-
}
313-
314261
/// Check if a function is async.
315262
fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Asyncness {
316263
let node = tcx.hir_node_by_def_id(def_id);
@@ -370,7 +317,6 @@ pub(crate) fn provide(providers: &mut Providers) {
370317
adt_sized_constraint,
371318
param_env,
372319
param_env_normalized_for_post_analysis,
373-
self_ty_of_trait_impl_enabling_order_dep_trait_object_hack,
374320
defaultness,
375321
unsizing_params_for_adt,
376322
..*providers

Diff for: tests/ui/lint/lint-incoherent-auto-trait-objects.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ impl Foo for dyn Send {}
44

55
impl Foo for dyn Send + Send {}
66
//~^ ERROR conflicting implementations
7-
//~| hard error
87

98
impl Foo for dyn Send + Sync {}
109

1110
impl Foo for dyn Sync + Send {}
1211
//~^ ERROR conflicting implementations
13-
//~| hard error
1412

1513
impl Foo for dyn Send + Sync + Send {}
1614
//~^ ERROR conflicting implementations
17-
//~| hard error
1815

1916
fn main() {}

0 commit comments

Comments
 (0)