Skip to content

Commit

Permalink
Rollup merge of #131475 - fmease:compiler-mv-obj-safe-dyn-compat-2, r…
Browse files Browse the repository at this point in the history
…=jieyouxu

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

Follow-up to #130826.
Part of #130852.

1. 1st commit: Fix stupid oversights. Should've been part of #130826.
2. 2nd commit: Rename the unstable feature `object_safe_for_dispatch` to `dyn_compatible_for_dispatch`. Might not be worth the churn, you decide.
3. 3rd commit: Apply the renaming to all UI tests (contents and paths).
matthiaskrgr authored Oct 10, 2024
2 parents 75ccd9f + 20cebae commit fa3dff3
Showing 179 changed files with 535 additions and 531 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
@@ -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),
15 changes: 8 additions & 7 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
@@ -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.*"]`.
@@ -546,13 +554,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!
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -777,6 +777,7 @@ symbols! {
dropck_eyepatch,
dropck_parametricity,
dylib,
dyn_compatible_for_dispatch,
dyn_metadata,
dyn_star,
dyn_trait,
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;
@@ -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;
@@ -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`.
@@ -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"));
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
@@ -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() {
4 changes: 0 additions & 4 deletions src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
@@ -3172,10 +3172,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
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 {
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;
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);
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;
}
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>;
}
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> {}
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
@@ -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...
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

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);
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
@@ -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
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...
@@ -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...
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...
@@ -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...
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`
@@ -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 () {
| -------------- ^^^^^^ ^^
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;

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...
@@ -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...
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...
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we correctly prevent users from making trait objects
// from traits with associated consts.
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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

trait Bar {
const X: usize;
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>;
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...
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)]
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
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)]
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;

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-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...
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-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...
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we correctly prevent users from making trait objects
// from traits with generic methods, unless `where Self : Sized` is
// present.
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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


