Skip to content

Commit

Permalink
UI tests: Rename "object safe" to "dyn compatible"
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Oct 9, 2024
1 parent 2e7a52b commit 3210aed
Show file tree
Hide file tree
Showing 155 changed files with 361 additions and 359 deletions.
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
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.

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
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-where-bounds.rs:15:16
--> $DIR/dyn-compatibility-err-where-bounds.rs:15: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-where-bounds.rs:8:8
--> $DIR/dyn-compatibility-err-where-bounds.rs:8:8
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Expand All @@ -15,13 +15,13 @@ LL | fn test(&self) where [u8; bar::<Self>()]: Sized;
= 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-where-bounds.rs:17:5
--> $DIR/dyn-compatibility-err-where-bounds.rs:17: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-where-bounds.rs:8:8
--> $DIR/dyn-compatibility-err-where-bounds.rs:8:8
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0284]: type annotations needed
--> $DIR/object-safety-ok-infer-err.rs:19:5
--> $DIR/dyn-compatibility-ok-infer-err.rs:19:5
|
LL | use_dyn(&());
| ^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `use_dyn`
|
note: required by a const generic parameter in `use_dyn`
--> $DIR/object-safety-ok-infer-err.rs:14:12
--> $DIR/dyn-compatibility-ok-infer-err.rs:14:12
|
LL | fn use_dyn<const N: usize>(v: &dyn Foo<N>) where [u8; N + 1]: Sized {
| ^^^^^^^^^^^^^^ required by this const generic parameter in `use_dyn`
Expand All @@ -15,15 +15,15 @@ LL | use_dyn::<N>(&());
| +++++

error[E0284]: type annotations needed
--> $DIR/object-safety-ok-infer-err.rs:19:5
--> $DIR/dyn-compatibility-ok-infer-err.rs:19:5
|
LL | use_dyn(&());
| ^^^^^^^ --- type must be known at this point
| |
| cannot infer the value of the const parameter `N` declared on the function `use_dyn`
|
note: required for `()` to implement `Foo<_>`
--> $DIR/object-safety-ok-infer-err.rs:8:22
--> $DIR/dyn-compatibility-ok-infer-err.rs:8:22
|
LL | impl<const N: usize> Foo<N> for () {
| -------------- ^^^^^^ ^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test for fixed unsoundness in #126079.
// Enforces that the associated types that are object safe
// Enforces that the associated types that are dyn-compatible.

use std::marker::PhantomData;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-associated-consts.rs:12:31
--> $DIR/associated-consts.rs:12:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` 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-associated-consts.rs:9:11
--> $DIR/associated-consts.rs:9:11
|
LL | trait Bar {
| --- this trait cannot be made into an object...
Expand All @@ -14,13 +14,13 @@ LL | const X: usize;
= help: consider moving `X` to another trait

error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-associated-consts.rs:14:5
--> $DIR/associated-consts.rs:14:5
|
LL | t
| ^ `Bar` 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-associated-consts.rs:9:11
--> $DIR/associated-consts.rs:9:11
|
LL | trait Bar {
| --- this trait 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 `Bar` cannot be made into an object
--> $DIR/object-safety-associated-consts.rs:14:5
--> $DIR/associated-consts.rs:14:5
|
LL | t
| ^ `Bar` 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-associated-consts.rs:9:11
--> $DIR/associated-consts.rs:9:11
|
LL | trait Bar {
| --- this trait cannot be made into an object...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Traits with bounds mentioning `Self` are not object safe
// Traits with bounds mentioning `Self` are dyn-incompatible.

trait X {
type U: PartialEq<Self>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `X` cannot be made into an object
--> $DIR/object-safety-bounds.rs:7:15
--> $DIR/bounds.rs:7:15
|
LL | fn f() -> Box<dyn X<U = u32>> {
| ^^^^^^^^^^^^^^ `X` 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-bounds.rs:4:13
--> $DIR/bounds.rs:4:13
|
LL | trait X {
| - this trait cannot be made into an object...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Check that while a trait with by-value self is object-safe, we
// Check that while a trait with by-value self is dyn-compatible, we
// can't actually invoke it from an object (yet...?).

#![feature(rustc_attrs)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0161]: cannot move a value of type `dyn Bar`
--> $DIR/object-safety-by-value-self-use.rs:15:5
--> $DIR/by-value-self-use.rs:15:5
|
LL | t.bar()
| ^ the size of `dyn Bar` cannot be statically determined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Check that a trait with by-value self is considered object-safe.
// Check that a trait with by-value self is considered dyn-compatible.

//@ build-pass (FIXME(62277): could be check-pass?)
#![allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ check-pass
// issue: rust-lang/rust#102933

use std::future::Future;

Expand Down
Loading

0 comments on commit 3210aed

Please sign in to comment.