Skip to content

Commit b6ef2b1

Browse files
Remove dyn_compatible_for_dispatch
1 parent f2c4ccd commit b6ef2b1

File tree

57 files changed

+793
-724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+793
-724
lines changed

compiler/rustc_feature/src/removed.rs

+9
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ declare_features! (
100100
Some("renamed to `doc_notable_trait`")),
101101
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
102102
(removed, dropck_parametricity, "1.38.0", Some(28498), None),
103+
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible[^1].
104+
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
105+
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
106+
///
107+
/// Renamed from `object_safe_for_dispatch`.
108+
///
109+
/// [^1]: Formerly known as "object safe".
110+
(removed, dyn_compatible_for_dispatch, "1.83.0", Some(43561),
111+
Some("removed, not used heavily and represented additional complexity in dyn compatibility")),
103112
/// Uses generic effect parameters for ~const bounds
104113
(removed, effects, "1.84.0", Some(102090),
105114
Some("removed, redundant with `#![feature(const_trait_impl)]`")),

compiler/rustc_feature/src/unstable.rs

-8
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,6 @@ declare_features! (
272272
(unstable, doc_notable_trait, "1.52.0", Some(45040)),
273273
/// Allows using the `may_dangle` attribute (RFC 1327).
274274
(unstable, dropck_eyepatch, "1.10.0", Some(34761)),
275-
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible[^1].
276-
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
277-
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
278-
///
279-
/// Renamed from `object_safe_for_dispatch`.
280-
///
281-
/// [^1]: Formerly known as "object safe".
282-
(unstable, dyn_compatible_for_dispatch, "1.83.0", Some(43561)),
283275
/// Allows using the `#[fundamental]` attribute.
284276
(unstable, fundamental, "1.0.0", Some(29635)),
285277
/// Allows using `#[link_name="llvm.*"]`.

compiler/rustc_hir_analysis/src/coherence/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ fn check_object_overlap<'tcx>(
199199

200200
for component_def_id in component_def_ids {
201201
if !tcx.is_dyn_compatible(component_def_id) {
202-
// Without the 'dyn_compatible_for_dispatch' feature this is an error
203-
// which will be reported by wfcheck. Ignore it here.
204-
// This is tested by `coherence-impl-trait-for-trait-dyn-compatible.rs`.
205-
// With the feature enabled, the trait is not implemented automatically,
206-
// so this is valid.
202+
// This is a WF error tested by `coherence-impl-trait-for-trait-dyn-compatible.rs`.
207203
} else {
208204
let mut supertrait_def_ids = elaborate::supertrait_def_ids(tcx, component_def_id);
209205
if supertrait_def_ids

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,10 @@ fn object_ty_for_trait<'tcx>(
639639
/// a pointer.
640640
///
641641
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in
642-
/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch
643-
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
644-
/// Instead, we fudge a little by introducing a new type parameter `U` such that
642+
/// a new check that `Trait` is dyn-compatible, creating a cycle.
643+
/// Instead, we emulate a placeholder by introducing a new type parameter `U` such that
645644
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
645+
///
646646
/// Written as a chalk-style query:
647647
/// ```ignore (not-rust)
648648
/// forall (U: Trait + ?Sized) {
@@ -673,8 +673,6 @@ fn receiver_is_dispatchable<'tcx>(
673673

674674
// the type `U` in the query
675675
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
676-
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
677-
// replace this with `dyn Trait`
678676
let unsized_self_ty: Ty<'tcx> =
679677
Ty::new_param(tcx, u32::MAX, rustc_span::sym::RustaceansAreAwesome);
680678

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
858858
}
859859

860860
if let Some(principal) = data.principal() {
861-
if !self.infcx.tcx.features().dyn_compatible_for_dispatch() {
862-
principal.with_self_ty(self.tcx(), self_ty)
863-
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
864-
principal.with_self_ty(self.tcx(), self_ty)
865-
} else {
866-
return;
867-
}
861+
principal.with_self_ty(self.tcx(), self_ty)
868862
} else {
869863
// Only auto trait bounds exist.
870864
return;

compiler/rustc_trait_selection/src/traits/wf.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -861,19 +861,14 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
861861
// FIXME(#27579) RFC also considers adding trait
862862
// obligations that don't refer to Self and
863863
// checking those
864-
865-
let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch();
866-
867-
if !defer_to_coercion {
868-
if let Some(principal) = data.principal_def_id() {
869-
self.out.push(traits::Obligation::with_depth(
870-
tcx,
871-
self.cause(ObligationCauseCode::WellFormed(None)),
872-
self.recursion_depth,
873-
self.param_env,
874-
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
875-
));
876-
}
864+
if let Some(principal) = data.principal_def_id() {
865+
self.out.push(traits::Obligation::with_depth(
866+
tcx,
867+
self.cause(ObligationCauseCode::WellFormed(None)),
868+
self.recursion_depth,
869+
self.param_env,
870+
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
871+
));
877872
}
878873
}
879874

src/tools/tidy/src/issues.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3844,7 +3844,6 @@ ui/suggestions/issue-103646.rs
38443844
ui/suggestions/issue-104086-suggest-let.rs
38453845
ui/suggestions/issue-104287.rs
38463846
ui/suggestions/issue-104327.rs
3847-
ui/suggestions/issue-104328.rs
38483847
ui/suggestions/issue-104961.rs
38493848
ui/suggestions/issue-105226.rs
38503849
ui/suggestions/issue-105494.rs

tests/ui/coherence/coherence-unsafe-trait-object-impl.rs

-18
This file was deleted.

tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
//@ check-pass
2-
31
// Regression test for #128176. Previously we would call `type_of` on the `1` anon const
42
// before the anon const had been lowered and had the `type_of` fed with a result.
53

64
#![feature(generic_const_exprs)]
7-
#![feature(dyn_compatible_for_dispatch)]
85
#![allow(incomplete_features)]
96

107
trait X {
@@ -13,6 +10,7 @@ trait X {
1310

1411
const _: () = {
1512
fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
13+
//~^ ERROR the trait `X` is not dyn compatible
1614
};
1715

1816
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0038]: the trait `X` is not dyn compatible
2+
--> $DIR/cg-in-dyn-issue-128176.rs:12:24
3+
|
4+
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
5+
| ^^^^^^^^^^^^^^^^^^^^ `X` is not dyn compatible
6+
|
7+
note: for a trait to be dyn compatible it needs to allow building a vtable
8+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
9+
--> $DIR/cg-in-dyn-issue-128176.rs:8:10
10+
|
11+
LL | trait X {
12+
| - this trait is not dyn compatible...
13+
LL | type Y<const N: i16>;
14+
| ^ ...because it contains the generic associated type `Y`
15+
= help: consider moving `Y` to another trait
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0038`.

tests/ui/dyn-compatibility/associated-consts.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with associated consts.
3-
//
4-
//@ revisions: curr dyn_compatible_for_dispatch
5-
6-
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
73

84
trait Bar {
95
const X: usize;
106
}
117

128
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
13-
//[curr]~^ ERROR E0038
9+
//~^ ERROR E0038
1410
t
1511
//~^ ERROR E0038
1612
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0038]: the trait `Bar` is not dyn compatible
2+
--> $DIR/associated-consts.rs:8:31
3+
|
4+
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5+
| ^^^^^^^ `Bar` is not dyn compatible
6+
|
7+
note: for a trait to be dyn compatible it needs to allow building a vtable
8+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
9+
--> $DIR/associated-consts.rs:5:11
10+
|
11+
LL | trait Bar {
12+
| --- this trait is not dyn compatible...
13+
LL | const X: usize;
14+
| ^ ...because it contains this associated `const`
15+
= help: consider moving `X` to another trait
16+
17+
error[E0038]: the trait `Bar` is not dyn compatible
18+
--> $DIR/associated-consts.rs:10:5
19+
|
20+
LL | t
21+
| ^ `Bar` is not dyn compatible
22+
|
23+
note: for a trait to be dyn compatible it needs to allow building a vtable
24+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
25+
--> $DIR/associated-consts.rs:5:11
26+
|
27+
LL | trait Bar {
28+
| --- this trait is not dyn compatible...
29+
LL | const X: usize;
30+
| ^ ...because it contains this associated `const`
31+
= help: consider moving `X` to another trait
32+
= note: required for the cast from `&T` to `&dyn Bar`
33+
34+
error: aborting due to 2 previous errors
35+
36+
For more information about this error, try `rustc --explain E0038`.

tests/ui/dyn-compatibility/generics.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with generic methods, unless `where Self : Sized` is
33
// present.
4-
//@ revisions: curr dyn_compatible_for_dispatch
5-
6-
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
74

85

96
trait Bar {
@@ -16,18 +13,16 @@ trait Quux {
1613
}
1714

1815
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
19-
//[curr]~^ ERROR E0038
16+
//~^ ERROR E0038
2017
t
21-
//[dyn_compatible_for_dispatch]~^ ERROR E0038
22-
//[curr]~^^ ERROR E0038
18+
//~^ ERROR E0038
2319
}
2420

2521
fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
26-
//[curr]~^ ERROR E0038
22+
//~^ ERROR E0038
2723
t as &dyn Bar
28-
//[dyn_compatible_for_dispatch]~^ ERROR E0038
29-
//[curr]~^^ ERROR E0038
30-
//[curr]~| ERROR E0038
24+
//~^ ERROR E0038
25+
//~| ERROR E0038
3126
}
3227

3328
fn make_quux<T:Quux>(t: &T) -> &dyn Quux {
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
error[E0038]: the trait `Bar` is not dyn compatible
2+
--> $DIR/generics.rs:15:31
3+
|
4+
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5+
| ^^^^^^^ `Bar` is not dyn compatible
6+
|
7+
note: for a trait to be dyn compatible it needs to allow building a vtable
8+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
9+
--> $DIR/generics.rs:7:8
10+
|
11+
LL | trait Bar {
12+
| --- this trait is not dyn compatible...
13+
LL | fn bar<T>(&self, t: T);
14+
| ^^^ ...because method `bar` has generic type parameters
15+
= help: consider moving `bar` to another trait
16+
17+
error[E0038]: the trait `Bar` is not dyn compatible
18+
--> $DIR/generics.rs:21:40
19+
|
20+
LL | fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
21+
| ^^^^^^^ `Bar` is not dyn compatible
22+
|
23+
note: for a trait to be dyn compatible it needs to allow building a vtable
24+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
25+
--> $DIR/generics.rs:7:8
26+
|
27+
LL | trait Bar {
28+
| --- this trait is not dyn compatible...
29+
LL | fn bar<T>(&self, t: T);
30+
| ^^^ ...because method `bar` has generic type parameters
31+
= help: consider moving `bar` to another trait
32+
33+
error[E0038]: the trait `Bar` is not dyn compatible
34+
--> $DIR/generics.rs:17:5
35+
|
36+
LL | t
37+
| ^ `Bar` is not dyn compatible
38+
|
39+
note: for a trait to be dyn compatible it needs to allow building a vtable
40+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
41+
--> $DIR/generics.rs:7:8
42+
|
43+
LL | trait Bar {
44+
| --- this trait is not dyn compatible...
45+
LL | fn bar<T>(&self, t: T);
46+
| ^^^ ...because method `bar` has generic type parameters
47+
= help: consider moving `bar` to another trait
48+
= note: required for the cast from `&T` to `&dyn Bar`
49+
50+
error[E0038]: the trait `Bar` is not dyn compatible
51+
--> $DIR/generics.rs:23:10
52+
|
53+
LL | t as &dyn Bar
54+
| ^^^^^^^^ `Bar` is not dyn compatible
55+
|
56+
note: for a trait to be dyn compatible it needs to allow building a vtable
57+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
58+
--> $DIR/generics.rs:7:8
59+
|
60+
LL | trait Bar {
61+
| --- this trait is not dyn compatible...
62+
LL | fn bar<T>(&self, t: T);
63+
| ^^^ ...because method `bar` has generic type parameters
64+
= help: consider moving `bar` to another trait
65+
66+
error[E0038]: the trait `Bar` is not dyn compatible
67+
--> $DIR/generics.rs:23:5
68+
|
69+
LL | t as &dyn Bar
70+
| ^ `Bar` is not dyn compatible
71+
|
72+
note: for a trait to be dyn compatible it needs to allow building a vtable
73+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
74+
--> $DIR/generics.rs:7:8
75+
|
76+
LL | trait Bar {
77+
| --- this trait is not dyn compatible...
78+
LL | fn bar<T>(&self, t: T);
79+
| ^^^ ...because method `bar` has generic type parameters
80+
= help: consider moving `bar` to another trait
81+
= note: required for the cast from `&T` to `&dyn Bar`
82+
83+
error: aborting due to 5 previous errors
84+
85+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)