trait Bar {
@@ -18,14 +18,14 @@ trait Quux {
fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038
t
//[object_safe_for_dispatch]~^ ERROR E0038
//[dyn_compatible_for_dispatch]~^ ERROR E0038
//[curr]~^^ ERROR E0038
}

fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038
t as &dyn Bar
//[object_safe_for_dispatch]~^ ERROR E0038
//[dyn_compatible_for_dispatch]~^ ERROR E0038
//[curr]~^^ ERROR E0038
//[curr]~| ERROR E0038
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ check-pass
// issue: rust-lang/rust#106247

pub trait Trait {
fn method(&self) where Self: Sync;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// issue: rust-lang/rust#19538

trait Foo {
fn foo<T>(&self, val: T);
}
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/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
Original file line number Diff line number Diff line change
@@ -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
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-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...
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-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...
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@
// form traits that make use of `Self` in an argument or return
// position, unless `where Self : Sized` is present..
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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


trait Bar {
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-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...
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-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...
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-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...
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we correctly prevent users from making trait objects
// from traits with static methods.
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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

trait Foo {
fn foo() {}
Original file line number Diff line number Diff line change
@@ -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)]
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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...
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...
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-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...
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we correctly prevent users from making trait objects
// from traits where `Self : Sized`.
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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

trait Bar
where Self : Sized
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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`
| |
| 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`
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-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`
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we correctly prevent users from making trait objects
// from traits where `Self : Sized`.
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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

trait Bar: Sized {
fn bar<T>(&self, t: T);
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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,15 +8,15 @@ 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...
LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
| ^^^^^^^^^^^^^ ...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,15 +25,15 @@ 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...
LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
| ^^^^^^^^^^^^^ ...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...
Original file line number Diff line number Diff line change
@@ -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)]

41 changes: 41 additions & 0 deletions tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Test that the use of the dyn-incompatible trait objects
// are gated by the `dyn_compatible_for_dispatch` feature gate.

trait DynIncompatible1: Sized {}

trait DynIncompatible2 {
fn static_fn() {}
}

trait DynIncompatible3 {
fn foo<T>(&self);
}

trait DynIncompatible4 {
fn foo(&self, s: &Self);
}

fn takes_dyn_incompatible_ref<T>(obj: &dyn DynIncompatible1) {
//~^ ERROR E0038
}

fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 {
//~^ ERROR E0038
loop {}
}

fn takes_dyn_incompatible_box(obj: Box<dyn DynIncompatible3>) {
//~^ ERROR E0038
}

fn return_dyn_incompatible_rc() -> std::rc::Rc<dyn DynIncompatible4> {
//~^ ERROR E0038
loop {}
}

trait Trait {}

impl Trait for dyn DynIncompatible1 {}
//~^ ERROR E0038

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
error[E0038]: the trait `DynIncompatible1` cannot be made into an object
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:40
|
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
|
LL | trait DynIncompatible1: Sized {}
| ---------------- ^^^^^ ...because it requires `Self: 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:46
|
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
|
LL | trait DynIncompatible2 {
| ---------------- this trait cannot be made into an object...
LL | fn static_fn() {}
| ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter
help: consider turning `static_fn` into a method by giving it a `&self` argument
|
LL | fn static_fn(&self) {}
| +++++
help: alternatively, consider constraining `static_fn` so it does not apply to trait objects
|
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:40
|
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
|
LL | trait DynIncompatible3 {
| ---------------- this trait cannot be made into an object...
LL | fn foo<T>(&self);
| ^^^ ...because method `foo` has generic type parameters
= 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:48
|
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
|
LL | trait DynIncompatible4 {
| ---------------- this trait cannot be made into an object...
LL | fn foo(&self, s: &Self);
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
= help: consider moving `foo` to another trait

error[E0038]: the trait `DynIncompatible1` cannot be made into an object
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:38:16
|
LL | impl Trait for 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
|
LL | trait DynIncompatible1: Sized {}
| ---------------- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0038`.
41 changes: 0 additions & 41 deletions tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/trait-objects.rs
Original file line number Diff line number Diff line change
@@ -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<'_>;
}

Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#![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;
}
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
}
Original file line number Diff line number Diff line change
@@ -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,39 +49,39 @@ 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);
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;
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0308]: mismatched types
--> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:36:5
--> $DIR/dyn-incompatible-trait-in-return-position-impl-trait.rs:36:5
|
LL | fn can() -> impl NotObjectSafe {
| ------------------ expected `A` because of return type
LL | fn can() -> impl DynIncompatible {
| -------------------- expected `A` because of return type
...
LL | B
| ^ expected `A`, found `B`

error[E0308]: mismatched types
--> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:43:5
--> $DIR/dyn-incompatible-trait-in-return-position-impl-trait.rs:43:5
|
LL | fn cat() -> impl ObjectSafe {
| --------------- expected `A` because of return type
LL | fn cat() -> impl DynCompatible {
| ------------------ expected `A` because of return type
...
LL | B
| ^ expected `A`, found `B`
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:22
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:22
|
LL | MyTrait::foo(&self)
| ------------ ^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait`
@@ -9,13 +9,13 @@ LL | MyTrait::foo(&self)
= help: the trait `MyTrait` is implemented for `Outer`

error[E0038]: the trait `MyTrait` cannot be made into an object
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:9
|
LL | MyTrait::foo(&self)
| ^^^^^^^^^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22
|
LL | trait MyTrait {
| ------- this trait cannot be made into an object...
@@ -25,21 +25,21 @@ LL | fn foo(&self) -> impl Marker;
= help: only type `Outer` implements the trait, consider using it directly instead

error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:9
|
LL | MyTrait::foo(&self)
| ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait`
|
= help: the trait `MyTrait` is implemented for `Outer`

error[E0038]: the trait `MyTrait` cannot be made into an object
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:16:6
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:16:6
|
LL | impl dyn MyTrait {
| ^^^^^^^^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22
|
LL | trait MyTrait {
| ------- this trait cannot be made into an object...
@@ -49,13 +49,13 @@ LL | fn foo(&self) -> impl Marker;
= help: only type `Outer` implements the trait, consider using it directly instead

error[E0038]: the trait `MyTrait` cannot be made into an object
--> $DIR/cycle-effective-visibilities-during-object-safety.rs:18:15
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:18:15
|
LL | fn other(&self) -> impl Marker {
| ^^^^ `MyTrait` 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/cycle-effective-visibilities-during-object-safety.rs:5:22
--> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22
|
LL | trait MyTrait {
| ------- this trait cannot be made into an object...
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:14:33
--> $DIR/dyn-compatibility.rs:14:33
|
LL | let i = Box::new(42_u32) as 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.rs:4:22
--> $DIR/dyn-compatibility.rs:4:22
|
LL | trait Foo {
| --- this trait cannot be made into an object...
@@ -15,13 +15,13 @@ LL | fn baz(&self) -> impl Debug;
= help: only type `u32` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety.rs:17:15
--> $DIR/dyn-compatibility.rs:17:15
|
LL | let s = i.baz();
| ^^^ `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:4:22
--> $DIR/dyn-compatibility.rs:4:22
|
LL | trait Foo {
| --- this trait cannot be made into an object...
@@ -31,13 +31,13 @@ LL | fn baz(&self) -> impl Debug;
= help: only type `u32` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety.rs:17:13
--> $DIR/dyn-compatibility.rs:17:13
|
LL | let s = i.baz();
| ^^^^^^^ `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:4:22
--> $DIR/dyn-compatibility.rs:4:22
|
LL | trait Foo {
| --- this trait cannot be made into an object...
@@ -47,13 +47,13 @@ LL | fn baz(&self) -> impl Debug;
= help: only type `u32` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety.rs:14:13
--> $DIR/dyn-compatibility.rs:14:13
|
LL | let i = Box::new(42_u32) as 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.rs:4:22
--> $DIR/dyn-compatibility.rs:4:22
|
LL | trait Foo {
| --- this trait cannot be made into an object...
8 changes: 4 additions & 4 deletions tests/ui/issues/issue-58734.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
trait Trait {
fn exists(self) -> ();

fn not_object_safe() -> Self;
fn dyn_incompatible() -> Self;
}

impl Trait for () {
fn exists(self) -> () {
}

fn not_object_safe() -> Self {
fn dyn_incompatible() -> Self {
()
}
}

fn main() {
// object-safe or not, this call is OK
// dyn-compatible or not, this call is OK
Trait::exists(());
// no object safety error
// no dyn-compatibility error
Trait::nonexistent(());
//~^ ERROR no function or associated item named `nonexistent` found
//~| WARN trait objects without an explicit `dyn` are deprecated
8 changes: 4 additions & 4 deletions tests/ui/kindck/kindck-inherited-copy-bound.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Test that Copy bounds inherited by trait are checked.
//
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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


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

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

fn main() { }
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that we if we get ahold of an object unsafe trait
// Check that we if we get ahold of a dyn-incompatible trait
// object with auto traits and lifetimes, we can downcast it
//
//@ check-pass

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

trait Trait: Sized {}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Check that we can manually implement an object-unsafe trait for its trait object.
// Check that we can manually implement a dyn-incompatible trait for its trait object.

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ run-pass

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

trait Bad {
fn stat() -> char {
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
//
//@ check-pass

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

trait Statics {
fn plain() {}
2 changes: 1 addition & 1 deletion tests/ui/sanitizer/cfi/async-closures.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ use std::ops::AsyncFn;
#[inline(never)]
fn identity<T>(x: T) -> T { x }

// We can't actually create a `dyn AsyncFn()`, because it's not object-safe, but we should check
// We can't actually create a `dyn AsyncFn()`, because it's dyn-incompatible, but we should check
// that we don't bug out when we encounter one.

fn main() {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/arbitrary-self-types-not-object-safe.rs:33:32
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:32
|
LL | fn foo(self: &Rc<Self>) -> usize;
| --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
@@ -8,7 +8,7 @@ LL | let x = Rc::new(5usize) as Rc<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/arbitrary-self-types-not-object-safe.rs:8:18
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18
|
LL | trait Foo {
| --- this trait cannot be made into an object...
@@ -17,7 +17,7 @@ LL | fn foo(self: &Rc<Self>) -> usize;
= help: only type `usize` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:13
|
LL | fn foo(self: &Rc<Self>) -> usize;
| --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
@@ -26,7 +26,7 @@ LL | let x = Rc::new(5usize) as Rc<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/arbitrary-self-types-not-object-safe.rs:8:18
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:13
|
LL | fn foo(self: &Rc<Self>) -> usize;
| --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
@@ -8,7 +8,7 @@ LL | let x = Rc::new(5usize) as Rc<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/arbitrary-self-types-not-object-safe.rs:8:18
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18
|
LL | trait Foo {
| --- this trait cannot be made into an object...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ revisions: curr object_safe_for_dispatch
//@ revisions: curr dyn_compatible_for_dispatch

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

use std::rc::Rc;

@@ -33,7 +33,7 @@ fn make_foo() {
let x = Rc::new(5usize) as Rc<dyn Foo>;
//[curr]~^ ERROR E0038
//[curr]~| ERROR E0038
//[object_safe_for_dispatch]~^^^ ERROR E0038
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
}

fn make_bar() {
6 changes: 3 additions & 3 deletions tests/ui/self/arbitrary_self_types_pointers_and_wrappers.rs
Original file line number Diff line number Diff line change
@@ -50,9 +50,9 @@ impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}


trait Trait {
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
// without unsized_locals), but wrappers arond `Self` currently are not.
// FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented
// This method isn't dyn-compatible yet. Unsized by-value `self` is dyn-compatible (but not
// callable without unsized_locals), but wrappers arond `Self` currently are not.
// FIXME (mikeyhew) uncomment this when unsized rvalues dyn-compatibility is implemented
// fn wrapper(self: Wrapper<Self>) -> i32;
fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_mut)]
// Check that a trait is still object-safe (and usable) if it has
// Check that a trait is still dyn-compatible (and usable) if it has
// methods with by-value self so long as they require `Self : Sized`.


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_variables)]
// Check that a trait is still object-safe (and usable) if it has
// Check that a trait is still dyn-compatible (and usable) if it has
// generic methods so long as they require `Self : Sized`.


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
// Check that a trait is still object-safe (and usable) if it has
// Check that a trait is still dyn-compatible (and usable) if it has
// methods that return `Self` so long as they require `Self : Sized`.


8 changes: 4 additions & 4 deletions tests/ui/specialization/issue-44861.rs
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ pub trait Smartass {
type Data2: CoerceUnsized<*const [u8]>;
}

pub trait MaybeObjectSafe {}
pub trait MaybeDynCompatible {}

impl MaybeObjectSafe for () {}
impl MaybeDynCompatible for () {}

impl<T> Smartass for T {
type Data = <Self as Smartass>::Data2;
@@ -26,7 +26,7 @@ impl Smartass for () {
type Data2 = *const [u8; 1];
}

impl Smartass for dyn MaybeObjectSafe {
impl Smartass for dyn MaybeDynCompatible {
type Data = *const [u8];
type Data2 = *const [u8; 0];
}
@@ -35,6 +35,6 @@ impl<U: Smartass+?Sized, T: Smartass+?Sized> CoerceUnsized<SmartassPtr<T>> for S
where <U as Smartass>::Data: std::ops::CoerceUnsized<<T as Smartass>::Data>
{}

pub fn conv(s: SmartassPtr<()>) -> SmartassPtr<dyn MaybeObjectSafe> {
pub fn conv(s: SmartassPtr<()>) -> SmartassPtr<dyn MaybeDynCompatible> {
s
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/object-unsafe-trait-references-self.rs:9:12
--> $DIR/dyn-incompatible-trait-references-self.rs:9:12
|
LL | fn bar(x: &dyn Trait) {}
| ^^^^^^^^^ `Trait` 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-references-self.rs:2:22
--> $DIR/dyn-incompatible-trait-references-self.rs:2:22
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
@@ -18,21 +18,21 @@ LL | fn bat(&self) -> Self {}
= help: consider moving `bat` to another trait

error[E0038]: the trait `Other` cannot be made into an object
--> $DIR/object-unsafe-trait-references-self.rs:13:12
--> $DIR/dyn-incompatible-trait-references-self.rs:13:12
|
LL | fn foo(x: &dyn Other) {}
| ^^^^^^^^^ `Other` 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-references-self.rs:11:14
--> $DIR/dyn-incompatible-trait-references-self.rs:11:14
|
LL | trait Other: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/object-unsafe-trait-references-self.rs:2:22
--> $DIR/dyn-incompatible-trait-references-self.rs:2:22
|
LL | fn baz(&self, _: Self) {}
| ^^^^ doesn't have a size known at compile-time
@@ -48,7 +48,7 @@ LL | fn baz(&self, _: &Self) {}
| +

error[E0308]: mismatched types
--> $DIR/object-unsafe-trait-references-self.rs:4:27
--> $DIR/dyn-incompatible-trait-references-self.rs:4:27
|
LL | trait Trait {
| ----------- expected this type parameter
@@ -60,7 +60,7 @@ LL | fn bat(&self) -> Self {}
found unit type `()`

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/object-unsafe-trait-references-self.rs:4:22
--> $DIR/dyn-incompatible-trait-references-self.rs:4:22
|
LL | fn bat(&self) -> Self {}
| ^^^^ doesn't have a size known at compile-time
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | trait A: Sized {
| - in this trait
@@ -12,21 +12,21 @@ LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `A` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | fn f(a: A) -> A;
| ^ `A` 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-should-use-self-2021-without-dyn.rs:3:10
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:3:10
|
LL | trait A: Sized {
| - ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...

error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | trait B {
| - in this trait
@@ -39,13 +39,13 @@ LL | fn f(b: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `B` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | fn f(b: B) -> B;
| ^ `B` 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-should-use-self-2021-without-dyn.rs:11:8
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:8
|
LL | trait B {
| - this trait cannot be made into an object...
@@ -61,7 +61,7 @@ LL | fn f(b: B) -> B where Self: Sized;
| +++++++++++++++++

error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | trait C {
| - in this trait
@@ -74,23 +74,23 @@ LL | fn f(&self, c: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `C` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | fn f(&self, c: C) -> C;
| ----- ^ `C` cannot be made into an object
| |
| help: consider changing method `f`'s `self` parameter to be `&self` (notice the capitalization): `&Self`
|
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-should-use-self-2021-without-dyn.rs:18:10
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:10
|
LL | trait C {
| - this trait cannot be made into an object...
LL | fn f(&self, c: C) -> C;
| ^^^^^ ...because method `f`'s `self` parameter cannot be dispatched on

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | fn f(a: A) -> A;
| ^
@@ -106,7 +106,7 @@ LL | fn f(a: impl A) -> A;
| ++++

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:19
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:19
|
LL | fn f(a: A) -> A;
| ^
@@ -117,7 +117,7 @@ LL | fn f(a: A) -> impl A;
| ++++

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13
|
LL | fn f(b: B) -> B;
| ^
@@ -133,7 +133,7 @@ LL | fn f(b: impl B) -> B;
| ++++

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:19
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:19
|
LL | fn f(b: B) -> B;
| ^
@@ -144,7 +144,7 @@ LL | fn f(b: B) -> impl B;
| ++++

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20
|
LL | fn f(&self, c: C) -> C;
| ^
@@ -160,7 +160,7 @@ LL | fn f(&self, c: impl C) -> C;
| ++++

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:26
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:26
|
LL | fn f(&self, c: C) -> C;
| ^
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021.rs:4:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13
|
LL | trait A: Sized {
| - in this trait
@@ -12,21 +12,21 @@ LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `A` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021.rs:4:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13
|
LL | fn f(a: dyn A) -> dyn A;
| ^^^^^ `A` 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-should-use-self-2021.rs:3:10
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:3:10
|
LL | trait A: Sized {
| - ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...

error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self-2021.rs:9:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13
|
LL | trait B {
| - in this trait
@@ -39,13 +39,13 @@ LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `B` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self-2021.rs:9:13
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13
|
LL | fn f(a: dyn B) -> dyn B;
| ^^^^^ `B` 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-should-use-self-2021.rs:9:8
--> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:8
|
LL | trait B {
| - this trait cannot be made into an object...
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self.rs:3:13
--> $DIR/dyn-incompatible-trait-should-use-self.rs:3:13
|
LL | trait A: Sized {
| - in this trait
@@ -12,21 +12,21 @@ LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `A` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self.rs:3:13
--> $DIR/dyn-incompatible-trait-should-use-self.rs:3:13
|
LL | fn f(a: A) -> A;
| ^ `A` 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-should-use-self.rs:2:10
--> $DIR/dyn-incompatible-trait-should-use-self.rs:2:10
|
LL | trait A: Sized {
| - ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...

error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-unsafe-trait-should-use-self.rs:8:13
--> $DIR/dyn-incompatible-trait-should-use-self.rs:8:13
|
LL | trait B {
| - in this trait
@@ -39,13 +39,13 @@ LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~

error[E0038]: the trait `B` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-self.rs:8:13
--> $DIR/dyn-incompatible-trait-should-use-self.rs:8:13
|
LL | fn f(a: B) -> B;
| ^ `B` 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-should-use-self.rs:8:8
--> $DIR/dyn-incompatible-trait-should-use-self.rs:8:8
|
LL | trait B {
| - this trait cannot be made into an object...
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-where-sized.rs:9:12
--> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:9:12
|
LL | fn bar(x: &dyn Trait) {}
| ^^^^^^^^^ `Trait` 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-should-use-where-sized.rs:5:8
--> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:5:8
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
@@ -27,7 +27,7 @@ LL | fn bar(self: &Self) {}
| ~~~~~

error[E0307]: invalid `self` parameter type: `()`
--> $DIR/object-unsafe-trait-should-use-where-sized.rs:6:18
--> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:6:18
|
LL | fn bar(self: ()) {}
| ^^
2 changes: 1 addition & 1 deletion tests/ui/suggestions/issue-104328.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(object_safe_for_dispatch)]
#![feature(dyn_compatible_for_dispatch)]

trait Foo {
fn f() {}
6 changes: 3 additions & 3 deletions tests/ui/suggestions/issue-98500.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ aux-build:not-object-safe.rs
//@ aux-build:dyn-incompatible.rs

extern crate not_object_safe;
extern crate dyn_incompatible;

pub trait B where
Self: not_object_safe::A,
Self: dyn_incompatible::A,
{
fn f2(&self);
}
2 changes: 1 addition & 1 deletion tests/ui/suggestions/issue-98500.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ LL | struct S(Box<dyn B>);
| ^^^^^ `B` 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/auxiliary/not-object-safe.rs:4:8
--> $DIR/auxiliary/dyn-incompatible.rs:4:8
|
LL | fn f();
| ^ ...because associated function `f` has no `self` parameter
4 changes: 2 additions & 2 deletions tests/ui/traits/alias/no-duplicates.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// The purpose of this test is to demonstrate that duplicating object safe traits
// The purpose of this test is to demonstrate that duplicating dyn-compatible traits
// that are not auto traits is rejected with trait aliases even though one could
// reasonably accept this.

#![feature(trait_alias)]

use std::marker::Unpin;

// Some arbitrary object-safe trait:
// Some arbitrary dyn-compatible trait:
trait Obj {}

// Nest a few levels deep:
2 changes: 1 addition & 1 deletion tests/ui/traits/alias/no-extra-traits.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

use std::marker::Unpin;

// Some arbitrary object-safe traits:
// Some arbitrary dyn-compatible traits:
trait ObjA {}
trait ObjB {}

4 changes: 2 additions & 2 deletions tests/ui/traits/alias/object-wf.rs
Original file line number Diff line number Diff line change
@@ -20,15 +20,15 @@ fn _f0() {
let _: Box<dyn Unpin + _1 + Send + Sync>;
}

// Include object safe traits:
// Include dyn-compatible traits:

fn _f1() {
let _: Box<dyn Obj + _0>;
let _: Box<dyn Obj + _1>;
let _: Box<dyn Obj + _1 + _0>;
}

// And when the object safe trait is in a trait alias:
// And when the dyn-compatible trait is in a trait alias:

trait _2 = Obj;

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0277]: the trait bound `T: Copy` is not satisfied in `dyn Setup<From = T>`
--> $DIR/object-unsafety.rs:12:12
--> $DIR/dyn-incompatibility.rs:12:12
|
LL | copy::<dyn Setup<From=T>>(t)
| ^^^^^^^^^^^^^^^^^ within `dyn Setup<From = T>`, the trait `Copy` is not implemented for `T`, which is required by `dyn Setup<From = T>: Setup`
|
= note: required because it appears within the type `dyn Setup<From = T>`
note: required by a bound in `copy`
--> $DIR/object-unsafety.rs:7:12
--> $DIR/dyn-incompatibility.rs:7:12
|
LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
| ^^^^^ required by this bound in `copy`
@@ -16,7 +16,7 @@ LL | pub fn copy_any<T: std::marker::Copy>(t: &T) -> T {
| +++++++++++++++++++

error[E0308]: mismatched types
--> $DIR/object-unsafety.rs:12:31
--> $DIR/dyn-incompatibility.rs:12:31
|
LL | copy::<dyn Setup<From=T>>(t)
| ------------------------- ^ types differ
@@ -26,13 +26,13 @@ LL | copy::<dyn Setup<From=T>>(t)
= note: expected reference `&<dyn Setup<From = T> as Setup>::From`
found reference `&T`
note: function defined here
--> $DIR/object-unsafety.rs:7:4
--> $DIR/dyn-incompatibility.rs:7:4
|
LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
| ^^^^ --------------

error[E0277]: the trait bound `T: Copy` is not satisfied in `dyn Setup<From = T>`
--> $DIR/object-unsafety.rs:12:5
--> $DIR/dyn-incompatibility.rs:12:5
|
LL | copy::<dyn Setup<From=T>>(t)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `dyn Setup<From = T>`, the trait `Copy` is not implemented for `T`, which is required by `dyn Setup<From = T>: Setup`
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/supertrait-object-safety.rs:1:12
--> $DIR/supertrait-dyn-compatibility.rs:1:12
|
LL | #![feature(non_lifetime_binders)]
| ^^^^^^^^^^^^^^^^^^^^
@@ -8,13 +8,13 @@ LL | #![feature(non_lifetime_binders)]
= note: `#[warn(incomplete_features)]` on by default

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/supertrait-object-safety.rs:19:23
--> $DIR/supertrait-dyn-compatibility.rs:19:23
|
LL | let 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/supertrait-object-safety.rs:4:12
--> $DIR/supertrait-dyn-compatibility.rs:4:12
|
LL | trait Foo: for<T> Bar<T> {}
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
@@ -24,13 +24,13 @@ LL | trait Foo: for<T> Bar<T> {}
= note: required for the cast from `&()` to `&dyn Foo`

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/supertrait-object-safety.rs:19:12
--> $DIR/supertrait-dyn-compatibility.rs:19:12
|
LL | let 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/supertrait-object-safety.rs:4:12
--> $DIR/supertrait-dyn-compatibility.rs:4:12
|
LL | trait Foo: for<T> Bar<T> {}
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
@@ -39,13 +39,13 @@ LL | trait Foo: for<T> Bar<T> {}
= help: only type `()` implements the trait, consider using it directly instead

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/supertrait-object-safety.rs:22:5
--> $DIR/supertrait-dyn-compatibility.rs:22:5
|
LL | needs_bar(x);
| ^^^^^^^^^ `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/supertrait-object-safety.rs:4:12
--> $DIR/supertrait-dyn-compatibility.rs:4:12
|
LL | trait Foo: for<T> Bar<T> {}
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
2 changes: 1 addition & 1 deletion tests/ui/traits/object/print_vtable_sizes.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ trait A<T: help::V>: AsRef<[T::V]> + AsMut<[T::V]> {}
trait B<T>: AsRef<T> + AsRef<T> + AsRef<T> + AsRef<T> {}

trait C {
fn x() {} // not object safe, shouldn't be reported
fn x() {} // not dyn-compatible, shouldn't be reported
}

// This does not have any upcasting cost,
2 changes: 1 addition & 1 deletion tests/ui/traits/object/safety.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Check that static methods are not object-safe.
// Check that static methods render the trait dyn-incompatible.

trait Tr {
fn foo();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ build-fail
#![feature(rustc_attrs)]

// Ensure that non-object-safe methods in Iterator does not generate
// Ensure that dyn-incompatible methods in Iterator does not generate
// vtable entries.

#[rustc_dump_vtable]
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ error: vtable entries for `<std::vec::IntoIter<u8> as A>`: [
Method(<std::vec::IntoIter<u8> as Iterator>::advance_by),
Method(<std::vec::IntoIter<u8> as Iterator>::nth),
]
--> $DIR/vtable-non-object-safe.rs:8:1
--> $DIR/vtable-dyn-incompatible.rs:8:1
|
LL | trait A: Iterator {}
| ^^^^^^^^^^^^^^^^^
4 changes: 2 additions & 2 deletions tests/ui/traits/wf-object/no-duplicates.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The purpose of this test is to demonstrate that duplicating object safe traits
// The purpose of this test is to demonstrate that duplicating dyn-compatible traits
// that are not auto-traits is rejected even though one could reasonably accept this.

// Some arbitrary object-safe trait:
// Some arbitrary dyn-compatible trait:
trait Obj {}

// Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior:
2 changes: 1 addition & 1 deletion tests/ui/traits/wf-object/reverse-order.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

// Ensure that `dyn $($AutoTrait)+ ObjSafe` is well-formed.

// Some arbitrary object-safe trait:
// Some arbitrary dyn-compatible trait:
trait Obj {}

type _0 = dyn Unpin;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/by-value-trait-object-safety.rs:1:12
--> $DIR/by-value-trait-dyn-compatibility.rs:1:12
|
LL | #![feature(unsized_locals)]
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #![feature(unsized_locals)]
= note: `#[warn(incomplete_features)]` on by default

error: the `foo` method cannot be invoked on a trait object
--> $DIR/by-value-trait-object-safety.rs:20:7
--> $DIR/by-value-trait-dyn-compatibility.rs:20:7
|
LL | Self: Sized;
| ----- this has a `Sized` requirement
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Check that we do not allow casts or coercions
// to object unsafe trait objects inside a Box
// to dyn-incompatible trait objects inside a Box

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

trait Trait: Sized {}

Loading

0 comments on commit fa3dff3

Please sign in to comment.