Skip to content

Commit 2e7a52b

Browse files
committed
Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatch
1 parent 62b24ea commit 2e7a52b

File tree

42 files changed

+130
-124
lines changed

Some content is hidden

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

42 files changed

+130
-124
lines changed

compiler/rustc_feature/src/removed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ declare_features! (
154154
/// then removed. But there was no utility storing it separately, so now
155155
/// it's in this list.
156156
(removed, no_stack_check, "1.0.0", None, None),
157+
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible (object safe).
158+
/// Renamed to `dyn_compatible_for_dispatch`.
159+
(removed, object_safe_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561),
160+
Some("renamed to `dyn_compatible_for_dispatch`")),
157161
/// Allows using `#[on_unimplemented(..)]` on traits.
158162
/// (Moved to `rustc_attrs`.)
159163
(removed, on_unimplemented, "1.40.0", None, None),

compiler/rustc_feature/src/unstable.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ declare_features! (
259259
(unstable, doc_notable_trait, "1.52.0", Some(45040)),
260260
/// Allows using the `may_dangle` attribute (RFC 1327).
261261
(unstable, dropck_eyepatch, "1.10.0", Some(34761)),
262+
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
263+
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
264+
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
265+
///
266+
/// Renamed from `object_safe_for_dispatch`.
267+
///
268+
/// [^1]: Formerly known as "object safe".
269+
(unstable, dyn_compatible_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561)),
262270
/// Allows using the `#[fundamental]` attribute.
263271
(unstable, fundamental, "1.0.0", Some(29635)),
264272
/// Allows using `#[link_name="llvm.*"]`.
@@ -544,13 +552,6 @@ declare_features! (
544552
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
545553
/// Allows `for<T>` binders in where-clauses
546554
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
547-
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
548-
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
549-
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
550-
///
551-
/// [^1]: Formerly known as "object safe".
552-
// FIXME(dyn_compat_renaming): Rename feature.
553-
(unstable, object_safe_for_dispatch, "1.40.0", Some(43561)),
554555
/// Allows using enums in offset_of!
555556
(unstable, offset_of_enum, "1.75.0", Some(120141)),
556557
/// Allows using fields with slice type in offset_of!

compiler/rustc_hir_analysis/src/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_object_overlap<'tcx>(
199199
for component_def_id in component_def_ids {
200200
if !tcx.is_dyn_compatible(component_def_id) {
201201
// FIXME(dyn_compat_renaming): Rename test and update comment.
202-
// Without the 'object_safe_for_dispatch' feature this is an error
202+
// Without the 'dyn_compatible_for_dispatch' feature this is an error
203203
// which will be reported by wfcheck. Ignore it here.
204204
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.
205205
// With the feature enabled, the trait is not implemented automatically,

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ symbols! {
776776
dropck_eyepatch,
777777
dropck_parametricity,
778778
dylib,
779+
dyn_compatible_for_dispatch,
779780
dyn_metadata,
780781
dyn_star,
781782
dyn_trait,

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ fn object_ty_for_trait<'tcx>(
639639
/// contained by the trait object, because the object that needs to be coerced is behind
640640
/// a pointer.
641641
///
642-
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
643-
/// in a new check that `Trait` is dyn-compatible, creating a cycle (until object_safe_for_dispatch
642+
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in
643+
/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch
644644
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
645645
/// Instead, we fudge a little by introducing a new type parameter `U` such that
646646
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
@@ -674,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>(
674674

675675
// the type `U` in the query
676676
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
677-
// FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
677+
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
678678
// replace this with `dyn Trait`
679679
let unsized_self_ty: Ty<'tcx> =
680680
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
881881
}
882882

883883
if let Some(principal) = data.principal() {
884-
if !self.infcx.tcx.features().object_safe_for_dispatch {
884+
if !self.infcx.tcx.features().dyn_compatible_for_dispatch {
885885
principal.with_self_ty(self.tcx(), self_ty)
886886
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
887887
principal.with_self_ty(self.tcx(), self_ty)

compiler/rustc_trait_selection/src/traits/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
829829
// obligations that don't refer to Self and
830830
// checking those
831831

832-
let defer_to_coercion = tcx.features().object_safe_for_dispatch;
832+
let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch;
833833

834834
if !defer_to_coercion {
835835
if let Some(principal) = data.principal_def_id() {

tests/crashes/120241-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ known-bug: #120241
22
//@ edition:2021
3-
#![feature(object_safe_for_dispatch)]
3+
#![feature(dyn_compatible_for_dispatch)]
44
#![feature(unsized_fn_params)]
55

66
fn guard(_s: Copy) -> bool {

tests/crashes/120241.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ known-bug: #120241
22
//@ edition:2021
3-
#![feature(object_safe_for_dispatch)]
3+
#![feature(dyn_compatible_for_dispatch)]
44

55
trait B {
66
fn f(a: A) -> A;

tests/crashes/120482.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ known-bug: #120482
22
//@ edition:2021
3-
#![feature(object_safe_for_dispatch)]
3+
#![feature(dyn_compatible_for_dispatch)]
44

55
trait B {
66
fn bar(&self, x: &Self);

tests/crashes/125512.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ known-bug: rust-lang/rust#125512
22
//@ edition:2021
3-
#![feature(object_safe_for_dispatch)]
3+
#![feature(dyn_compatible_for_dispatch)]
44
trait B {
55
fn f(a: A) -> A;
66
}

tests/crashes/128176.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ known-bug: rust-lang/rust#128176
22

33
#![feature(generic_const_exprs)]
4-
#![feature(object_safe_for_dispatch)]
4+
#![feature(dyn_compatible_for_dispatch)]
55
trait X {
66
type Y<const N: i16>;
77
}

tests/crashes/130521.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ known-bug: #130521
22

3-
#![feature(object_safe_for_dispatch)]
3+
#![feature(dyn_compatible_for_dispatch)]
44
struct Vtable(dyn Cap);
55

66
trait Cap<'a> {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Check that unsafe trait object do not implement themselves
22
// automatically
33

4-
#![feature(object_safe_for_dispatch)]
4+
#![feature(dyn_compatible_for_dispatch)]
55

66
trait Trait: Sized {
77
fn call(&self);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Test that the use of the dyn-incompatible trait objects
2+
// are gated by the `dyn_compatible_for_dispatch` feature gate.
3+
4+
trait DynIncompatible1: Sized {}
5+
6+
trait DynIncompatible2 {
7+
fn static_fn() {}
8+
}
9+
10+
trait DynIncompatible3 {
11+
fn foo<T>(&self);
12+
}
13+
14+
trait DynIncompatible4 {
15+
fn foo(&self, s: &Self);
16+
}
17+
18+
fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
19+
//~^ ERROR E0038
20+
}
21+
22+
fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
23+
//~^ ERROR E0038
24+
loop {}
25+
}
26+
27+
fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
28+
//~^ ERROR E0038
29+
}
30+
31+
fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
32+
//~^ ERROR E0038
33+
loop {}
34+
}
35+
36+
trait Trait {}
37+
38+
impl Trait for dyn DynIncompatible1 {}
39+
//~^ ERROR E0038
40+
41+
fn main() {}

tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr renamed to tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
2-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:39
1+
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
2+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:39
33
|
4-
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
5-
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
4+
LL | fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
5+
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object
66
|
77
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
8+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
99
|
10-
LL | trait NonObjectSafe1: Sized {}
11-
| -------------- ^^^^^ ...because it requires `Self: Sized`
10+
LL | trait DynIncompatible1: Sized {}
11+
| ---------------- ^^^^^ ...because it requires `Self: Sized`
1212
| |
1313
| this trait cannot be made into an object...
1414

15-
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
16-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45
15+
error[E0038]: the trait `DynIncompatible2` cannot be made into an object
16+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:45
1717
|
18-
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
19-
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
18+
LL | fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
19+
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object
2020
|
2121
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
22-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
22+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:7:8
2323
|
24-
LL | trait NonObjectSafe2 {
25-
| -------------- this trait cannot be made into an object...
24+
LL | trait DynIncompatible2 {
25+
| ---------------- this trait cannot be made into an object...
2626
LL | fn static_fn() {}
2727
| ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter
2828
help: consider turning `static_fn` into a method by giving it a `&self` argument
@@ -34,47 +34,47 @@ help: alternatively, consider constraining `static_fn` so it does not apply to t
3434
LL | fn static_fn() where Self: Sized {}
3535
| +++++++++++++++++
3636

37-
error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
38-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:39
37+
error[E0038]: the trait `DynIncompatible3` cannot be made into an object
38+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:39
3939
|
40-
LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
41-
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe3` cannot be made into an object
40+
LL | fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
41+
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object
4242
|
4343
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
44-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:11:8
44+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8
4545
|
46-
LL | trait NonObjectSafe3 {
47-
| -------------- this trait cannot be made into an object...
46+
LL | trait DynIncompatible3 {
47+
| ---------------- this trait cannot be made into an object...
4848
LL | fn foo<T>(&self);
4949
| ^^^ ...because method `foo` has generic type parameters
5050
= help: consider moving `foo` to another trait
5151

52-
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
53-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47
52+
error[E0038]: the trait `DynIncompatible4` cannot be made into an object
53+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:47
5454
|
55-
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
56-
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
55+
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
56+
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object
5757
|
5858
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
59-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
59+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:15:22
6060
|
61-
LL | trait NonObjectSafe4 {
62-
| -------------- this trait cannot be made into an object...
61+
LL | trait DynIncompatible4 {
62+
| ---------------- this trait cannot be made into an object...
6363
LL | fn foo(&self, s: &Self);
6464
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
6565
= help: consider moving `foo` to another trait
6666

67-
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
68-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16
67+
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
68+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:38:16
6969
|
70-
LL | impl Trait for dyn NonObjectSafe1 {}
71-
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
70+
LL | impl Trait for dyn DynIncompatible1 {}
71+
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object
7272
|
7373
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
74-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
74+
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
7575
|
76-
LL | trait NonObjectSafe1: Sized {}
77-
| -------------- ^^^^^ ...because it requires `Self: Sized`
76+
LL | trait DynIncompatible1: Sized {}
77+
| ---------------- ^^^^^ ...because it requires `Self: Sized`
7878
| |
7979
| this trait cannot be made into an object...
8080

tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs

-41
This file was deleted.

tests/ui/kindck/kindck-inherited-copy-bound.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Test that Copy bounds inherited by trait are checked.
22
//
3-
//@ revisions: curr object_safe_for_dispatch
3+
//@ revisions: curr dyn_compatible_for_dispatch
44

5-
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
5+
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
66

77

88
use std::any::Any;
@@ -19,7 +19,7 @@ fn take_param<T:Foo>(foo: &T) { }
1919
fn a() {
2020
let x: Box<_> = Box::new(3);
2121
take_param(&x); //[curr]~ ERROR E0277
22-
//[object_safe_for_dispatch]~^ ERROR E0277
22+
//[dyn_compatible_for_dispatch]~^ ERROR E0277
2323
}
2424

2525
fn b() {
@@ -28,7 +28,7 @@ fn b() {
2828
let z = &x as &dyn Foo;
2929
//[curr]~^ ERROR E0038
3030
//[curr]~| ERROR E0038
31-
//[object_safe_for_dispatch]~^^^ ERROR E0038
31+
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
3232
}
3333

3434
fn main() { }

tests/ui/object-safety/object-safety-associated-consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Check that we correctly prevent users from making trait objects
22
// from traits with associated consts.
33
//
4-
//@ revisions: curr object_safe_for_dispatch
4+
//@ revisions: curr dyn_compatible_for_dispatch
55

6-
#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
6+
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
77

88
trait Bar {
99
const X: usize;

0 commit comments

Comments
 (0)