Skip to content

Commit 788e88a

Browse files
authored
Unrolled build for rust-lang#131475
Rollup merge of rust-lang#131475 - fmease:compiler-mv-obj-safe-dyn-compat-2, r=jieyouxu Compiler & its UI tests: Rename remaining occurrences of "object safe" to "dyn compatible" Follow-up to rust-lang#130826. Part of rust-lang#130852. 1. 1st commit: Fix stupid oversights. Should've been part of rust-lang#130826. 2. 2nd commit: Rename the unstable feature `object_safe_for_dispatch` to `dyn_compatible_for_dispatch`. Might not be worth the churn, you decide. 3. 3rd commit: Apply the renaming to all UI tests (contents and paths).
2 parents d0141af + 20cebae commit 788e88a

File tree

179 files changed

+535
-531
lines changed

Some content is hidden

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

179 files changed

+535
-531
lines changed

Diff for: 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),

Diff for: 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.*"]`.
@@ -546,13 +554,6 @@ declare_features! (
546554
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
547555
/// Allows `for<T>` binders in where-clauses
548556
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
549-
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
550-
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
551-
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
552-
///
553-
/// [^1]: Formerly known as "object safe".
554-
// FIXME(dyn_compat_renaming): Rename feature.
555-
(unstable, object_safe_for_dispatch, "1.40.0", Some(43561)),
556557
/// Allows using enums in offset_of!
557558
(unstable, offset_of_enum, "1.75.0", Some(120141)),
558559
/// Allows using fields with slice type in offset_of!

Diff for: 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,

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ symbols! {
777777
dropck_eyepatch,
778778
dropck_parametricity,
779779
dylib,
780+
dyn_compatible_for_dispatch,
780781
dyn_metadata,
781782
dyn_star,
782783
dyn_trait,

Diff for: compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
//! "Object safety" refers to the ability for a trait to be converted
2-
//! to an object. In general, traits may only be converted to an
3-
//! object if all of their methods meet certain criteria. In particular,
4-
//! they must:
1+
//! "Dyn-compatibility"[^1] refers to the ability for a trait to be converted
2+
//! to a trait object. In general, traits may only be converted to a trait
3+
//! object if certain criteria are met.
54
//!
6-
//! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version
7-
//! that doesn't contain the vtable;
8-
//! - not reference the erased type `Self` except for in this receiver;
9-
//! - not have generic type parameters.
5+
//! [^1]: Formerly known as "object safety".
106
117
use std::iter;
128
use std::ops::ControlFlow;
@@ -506,8 +502,8 @@ fn virtual_call_violations_for_method<'tcx>(
506502

507503
/// This code checks that `receiver_is_dispatchable` is correctly implemented.
508504
///
509-
/// This check is outlined from the object safety check to avoid cycles with
510-
/// layout computation, which relies on knowing whether methods are object safe.
505+
/// This check is outlined from the dyn-compatibility check to avoid cycles with
506+
/// layout computation, which relies on knowing whether methods are dyn-compatible.
511507
fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) {
512508
if !is_vtable_safe_method(tcx, trait_def_id, method) {
513509
return;
@@ -643,8 +639,8 @@ fn object_ty_for_trait<'tcx>(
643639
/// contained by the trait object, because the object that needs to be coerced is behind
644640
/// a pointer.
645641
///
646-
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
647-
/// in a new check that `Trait` is object safe, 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
648644
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
649645
/// Instead, we fudge a little by introducing a new type parameter `U` such that
650646
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
@@ -678,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>(
678674

679675
// the type `U` in the query
680676
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
681-
// 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
682678
// replace this with `dyn Trait`
683679
let unsized_self_ty: Ty<'tcx> =
684680
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
@@ -865,7 +861,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
865861
}
866862

867863
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
868-
// Constants can only influence object safety if they are generic and reference `Self`.
864+
// Constants can only influence dyn-compatibility if they are generic and reference `Self`.
869865
// This is only possible for unevaluated constants, so we walk these here.
870866
self.tcx.expand_abstract_consts(ct).super_visit_with(self)
871867
}

Diff for: 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)

Diff for: 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() {

Diff for: src/tools/tidy/src/issues.txt

-4
Original file line numberDiff line numberDiff line change
@@ -3172,10 +3172,6 @@ ui/nll/user-annotations/issue-55241.rs
31723172
ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs
31733173
ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs
31743174
ui/numbers-arithmetic/issue-8460.rs
3175-
ui/object-safety/issue-102762.rs
3176-
ui/object-safety/issue-102933.rs
3177-
ui/object-safety/issue-106247.rs
3178-
ui/object-safety/issue-19538.rs
31793175
ui/on-unimplemented/issue-104140.rs
31803176
ui/or-patterns/issue-64879-trailing-before-guard.rs
31813177
ui/or-patterns/issue-67514-irrefutable-param.rs

Diff for: 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 {

Diff for: 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;

Diff for: 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);

Diff for: 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
}

Diff for: 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
}

