Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler & its UI tests: Rename remaining occurrences of "object safe" to "dyn compatible" #131475

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ declare_features! (
/// then removed. But there was no utility storing it separately, so now
/// it's in this list.
(removed, no_stack_check, "1.0.0", None, None),
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible (object safe).
/// Renamed to `dyn_compatible_for_dispatch`.
(removed, object_safe_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561),
Some("renamed to `dyn_compatible_for_dispatch`")),
/// Allows using `#[on_unimplemented(..)]` on traits.
/// (Moved to `rustc_attrs`.)
(removed, on_unimplemented, "1.40.0", None, None),
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ declare_features! (
(unstable, doc_notable_trait, "1.52.0", Some(45040)),
/// Allows using the `may_dangle` attribute (RFC 1327).
(unstable, dropck_eyepatch, "1.10.0", Some(34761)),
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
///
/// Renamed from `object_safe_for_dispatch`.
///
/// [^1]: Formerly known as "object safe".
(unstable, dyn_compatible_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561)),
/// Allows using the `#[fundamental]` attribute.
(unstable, fundamental, "1.0.0", Some(29635)),
/// Allows using `#[link_name="llvm.*"]`.
Expand Down Expand Up @@ -544,13 +552,6 @@ declare_features! (
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
/// Allows `for<T>` binders in where-clauses
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
///
/// [^1]: Formerly known as "object safe".
// FIXME(dyn_compat_renaming): Rename feature.
(unstable, object_safe_for_dispatch, "1.40.0", Some(43561)),
/// Allows using enums in offset_of!
(unstable, offset_of_enum, "1.75.0", Some(120141)),
/// Allows using fields with slice type in offset_of!
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn check_object_overlap<'tcx>(
for component_def_id in component_def_ids {
if !tcx.is_dyn_compatible(component_def_id) {
// FIXME(dyn_compat_renaming): Rename test and update comment.
// Without the 'object_safe_for_dispatch' feature this is an error
// Without the 'dyn_compatible_for_dispatch' feature this is an error
// which will be reported by wfcheck. Ignore it here.
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.
// With the feature enabled, the trait is not implemented automatically,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ symbols! {
dropck_eyepatch,
dropck_parametricity,
dylib,
dyn_compatible_for_dispatch,
dyn_metadata,
dyn_star,
dyn_trait,
Expand Down
24 changes: 10 additions & 14 deletions compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! "Object safety" refers to the ability for a trait to be converted
//! to an object. In general, traits may only be converted to an
//! object if all of their methods meet certain criteria. In particular,
//! they must:
//! "Dyn-compatibility"[^1] refers to the ability for a trait to be converted
//! to a trait object. In general, traits may only be converted to a trait
//! object if certain criteria are met.
//!
//! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version
//! that doesn't contain the vtable;
//! - not reference the erased type `Self` except for in this receiver;
//! - not have generic type parameters.
//! [^1]: Formerly known as "object safety".

use std::iter;
use std::ops::ControlFlow;
Expand Down Expand Up @@ -506,8 +502,8 @@ fn virtual_call_violations_for_method<'tcx>(

/// This code checks that `receiver_is_dispatchable` is correctly implemented.
///
/// This check is outlined from the object safety check to avoid cycles with
/// layout computation, which relies on knowing whether methods are object safe.
/// This check is outlined from the dyn-compatibility check to avoid cycles with
/// layout computation, which relies on knowing whether methods are dyn-compatible.
fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) {
if !is_vtable_safe_method(tcx, trait_def_id, method) {
return;
Expand Down Expand Up @@ -643,8 +639,8 @@ fn object_ty_for_trait<'tcx>(
/// contained by the trait object, because the object that needs to be coerced is behind
/// a pointer.
///
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
/// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in
/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>).
/// Instead, we fudge a little by introducing a new type parameter `U` such that
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
Expand Down Expand Up @@ -678,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>(

// the type `U` in the query
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
// FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
// replace this with `dyn Trait`
let unsized_self_ty: Ty<'tcx> =
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome"));
Expand Down Expand Up @@ -865,7 +861,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
}

fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
// Constants can only influence object safety if they are generic and reference `Self`.
// Constants can only influence dyn-compatibility if they are generic and reference `Self`.
// This is only possible for unevaluated constants, so we walk these here.
self.tcx.expand_abstract_consts(ct).super_visit_with(self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

if let Some(principal) = data.principal() {
if !self.infcx.tcx.features().object_safe_for_dispatch {
if !self.infcx.tcx.features().dyn_compatible_for_dispatch {
principal.with_self_ty(self.tcx(), self_ty)
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
principal.with_self_ty(self.tcx(), self_ty)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
// obligations that don't refer to Self and
// checking those

let defer_to_coercion = tcx.features().object_safe_for_dispatch;
let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch;

if !defer_to_coercion {
if let Some(principal) = data.principal_def_id() {
Expand Down
4 changes: 0 additions & 4 deletions src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3173,10 +3173,6 @@ ui/nll/user-annotations/issue-55241.rs
ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs
ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs
ui/numbers-arithmetic/issue-8460.rs
ui/object-safety/issue-102762.rs
ui/object-safety/issue-102933.rs
ui/object-safety/issue-106247.rs
ui/object-safety/issue-19538.rs
ui/on-unimplemented/issue-104140.rs
ui/or-patterns/issue-64879-trailing-before-guard.rs
ui/or-patterns/issue-67514-irrefutable-param.rs
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/120241-2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: #120241
//@ edition:2021
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]
#![feature(unsized_fn_params)]

fn guard(_s: Copy) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/120241.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: #120241
//@ edition:2021
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]

trait B {
fn f(a: A) -> A;
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/120482.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: #120482
//@ edition:2021
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]

trait B {
fn bar(&self, x: &Self);
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/125512.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: rust-lang/rust#125512
//@ edition:2021
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]
trait B {
fn f(a: A) -> A;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/128176.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ known-bug: rust-lang/rust#128176

#![feature(generic_const_exprs)]
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]
trait X {
type Y<const N: i16>;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/130521.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: #130521

#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]
struct Vtable(dyn Cap);

trait Cap<'a> {}
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/allocator/dyn-compatible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ run-pass

// Check that `Allocator` is dyn-compatible, this allows for polymorphic allocators

#![feature(allocator_api)]

use std::alloc::{Allocator, System};

fn ensure_dyn_compatible(_: &dyn Allocator) {}

fn main() {
ensure_dyn_compatible(&System);
}
13 changes: 0 additions & 13 deletions tests/ui/allocator/object-safe.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ trait Tr1: Sized { type As1; }
trait Tr2<'a>: Sized { type As2; }

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

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

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

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

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

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety.rs:9:12
--> $DIR/dyn-compatibility.rs:9:12
|
LL | let x: &dyn Foo = todo!();
| ^^^^^^^^ `Foo` cannot be made into an object
|
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>
--> $DIR/object-safety.rs:5:14
--> $DIR/dyn-compatibility.rs:5:14
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Test that we give suitable error messages when the user attempts to
// impl a trait `Trait` for its own object type.

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0038]: the trait `DynIncompatible` cannot be made into an object
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:26
|
LL | impl DynIncompatible for dyn DynIncompatible { }
| ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` cannot be made into an object
|
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>
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:6:45
|
LL | trait DynIncompatible { fn eq(&self, other: Self); }
| --------------- ^^^^ ...because method `eq` references the `Self` type in this parameter
| |
| this trait cannot be made into an object...
= help: consider moving `eq` to another trait

error[E0046]: not all trait items implemented, missing: `eq`
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:1
|
LL | trait DynIncompatible { fn eq(&self, other: Self); }
| -------------------------- `eq` from trait
LL | impl DynIncompatible for dyn DynIncompatible { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0038, E0046.
For more information about an error, try `rustc --explain E0038`.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/coherence/coherence-unsafe-trait-object-impl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Check that unsafe trait object do not implement themselves
// automatically

#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]

trait Trait: Sized {
fn call(&self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0038]: the trait `ConstParamTy_` cannot be made into an object
--> $DIR/const_param_ty_object_safety.rs:6:12
--> $DIR/const_param_ty_dyn_compatibility.rs:6:12
|
LL | fn foo(a: &dyn ConstParamTy_) {}
| ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object
Expand All @@ -14,7 +14,7 @@ LL | fn foo(a: &impl ConstParamTy_) {}
| ~~~~

error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object
--> $DIR/const_param_ty_object_safety.rs:9:12
--> $DIR/const_param_ty_dyn_compatibility.rs:9:12
|
LL | fn bar(a: &dyn UnsizedConstParamTy) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety-err-ret.rs:17:16
--> $DIR/dyn-compatibility-err-ret.rs:17:16
|
LL | fn use_dyn(v: &dyn Foo) {
| ^^^^^^^ `Foo` cannot be made into an object
|
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>
--> $DIR/object-safety-err-ret.rs:8:8
--> $DIR/dyn-compatibility-err-ret.rs:8:8
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Expand All @@ -17,13 +17,13 @@ LL | fn test(&self) -> [u8; bar::<Self>()];
= help: only type `()` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety-err-ret.rs:18:5
--> $DIR/dyn-compatibility-err-ret.rs:18:5
|
LL | v.test();
| ^^^^^^^^ `Foo` cannot be made into an object
|
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>
--> $DIR/object-safety-err-ret.rs:8:8
--> $DIR/dyn-compatibility-err-ret.rs:8:8
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Expand Down
Loading
Loading