UI tests: Rename "object safe" to "dyn compatible"
This commit is contained in:
parent
2e7a52b22f
commit
20cebae312
@ -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
|
||||
|
13
tests/ui/allocator/dyn-compatible.rs
Normal file
13
tests/ui/allocator/dyn-compatible.rs
Normal file
@ -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);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
// Check that `Allocator` is object safe, this allows for polymorphic allocators
|
||||
|
||||
#![feature(allocator_api)]
|
||||
|
||||
use std::alloc::{Allocator, System};
|
||||
|
||||
fn ensure_object_safe(_: &dyn Allocator) {}
|
||||
|
||||
fn main() {
|
||||
ensure_object_safe(&System);
|
||||
}
|
@ -4,21 +4,21 @@
|
||||
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() {}
|
@ -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...
|
@ -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
|
||||
|
@ -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`.
|
@ -1,27 +0,0 @@
|
||||
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
|
||||
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:24
|
||||
|
|
||||
LL | impl NotObjectSafe for dyn NotObjectSafe { }
|
||||
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` 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-object-safe.rs:6:43
|
||||
|
|
||||
LL | trait NotObjectSafe { 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-object-safe.rs:7:1
|
||||
|
|
||||
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
|
||||
| -------------------------- `eq` from trait
|
||||
LL | impl NotObjectSafe for dyn NotObjectSafe { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`.
|
@ -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
|
||||
@ -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
|
@ -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...
|
||||
@ -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...
|
@ -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...
|
||||
@ -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...
|
@ -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`
|
||||
@ -15,7 +15,7 @@ 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
|
||||
@ -23,7 +23,7 @@ LL | use_dyn(&());
|
||||
| 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 () {
|
||||
| -------------- ^^^^^^ ^^
|
@ -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;
|
||||
|
@ -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...
|
||||
@ -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...
|
@ -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...
|
@ -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>;
|
@ -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...
|
@ -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)]
|
@ -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
|
@ -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)]
|
@ -1,4 +1,5 @@
|
||||
//@ check-pass
|
||||
// issue: rust-lang/rust#102933
|
||||
|
||||
use std::future::Future;
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:18:31
|
||||
--> $DIR/generics.rs:18: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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -14,13 +14,13 @@ LL | fn bar<T>(&self, t: T);
|
||||
= help: consider moving `bar` to another trait
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:25:40
|
||||
--> $DIR/generics.rs:25:40
|
||||
|
|
||||
LL | fn make_bar_explicit<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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -29,13 +29,13 @@ LL | fn bar<T>(&self, t: T);
|
||||
= help: consider moving `bar` to another trait
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:20:5
|
||||
--> $DIR/generics.rs:20: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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -45,13 +45,13 @@ LL | fn bar<T>(&self, t: T);
|
||||
= note: required for the cast from `&T` to `&dyn Bar`
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:27:10
|
||||
--> $DIR/generics.rs:27:10
|
||||
|
|
||||
LL | t as &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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -60,13 +60,13 @@ LL | fn bar<T>(&self, t: T);
|
||||
= help: consider moving `bar` to another trait
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:27:5
|
||||
--> $DIR/generics.rs:27:5
|
||||
|
|
||||
LL | t as &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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:20:5
|
||||
--> $DIR/generics.rs:20: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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -15,13 +15,13 @@ LL | fn bar<T>(&self, t: T);
|
||||
= note: required for the cast from `&T` to `&dyn Bar`
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-generics.rs:27:5
|
||||
--> $DIR/generics.rs:27:5
|
||||
|
|
||||
LL | t as &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-generics.rs:10:8
|
||||
--> $DIR/generics.rs:10:8
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,4 +1,5 @@
|
||||
//@ check-pass
|
||||
// issue: rust-lang/rust#106247
|
||||
|
||||
pub trait Trait {
|
||||
fn method(&self) where Self: Sync;
|
@ -1,3 +1,5 @@
|
||||
// issue: rust-lang/rust#19538
|
||||
|
||||
trait Foo {
|
||||
fn foo<T>(&self, val: T);
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/issue-19538.rs:17:15
|
||||
--> $DIR/mention-correct-dyn-incompatible-trait.rs:19:15
|
||||
|
|
||||
LL | let test: &mut dyn Bar = &mut thing;
|
||||
| ^^^^^^^^^^^^ `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/issue-19538.rs:2:8
|
||||
--> $DIR/mention-correct-dyn-incompatible-trait.rs:4:8
|
||||
|
|
||||
LL | fn foo<T>(&self, val: T);
|
||||
| ^^^ ...because method `foo` has generic type parameters
|
||||
@ -16,13 +16,13 @@ LL | trait Bar: Foo { }
|
||||
= help: only type `Thing` implements the trait, consider using it directly instead
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/issue-19538.rs:17:30
|
||||
--> $DIR/mention-correct-dyn-incompatible-trait.rs:19:30
|
||||
|
|
||||
LL | let test: &mut dyn Bar = &mut thing;
|
||||
| ^^^^^^^^^^ `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/issue-19538.rs:2:8
|
||||
--> $DIR/mention-correct-dyn-incompatible-trait.rs:4:8
|
||||
|
|
||||
LL | fn foo<T>(&self, val: T);
|
||||
| ^^^ ...because method `foo` has generic type parameters
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Expr` cannot be made into an object
|
||||
--> $DIR/object-safety-issue-22040.rs:12:23
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:12:23
|
||||
|
|
||||
LL | elements: Vec<Box<dyn Expr + 'x>>,
|
||||
| ^^^^^^^^^^^^^ `Expr` 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-issue-22040.rs:5:21
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:5:21
|
||||
|
|
||||
LL | trait Expr: Debug + PartialEq {
|
||||
| ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter
|
||||
@ -14,13 +14,13 @@ LL | trait Expr: Debug + PartialEq {
|
||||
= help: only type `SExpr<'x>` implements the trait, consider using it directly instead
|
||||
|
||||
error[E0038]: the trait `Expr` cannot be made into an object
|
||||
--> $DIR/object-safety-issue-22040.rs:38:16
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:38:16
|
||||
|
|
||||
LL | let a: Box<dyn Expr> = Box::new(SExpr::new());
|
||||
| ^^^^^^^^ `Expr` 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-issue-22040.rs:5:21
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:5:21
|
||||
|
|
||||
LL | trait Expr: Debug + PartialEq {
|
||||
| ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter
|
||||
@ -29,13 +29,13 @@ LL | trait Expr: Debug + PartialEq {
|
||||
= help: only type `SExpr<'x>` implements the trait, consider using it directly instead
|
||||
|
||||
error[E0038]: the trait `Expr` cannot be made into an object
|
||||
--> $DIR/object-safety-issue-22040.rs:40:16
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:40:16
|
||||
|
|
||||
LL | let b: Box<dyn Expr> = Box::new(SExpr::new());
|
||||
| ^^^^^^^^ `Expr` 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-issue-22040.rs:5:21
|
||||
--> $DIR/mentions-Self-in-super-predicates.rs:5:21
|
||||
|
|
||||
LL | trait Expr: Debug + PartialEq {
|
||||
| ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:22:31
|
||||
--> $DIR/mentions-Self.rs:22: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-mentions-Self.rs:11:22
|
||||
--> $DIR/mentions-Self.rs:11:22
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -14,13 +14,13 @@ LL | fn bar(&self, x: &Self);
|
||||
= help: consider moving `bar` to another trait
|
||||
|
||||
error[E0038]: the trait `Baz` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:28:31
|
||||
--> $DIR/mentions-Self.rs:28:31
|
||||
|
|
||||
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
|
||||
| ^^^^^^^ `Baz` 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-mentions-Self.rs:15:22
|
||||
--> $DIR/mentions-Self.rs:15:22
|
||||
|
|
||||
LL | trait Baz {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -29,13 +29,13 @@ LL | fn baz(&self) -> Self;
|
||||
= help: consider moving `baz` to another trait
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:24:5
|
||||
--> $DIR/mentions-Self.rs:24: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-mentions-Self.rs:11:22
|
||||
--> $DIR/mentions-Self.rs:11:22
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -45,13 +45,13 @@ LL | fn bar(&self, x: &Self);
|
||||
= note: required for the cast from `&T` to `&dyn Bar`
|
||||
|
||||
error[E0038]: the trait `Baz` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:30:5
|
||||
--> $DIR/mentions-Self.rs:30:5
|
||||
|
|
||||
LL | t
|
||||
| ^ `Baz` 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-mentions-Self.rs:15:22
|
||||
--> $DIR/mentions-Self.rs:15:22
|
||||
|
|
||||
LL | trait Baz {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:24:5
|
||||
--> $DIR/mentions-Self.rs:24: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-mentions-Self.rs:11:22
|
||||
--> $DIR/mentions-Self.rs:11:22
|
||||
|
|
||||
LL | trait Bar {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -15,13 +15,13 @@ LL | fn bar(&self, x: &Self);
|
||||
= note: required for the cast from `&T` to `&dyn Bar`
|
||||
|
||||
error[E0038]: the trait `Baz` cannot be made into an object
|
||||
--> $DIR/object-safety-mentions-Self.rs:30:5
|
||||
--> $DIR/mentions-Self.rs:30:5
|
||||
|
|
||||
LL | t
|
||||
| ^ `Baz` 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-mentions-Self.rs:15:22
|
||||
--> $DIR/mentions-Self.rs:15:22
|
||||
|
|
||||
LL | trait Baz {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-unsafe-missing-assoc-type.rs:5:16
|
||||
--> $DIR/missing-assoc-type.rs:5:16
|
||||
|
|
||||
LL | fn bar(x: &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-unsafe-missing-assoc-type.rs:2:10
|
||||
--> $DIR/missing-assoc-type.rs:2:10
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -14,13 +14,13 @@ LL | type Bar<T>;
|
||||
= help: consider moving `Bar` to another trait
|
||||
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-unsafe-missing-assoc-type.rs:5:16
|
||||
--> $DIR/missing-assoc-type.rs:5:16
|
||||
|
|
||||
LL | fn bar(x: &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-unsafe-missing-assoc-type.rs:2:10
|
||||
--> $DIR/missing-assoc-type.rs:2:10
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -30,13 +30,13 @@ LL | type Bar<T>;
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-unsafe-missing-assoc-type.rs:5:16
|
||||
--> $DIR/missing-assoc-type.rs:5:16
|
||||
|
|
||||
LL | fn bar(x: &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-unsafe-missing-assoc-type.rs:2:10
|
||||
--> $DIR/missing-assoc-type.rs:2:10
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -46,13 +46,13 @@ LL | type Bar<T>;
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-unsafe-missing-assoc-type.rs:5:12
|
||||
--> $DIR/missing-assoc-type.rs:5:12
|
||||
|
|
||||
LL | fn bar(x: &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-unsafe-missing-assoc-type.rs:2:10
|
||||
--> $DIR/missing-assoc-type.rs:2:10
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-safety-no-static.rs:12:22
|
||||
--> $DIR/no-static.rs:12:22
|
||||
|
|
||||
LL | fn diverges() -> Box<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-no-static.rs:9:8
|
||||
--> $DIR/no-static.rs:9:8
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -22,13 +22,13 @@ LL | fn foo() where Self: Sized {}
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-safety-no-static.rs:22:12
|
||||
--> $DIR/no-static.rs:22:12
|
||||
|
|
||||
LL | let b: Box<dyn Foo> = Box::new(Bar);
|
||||
| ^^^^^^^^^^^^ `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-no-static.rs:9:8
|
||||
--> $DIR/no-static.rs:9:8
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -45,13 +45,13 @@ LL | fn foo() where Self: Sized {}
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-safety-no-static.rs:22:27
|
||||
--> $DIR/no-static.rs:22:27
|
||||
|
|
||||
LL | let b: Box<dyn Foo> = Box::new(Bar);
|
||||
| ^^^^^^^^^^^^^ `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-no-static.rs:9:8
|
||||
--> $DIR/no-static.rs:9:8
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Foo` cannot be made into an object
|
||||
--> $DIR/object-safety-no-static.rs:22:27
|
||||
--> $DIR/no-static.rs:22:27
|
||||
|
|
||||
LL | let b: Box<dyn Foo> = Box::new(Bar);
|
||||
| ^^^^^^^^^^^^^ `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-no-static.rs:9:8
|
||||
--> $DIR/no-static.rs:9:8
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --- this trait cannot be made into an object...
|
@ -1,4 +1,4 @@
|
||||
// Check that `Self` appearing in a phantom fn does not make a trait not object safe.
|
||||
// Check that `Self` appearing in a phantom fn does not make a trait dyn-incompatible.
|
||||
|
||||
//@ build-pass (FIXME(62277): could be check-pass?)
|
||||
#![allow(dead_code)]
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized-2.rs:14:31
|
||||
--> $DIR/sized-2.rs:14: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-sized-2.rs:9:18
|
||||
--> $DIR/sized-2.rs:9:18
|
||||
|
|
||||
LL | trait Bar
|
||||
| --- this trait cannot be made into an object...
|
||||
@ -13,13 +13,13 @@ LL | where Self : Sized
|
||||
| ^^^^^ ...because it requires `Self: Sized`
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized-2.rs:16:5
|
||||
--> $DIR/sized-2.rs:16: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-sized-2.rs:9:18
|
||||
--> $DIR/sized-2.rs:9:18
|
||||
|
|
||||
LL | trait Bar
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized-2.rs:16:5
|
||||
--> $DIR/sized-2.rs:16: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-sized-2.rs:9:18
|
||||
--> $DIR/sized-2.rs:9:18
|
||||
|
|
||||
LL | trait Bar
|
||||
| --- this trait cannot be made into an object...
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized.rs:12:32
|
||||
--> $DIR/sized.rs:12:32
|
||||
|
|
||||
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-sized.rs:8:12
|
||||
--> $DIR/sized.rs:8:12
|
||||
|
|
||||
LL | trait Bar: Sized {
|
||||
| --- ^^^^^ ...because it requires `Self: Sized`
|
||||
@ -13,13 +13,13 @@ LL | trait Bar: Sized {
|
||||
| this trait cannot be made into an object...
|
||||
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized.rs:14:5
|
||||
--> $DIR/sized.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-sized.rs:8:12
|
||||
--> $DIR/sized.rs:8:12
|
||||
|
|
||||
LL | trait Bar: Sized {
|
||||
| --- ^^^^^ ...because it requires `Self: Sized`
|
@ -1,11 +1,11 @@
|
||||
error[E0038]: the trait `Bar` cannot be made into an object
|
||||
--> $DIR/object-safety-sized.rs:14:5
|
||||
--> $DIR/sized.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-sized.rs:8:12
|
||||
--> $DIR/sized.rs:8:12
|
||||
|
|
||||
LL | trait Bar: Sized {
|
||||
| --- ^^^^^ ...because it requires `Self: Sized`
|
@ -1,14 +1,14 @@
|
||||
error[E0311]: the parameter type `Self` may not live long enough
|
||||
|
|
||||
note: ...that is required by this bound
|
||||
--> $DIR/object-safety-supertrait-mentions-GAT.rs:6:15
|
||||
--> $DIR/supertrait-mentions-GAT.rs:6:15
|
||||
|
|
||||
LL | Self: 'a;
|
||||
| ^^
|
||||
= help: consider adding an explicit lifetime bound `Self: 'a`...
|
||||
|
||||
error: associated item referring to unboxed trait object for its own trait
|
||||
--> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
|
||||
--> $DIR/supertrait-mentions-GAT.rs:10:20
|
||||
|
|
||||
LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
|
||||
| ---------- in this trait
|
||||
@ -21,13 +21,13 @@ LL | fn c(&self) -> Self;
|
||||
| ~~~~
|
||||
|
||||
error[E0038]: the trait `SuperTrait` cannot be made into an object
|
||||
--> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
|
||||
--> $DIR/supertrait-mentions-GAT.rs:10:20
|
||||
|
|
||||
LL | fn c(&self) -> dyn SuperTrait<T>;
|
||||
| ^^^^^^^^^^^^^^^^^ `SuperTrait` 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-supertrait-mentions-GAT.rs:4:10
|
||||
--> $DIR/supertrait-mentions-GAT.rs:4:10
|
||||
|
|
||||
LL | type Gat<'a>
|
||||
| ^^^ ...because it contains the generic associated type `Gat`
|
@ -1,11 +1,11 @@
|
||||
error[E0277]: the size for values of type `Self` cannot be known at compilation time
|
||||
--> $DIR/object-safety-supertrait-mentions-Self.rs:8:13
|
||||
--> $DIR/supertrait-mentions-Self.rs:8:13
|
||||
|
|
||||
LL | trait Baz : Bar<Self> {
|
||||
| ^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required by an implicit `Sized` bound in `Bar`
|
||||
--> $DIR/object-safety-supertrait-mentions-Self.rs:4:11
|
||||
--> $DIR/supertrait-mentions-Self.rs:4:11
|
||||
|
|
||||
LL | trait Bar<T> {
|
||||
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
|
||||
@ -19,13 +19,13 @@ LL | trait Bar<T: ?Sized> {
|
||||
| ++++++++
|
||||
|
||||
error[E0038]: the trait `Baz` cannot be made into an object
|
||||
--> $DIR/object-safety-supertrait-mentions-Self.rs:16:31
|
||||
--> $DIR/supertrait-mentions-Self.rs:16:31
|
||||
|
|
||||
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
|
||||
| ^^^^^^^ `Baz` 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-supertrait-mentions-Self.rs:8:13
|
||||
--> $DIR/supertrait-mentions-Self.rs:8:13
|
||||
|
|
||||
LL | trait Baz : Bar<Self> {
|
||||
| --- ^^^^^^^^^ ...because it uses `Self` as a type parameter
|
@ -1,7 +1,8 @@
|
||||
//@ compile-flags: --crate-type=lib
|
||||
// This test checks that the `where_clauses_object_safety` lint does not cause
|
||||
// other object safety *hard errors* to be suppressed, because we currently
|
||||
// only emit one object safety error per trait...
|
||||
// other dyn-compatibility *hard errors* to be suppressed, because we currently
|
||||
// only emit one dyn-compatibility error per trait...
|
||||
// issue: rust-lang/rust#102762
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
@ -1,5 +1,5 @@
|
||||
error[E0038]: the trait `Fetcher` cannot be made into an object
|
||||
--> $DIR/issue-102762.rs:18:21
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:19:21
|
||||
|
|
||||
LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
|
||||
| ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self`
|
||||
@ -8,7 +8,7 @@ LL | fn fetcher() -> Box<dyn Fetcher> {
|
||||
| ^^^^^^^^^^^ `Fetcher` 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/issue-102762.rs:10:22
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22
|
||||
|
|
||||
LL | pub trait Fetcher: Send + Sync {
|
||||
| ------- this trait cannot be made into an object...
|
||||
@ -16,7 +16,7 @@ LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>>
|
||||
| ^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on
|
||||
|
||||
error[E0038]: the trait `Fetcher` cannot be made into an object
|
||||
--> $DIR/issue-102762.rs:24:19
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:25:19
|
||||
|
|
||||
LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
|
||||
| ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self`
|
||||
@ -25,7 +25,7 @@ LL | let fetcher = fetcher();
|
||||
| ^^^^^^^^^ `Fetcher` 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/issue-102762.rs:10:22
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22
|
||||
|
|
||||
LL | pub trait Fetcher: Send + Sync {
|
||||
| ------- this trait cannot be made into an object...
|
||||
@ -33,7 +33,7 @@ LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>>
|
||||
| ^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on
|
||||
|
||||
error[E0038]: the trait `Fetcher` cannot be made into an object
|
||||
--> $DIR/issue-102762.rs:26:13
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:27:13
|
||||
|
|
||||
LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
|
||||
| ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self`
|
||||
@ -42,7 +42,7 @@ LL | let _ = fetcher.get();
|
||||
| ^^^^^^^^^^^^^ `Fetcher` 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/issue-102762.rs:10:22
|
||||
--> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22
|
||||
|
|
||||
LL | pub trait Fetcher: Send + Sync {
|
||||
| ------- this trait cannot be made into an object...
|
@ -1,4 +1,4 @@
|
||||
// Check that a self parameter type requires a DispatchFromDyn impl to be object safe
|
||||
// Check that a self parameter type requires a DispatchFromDyn impl to be dyn-compatible.
|
||||
|
||||
#![feature(arbitrary_self_types, unsize, coerce_unsized)]
|
||||
|
||||
|
@ -15,20 +15,20 @@ trait DynIncompatible4 {
|
||||
fn foo(&self, s: &Self);
|
||||
}
|
||||
|
||||
fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
|
||||
fn takes_dyn_incompatible_ref<T>(obj: &dyn DynIncompatible1) {
|
||||
//~^ ERROR E0038
|
||||
}
|
||||
|
||||
fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
|
||||
fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 {
|
||||
//~^ ERROR E0038
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
|
||||
fn takes_dyn_incompatible_box(obj: Box<dyn DynIncompatible3>) {
|
||||
//~^ ERROR E0038
|
||||
}
|
||||
|
||||
fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||
fn return_dyn_incompatible_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||
//~^ ERROR E0038
|
||||
loop {}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:39
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:40
|
||||
|
|
||||
LL | fn takes_non_object_safe_ref<T>(obj: &dyn DynIncompatible1) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object
|
||||
LL | fn takes_dyn_incompatible_ref<T>(obj: &dyn DynIncompatible1) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` 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/feature-gate-dyn_compatible_for_dispatch.rs:4:25
|
||||
@ -13,10 +13,10 @@ LL | trait DynIncompatible1: Sized {}
|
||||
| this trait cannot be made into an object...
|
||||
|
||||
error[E0038]: the trait `DynIncompatible2` cannot be made into an object
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:45
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:46
|
||||
|
|
||||
LL | fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object
|
||||
LL | fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` 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/feature-gate-dyn_compatible_for_dispatch.rs:7:8
|
||||
@ -35,10 +35,10 @@ LL | fn static_fn() where Self: Sized {}
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `DynIncompatible3` cannot be made into an object
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:39
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:40
|
||||
|
|
||||
LL | fn takes_non_object_safe_box(obj: Box<dyn DynIncompatible3>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object
|
||||
LL | fn takes_dyn_incompatible_box(obj: Box<dyn DynIncompatible3>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` 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/feature-gate-dyn_compatible_for_dispatch.rs:11:8
|
||||
@ -50,10 +50,10 @@ LL | fn foo<T>(&self);
|
||||
= help: consider moving `foo` to another trait
|
||||
|
||||
error[E0038]: the trait `DynIncompatible4` cannot be made into an object
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:47
|
||||
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:48
|
||||
|
|
||||
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object
|
||||
LL | fn return_dyn_incompatible_rc() -> std::rc::Rc<dyn DynIncompatible4> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` 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/feature-gate-dyn_compatible_for_dispatch.rs:15:22
|
||||
|
@ -6,7 +6,7 @@
|
||||
trait StreamingIterator {
|
||||
type Item<'a> where Self: 'a;
|
||||
fn size_hint(&self) -> (usize, Option<usize>);
|
||||
// Uncommenting makes `StreamingIterator` not object safe
|
||||
// Uncommenting makes `StreamingIterator` dyn-incompatible.
|
||||
// fn next(&mut self) -> Self::Item<'_>;
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,25 @@
|
||||
#![allow(bare_trait_objects)]
|
||||
trait NotObjectSafe {
|
||||
|
||||
trait DynIncompatible {
|
||||
fn foo() -> Self;
|
||||
}
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
|
||||
impl NotObjectSafe for A {
|
||||
impl DynIncompatible for A {
|
||||
fn foo() -> Self {
|
||||
A
|
||||
}
|
||||
}
|
||||
|
||||
impl NotObjectSafe for B {
|
||||
impl DynIncompatible for B {
|
||||
fn foo() -> Self {
|
||||
B
|
||||
}
|
||||
}
|
||||
|
||||
fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be made into an object
|
||||
fn car() -> dyn DynIncompatible { //~ ERROR the trait `DynIncompatible` cannot be made into an object
|
||||
//~^ ERROR return type cannot have an unboxed trait object
|
||||
if true {
|
||||
return A;
|
||||
@ -26,7 +27,7 @@ fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be ma
|
||||
B
|
||||
}
|
||||
|
||||
fn cat() -> Box<dyn NotObjectSafe> { //~ ERROR the trait `NotObjectSafe` cannot be made into an
|
||||
fn cat() -> Box<dyn DynIncompatible> { //~ ERROR the trait `DynIncompatible` cannot be made into an
|
||||
if true {
|
||||
return Box::new(A); //~ ERROR cannot be made into an object
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
|
||||
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13
|
||||
error[E0038]: the trait `DynIncompatible` cannot be made into an object
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
|
||||
|
|
||||
LL | fn car() -> dyn NotObjectSafe {
|
||||
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
||||
LL | fn car() -> 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/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
||||
|
|
||||
LL | trait NotObjectSafe {
|
||||
| ------------- this trait cannot be made into an object...
|
||||
LL | trait DynIncompatible {
|
||||
| --------------- this trait cannot be made into an object...
|
||||
LL | fn foo() -> Self;
|
||||
| ^^^ ...because associated function `foo` has no `self` parameter
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead:
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead:
|
||||
A
|
||||
B
|
||||
help: consider turning `foo` into a method by giving it a `&self` argument
|
||||
@ -23,20 +23,20 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o
|
||||
LL | fn foo() -> Self where Self: Sized;
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
|
||||
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:29:17
|
||||
error[E0038]: the trait `DynIncompatible` cannot be made into an object
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:30:17
|
||||
|
|
||||
LL | fn cat() -> Box<dyn NotObjectSafe> {
|
||||
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
||||
LL | fn cat() -> Box<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/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
||||
|
|
||||
LL | trait NotObjectSafe {
|
||||
| ------------- this trait cannot be made into an object...
|
||||
LL | trait DynIncompatible {
|
||||
| --------------- this trait cannot be made into an object...
|
||||
LL | fn foo() -> Self;
|
||||
| ^^^ ...because associated function `foo` has no `self` parameter
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead:
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead:
|
||||
A
|
||||
B
|
||||
help: consider turning `foo` into a method by giving it a `&self` argument
|
||||
@ -49,15 +49,15 @@ LL | fn foo() -> Self where Self: Sized;
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0746]: return type cannot have an unboxed trait object
|
||||
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
|
||||
|
|
||||
LL | fn car() -> dyn NotObjectSafe {
|
||||
| ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
LL | fn car() -> dyn DynIncompatible {
|
||||
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: if there were a single returned type, you could use `impl Trait` instead
|
||||
help: box the return type, and wrap all of the returned values in `Box::new`
|
||||
|
|
||||
LL ~ fn car() -> Box<dyn NotObjectSafe> {
|
||||
LL ~ fn car() -> Box<dyn DynIncompatible> {
|
||||
LL |
|
||||
LL | if true {
|
||||
LL ~ return Box::new(A);
|
||||
@ -65,23 +65,23 @@ LL | }
|
||||
LL ~ Box::new(B)
|
||||
|
|
||||
|
||||
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
|
||||
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:31:16
|
||||
error[E0038]: the trait `DynIncompatible` cannot be made into an object
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:32:16
|
||||
|
|
||||
LL | return Box::new(A);
|
||||
| ^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
||||
| ^^^^^^^^^^^ `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/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
||||
|
|
||||
LL | trait NotObjectSafe {
|
||||
| ------------- this trait cannot be made into an object...
|
||||
LL | trait DynIncompatible {
|
||||
| --------------- this trait cannot be made into an object...
|
||||
LL | fn foo() -> Self;
|
||||
| ^^^ ...because associated function `foo` has no `self` parameter
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead:
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead:
|
||||
A
|
||||
B
|
||||
= note: required for the cast from `Box<A>` to `Box<(dyn NotObjectSafe + 'static)>`
|
||||
= note: required for the cast from `Box<A>` to `Box<(dyn DynIncompatible + 'static)>`
|
||||
help: consider turning `foo` into a method by giving it a `&self` argument
|
||||
|
|
||||
LL | fn foo(&self) -> Self;
|
||||
@ -91,23 +91,23 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o
|
||||
LL | fn foo() -> Self where Self: Sized;
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
|
||||
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:33:5
|
||||
error[E0038]: the trait `DynIncompatible` cannot be made into an object
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:34:5
|
||||
|
|
||||
LL | Box::new(B)
|
||||
| ^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
||||
| ^^^^^^^^^^^ `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/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8
|
||||
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8
|
||||
|
|
||||
LL | trait NotObjectSafe {
|
||||
| ------------- this trait cannot be made into an object...
|
||||
LL | trait DynIncompatible {
|
||||
| --------------- this trait cannot be made into an object...
|
||||
LL | fn foo() -> Self;
|
||||
| ^^^ ...because associated function `foo` has no `self` parameter
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead:
|
||||
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead:
|
||||
A
|
||||
B
|
||||
= note: required for the cast from `Box<B>` to `Box<(dyn NotObjectSafe + 'static)>`
|
||||
= note: required for the cast from `Box<B>` to `Box<(dyn DynIncompatible + 'static)>`
|
||||
help: consider turning `foo` into a method by giving it a `&self` argument
|
||||
|
|
||||
LL | fn foo(&self) -> Self;
|
@ -1,42 +1,42 @@
|
||||
trait NotObjectSafe {
|
||||
trait DynIncompatible {
|
||||
fn foo() -> Self;
|
||||
}
|
||||
|
||||
trait ObjectSafe {
|
||||
trait DynCompatible {
|
||||
fn bar(&self);
|
||||
}
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
|
||||
impl NotObjectSafe for A {
|
||||
impl DynIncompatible for A {
|
||||
fn foo() -> Self {
|
||||
A
|
||||
}
|
||||
}
|
||||
|
||||
impl NotObjectSafe for B {
|
||||
impl DynIncompatible for B {
|
||||
fn foo() -> Self {
|
||||
B
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectSafe for A {
|
||||
impl DynCompatible for A {
|
||||
fn bar(&self) {}
|
||||
}
|
||||
|
||||
impl ObjectSafe for B {
|
||||
impl DynCompatible for B {
|
||||
fn bar(&self) {}
|
||||
}
|
||||
|
||||
fn can() -> impl NotObjectSafe {
|
||||
fn can() -> impl DynIncompatible {
|
||||
if true {
|
||||
return A;
|
||||
}
|
||||
B //~ ERROR mismatched types
|
||||
}
|
||||
|
||||
fn cat() -> impl ObjectSafe {
|
||||
fn cat() -> impl DynCompatible {
|
||||
if true {
|
||||
return A;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user