Diff for: 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> {}

Diff for: tests/ui/allocator/dyn-compatible.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-pass
2+
3+
// Check that `Allocator` is dyn-compatible, this allows for polymorphic allocators
4+
5+
#![feature(allocator_api)]
6+
7+
use std::alloc::{Allocator, System};
8+
9+
fn ensure_dyn_compatible(_: &dyn Allocator) {}
10+
11+
fn main() {
12+
ensure_dyn_compatible(&System);
13+
}

Diff for: tests/ui/allocator/object-safe.rs

-13
This file was deleted.

Diff for: tests/ui/associated-type-bounds/entails-sized-object-safety.rs renamed to tests/ui/associated-type-bounds/entails-sized-dyn-compatibility.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ trait Tr1: Sized { type As1; }
44
trait Tr2<'a>: Sized { type As2; }
55

66
trait ObjTr1 { fn foo() -> Self where Self: Tr1<As1: Copy>; }
7-
fn _assert_obj_safe_1(_: Box<dyn ObjTr1>) {}
7+
fn _assert_dyn_compat_1(_: Box<dyn ObjTr1>) {}
88

99
trait ObjTr2 { fn foo() -> Self where Self: Tr1<As1: 'static>; }
10-
fn _assert_obj_safe_2(_: Box<dyn ObjTr2>) {}
10+
fn _assert_dyn_compat_2(_: Box<dyn ObjTr2>) {}
1111

1212
trait ObjTr3 { fn foo() -> Self where Self: Tr1<As1: Into<u8> + 'static + Copy>; }
13-
fn _assert_obj_safe_3(_: Box<dyn ObjTr3>) {}
13+
fn _assert_dyn_compat_3(_: Box<dyn ObjTr3>) {}
1414

1515
trait ObjTr4 { fn foo() -> Self where Self: Tr1<As1: for<'a> Tr2<'a>>; }
16-
fn _assert_obj_safe_4(_: Box<dyn ObjTr4>) {}
16+
fn _assert_dyn_compat_4(_: Box<dyn ObjTr4>) {}
1717

1818
trait ObjTr5 { fn foo() -> Self where for<'a> Self: Tr1<As1: Tr2<'a>>; }
19-
fn _assert_obj_safe_5(_: Box<dyn ObjTr5>) {}
19+
fn _assert_dyn_compat_5(_: Box<dyn ObjTr5>) {}
2020

2121
trait ObjTr6 { fn foo() -> Self where Self: for<'a> Tr1<As1: Tr2<'a, As2: for<'b> Tr2<'b>>>; }
22-
fn _assert_obj_safe_6(_: Box<dyn ObjTr6>) {}
22+
fn _assert_dyn_compat_6(_: Box<dyn ObjTr6>) {}
2323

2424
fn main() {}

Diff for: tests/ui/async-await/in-trait/object-safety.stderr renamed to tests/ui/async-await/in-trait/dyn-compatibility.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0038]: the trait `Foo` cannot be made into an object
2-
--> $DIR/object-safety.rs:9:12
2+
--> $DIR/dyn-compatibility.rs:9:12
33
|
44
LL | let x: &dyn Foo = todo!();
55
| ^^^^^^^^ `Foo` 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/object-safety.rs:5:14
8+
--> $DIR/dyn-compatibility.rs:5:14
99
|
1010
LL | trait Foo {
1111
| --- this trait cannot be made into an object...

Diff for: tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.rs renamed to tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Test that we give suitable error messages when the user attempts to
22
// impl a trait `Trait` for its own object type.
33

4-
// If the trait is not object-safe, we give a more tailored message
4+
// If the trait is dyn-incompatible, we give a more tailored message
55
// because we're such schnuckels:
6-
trait NotObjectSafe { fn eq(&self, other: Self); }
7-
impl NotObjectSafe for dyn NotObjectSafe { }
6+
trait DynIncompatible { fn eq(&self, other: Self); }
7+
impl DynIncompatible for dyn DynIncompatible { }
88
//~^ ERROR E0038
99
//~| ERROR E0046
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0038]: the trait `DynIncompatible` cannot be made into an object
2+
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:26
3+
|
4+
LL | impl DynIncompatible for dyn DynIncompatible { }
5+
| ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` cannot be made into an object
6+
|
7+
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/coherence-impl-trait-for-trait-dyn-compatible.rs:6:45
9+
|
10+
LL | trait DynIncompatible { fn eq(&self, other: Self); }
11+
| --------------- ^^^^ ...because method `eq` references the `Self` type in this parameter
12+
| |
13+
| this trait cannot be made into an object...
14+
= help: consider moving `eq` to another trait
15+
16+
error[E0046]: not all trait items implemented, missing: `eq`
17+
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:1
18+
|
19+
LL | trait DynIncompatible { fn eq(&self, other: Self); }
20+
| -------------------------- `eq` from trait
21+
LL | impl DynIncompatible for dyn DynIncompatible { }
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation
23+
24+
error: aborting due to 2 previous errors
25+
26+
Some errors have detailed explanations: E0038, E0046.
27+
For more information about an error, try `rustc --explain E0038`.

Diff for: tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr

-27
This file was deleted.

Diff for: 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);

Diff for: tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr renamed to tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0038]: the trait `ConstParamTy_` cannot be made into an object
2-
--> $DIR/const_param_ty_object_safety.rs:6:12
2+
--> $DIR/const_param_ty_dyn_compatibility.rs:6:12
33
|
44
LL | fn foo(a: &dyn ConstParamTy_) {}
55
| ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object
@@ -14,7 +14,7 @@ LL | fn foo(a: &impl ConstParamTy_) {}
1414
| ~~~~
1515

1616
error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object
17-
--> $DIR/const_param_ty_object_safety.rs:9:12
17+
--> $DIR/const_param_ty_dyn_compatibility.rs:9:12
1818
|
1919
LL | fn bar(a: &dyn UnsizedConstParamTy) {}
2020
| ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object

Diff for: tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr renamed to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0038]: the trait `Foo` cannot be made into an object
2-
--> $DIR/object-safety-err-ret.rs:17:16
2+
--> $DIR/dyn-compatibility-err-ret.rs:17:16
33
|
44
LL | fn use_dyn(v: &dyn Foo) {
55
| ^^^^^^^ `Foo` 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/object-safety-err-ret.rs:8:8
8+
--> $DIR/dyn-compatibility-err-ret.rs:8:8
99
|
1010
LL | trait Foo {
1111
| --- this trait cannot be made into an object...
@@ -17,13 +17,13 @@ LL | fn test(&self) -> [u8; bar::<Self>()];
1717
= help: only type `()` implements the trait, consider using it directly instead
1818

1919
error[E0038]: the trait `Foo` cannot be made into an object
20-
--> $DIR/object-safety-err-ret.rs:18:5
20+
--> $DIR/dyn-compatibility-err-ret.rs:18:5
2121
|
2222
LL | v.test();
2323
| ^^^^^^^^ `Foo` cannot be made into an object
2424
|
2525
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>
26-
--> $DIR/object-safety-err-ret.rs:8:8
26+
--> $DIR/dyn-compatibility-err-ret.rs:8:8
2727
|
2828
LL | trait Foo {
2929
| --- this trait cannot be made into an object...

0 commit comments

Comments
 (0)