1
Fork 0

Remove dyn_compatible_for_dispatch

This commit is contained in:
Michael Goulet 2025-02-04 02:37:13 +00:00
parent 617aad8c2e
commit f3d31f77e4
58 changed files with 524 additions and 899 deletions

View file

@ -100,6 +100,15 @@ declare_features! (
Some("renamed to `doc_notable_trait`")), Some("renamed to `doc_notable_trait`")),
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). /// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
(removed, dropck_parametricity, "1.38.0", Some(28498), None), (removed, dropck_parametricity, "1.38.0", Some(28498), None),
/// 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".
(removed, dyn_compatible_for_dispatch, "1.83.0", Some(43561),
Some("removed, not used heavily and represented additional complexity in dyn compatibility")),
/// Uses generic effect parameters for ~const bounds /// Uses generic effect parameters for ~const bounds
(removed, effects, "1.84.0", Some(102090), (removed, effects, "1.84.0", Some(102090),
Some("removed, redundant with `#![feature(const_trait_impl)]`")), Some("removed, redundant with `#![feature(const_trait_impl)]`")),

View file

@ -270,14 +270,6 @@ declare_features! (
(unstable, doc_notable_trait, "1.52.0", Some(45040)), (unstable, doc_notable_trait, "1.52.0", Some(45040)),
/// Allows using the `may_dangle` attribute (RFC 1327). /// Allows using the `may_dangle` attribute (RFC 1327).
(unstable, dropck_eyepatch, "1.10.0", Some(34761)), (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, "1.83.0", Some(43561)),
/// Allows using the `#[fundamental]` attribute. /// Allows using the `#[fundamental]` attribute.
(unstable, fundamental, "1.0.0", Some(29635)), (unstable, fundamental, "1.0.0", Some(29635)),
/// Allows using `#[link_name="llvm.*"]`. /// Allows using `#[link_name="llvm.*"]`.

View file

@ -199,11 +199,7 @@ fn check_object_overlap<'tcx>(
for component_def_id in component_def_ids { for component_def_id in component_def_ids {
if !tcx.is_dyn_compatible(component_def_id) { if !tcx.is_dyn_compatible(component_def_id) {
// Without the 'dyn_compatible_for_dispatch' feature this is an error // This is a WF error tested by `coherence-impl-trait-for-trait-dyn-compatible.rs`.
// which will be reported by wfcheck. Ignore it here.
// This is tested by `coherence-impl-trait-for-trait-dyn-compatible.rs`.
// With the feature enabled, the trait is not implemented automatically,
// so this is valid.
} else { } else {
let mut supertrait_def_ids = elaborate::supertrait_def_ids(tcx, component_def_id); let mut supertrait_def_ids = elaborate::supertrait_def_ids(tcx, component_def_id);
if supertrait_def_ids if supertrait_def_ids

View file

@ -538,10 +538,10 @@ fn receiver_for_self_ty<'tcx>(
/// a pointer. /// a pointer.
/// ///
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in /// 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 /// a new check that `Trait` is dyn-compatible, creating a cycle.
/// is stabilized, see tracking issue <https://github.com/rust-lang/rust/issues/43561>). /// Instead, we emulate a placeholder by introducing a new type parameter `U` such that
/// 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`. /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
///
/// Written as a chalk-style query: /// Written as a chalk-style query:
/// ```ignore (not-rust) /// ```ignore (not-rust)
/// forall (U: Trait + ?Sized) { /// forall (U: Trait + ?Sized) {
@ -572,8 +572,6 @@ fn receiver_is_dispatchable<'tcx>(
// the type `U` in the query // the type `U` in the query
// use a bogus type parameter to mimic a forall(U) query using u32::MAX for now. // use a bogus type parameter to mimic a forall(U) query using u32::MAX for now.
// 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> = let unsized_self_ty: Ty<'tcx> =
Ty::new_param(tcx, u32::MAX, rustc_span::sym::RustaceansAreAwesome); Ty::new_param(tcx, u32::MAX, rustc_span::sym::RustaceansAreAwesome);

View file

@ -859,13 +859,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
if let Some(principal) = data.principal() { if let Some(principal) = data.principal() {
if !self.infcx.tcx.features().dyn_compatible_for_dispatch() { principal.with_self_ty(self.tcx(), self_ty)
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)
} else {
return;
}
} else { } else {
// Only auto trait bounds exist. // Only auto trait bounds exist.
return; return;

View file

@ -904,19 +904,14 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
// FIXME(#27579) RFC also considers adding trait // FIXME(#27579) RFC also considers adding trait
// obligations that don't refer to Self and // obligations that don't refer to Self and
// checking those // checking those
if let Some(principal) = data.principal_def_id() {
let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch(); self.out.push(traits::Obligation::with_depth(
tcx,
if !defer_to_coercion { self.cause(ObligationCauseCode::WellFormed(None)),
if let Some(principal) = data.principal_def_id() { self.recursion_depth,
self.out.push(traits::Obligation::with_depth( self.param_env,
tcx, ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
self.cause(ObligationCauseCode::WellFormed(None)), ));
self.recursion_depth,
self.param_env,
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
));
}
} }
} }

View file

@ -3827,7 +3827,6 @@ ui/suggestions/issue-103646.rs
ui/suggestions/issue-104086-suggest-let.rs ui/suggestions/issue-104086-suggest-let.rs
ui/suggestions/issue-104287.rs ui/suggestions/issue-104287.rs
ui/suggestions/issue-104327.rs ui/suggestions/issue-104327.rs
ui/suggestions/issue-104328.rs
ui/suggestions/issue-104961.rs ui/suggestions/issue-104961.rs
ui/suggestions/issue-105226.rs ui/suggestions/issue-105226.rs
ui/suggestions/issue-105494.rs ui/suggestions/issue-105494.rs

View file

@ -1,18 +0,0 @@
// Check that unsafe trait object do not implement themselves
// automatically
#![feature(dyn_compatible_for_dispatch)]
trait Trait: Sized {
fn call(&self);
}
fn takes_t<S: Trait>(s: S) {
s.call();
}
fn takes_t_obj(t: &dyn Trait) {
takes_t(t); //~ ERROR E0277
}
fn main() {}

View file

@ -1,22 +0,0 @@
error[E0277]: the trait bound `&dyn Trait: Trait` is not satisfied
--> $DIR/coherence-unsafe-trait-object-impl.rs:15:13
|
LL | takes_t(t);
| ------- ^ the trait `Trait` is not implemented for `&dyn Trait`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> $DIR/coherence-unsafe-trait-object-impl.rs:6:1
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
note: required by a bound in `takes_t`
--> $DIR/coherence-unsafe-trait-object-impl.rs:10:15
|
LL | fn takes_t<S: Trait>(s: S) {
| ^^^^^ required by this bound in `takes_t`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,10 +1,7 @@
//@ check-pass
// Regression test for #128176. Previously we would call `type_of` on the `1` anon const // Regression test for #128176. Previously we would call `type_of` on the `1` anon const
// before the anon const had been lowered and had the `type_of` fed with a result. // before the anon const had been lowered and had the `type_of` fed with a result.
#![feature(generic_const_exprs)] #![feature(generic_const_exprs)]
#![feature(dyn_compatible_for_dispatch)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
trait X { trait X {
@ -13,6 +10,7 @@ trait X {
const _: () = { const _: () = {
fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {} fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
//~^ ERROR the trait `X` is not dyn compatible
}; };
fn main() {} fn main() {}

View file

@ -0,0 +1,19 @@
error[E0038]: the trait `X` is not dyn compatible
--> $DIR/cg-in-dyn-issue-128176.rs:12:24
|
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
| ^^^^^^^^^^^^^^^^^^^^ `X` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/cg-in-dyn-issue-128176.rs:8:10
|
LL | trait X {
| - this trait is not dyn compatible...
LL | type Y<const N: i16>;
| ^ ...because it contains the generic associated type `Y`
= help: consider moving `Y` to another trait
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,20 +0,0 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/associated-consts.rs:14:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/associated-consts.rs:9:11
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | const X: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `X` to another trait
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,16 +1,12 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// from traits with associated consts. // from traits with associated consts.
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Bar { trait Bar {
const X: usize; const X: usize;
} }
fn make_bar<T:Bar>(t: &T) -> &dyn Bar { fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//~^ ERROR E0038 //~^ ERROR E0038
} }

View file

@ -1,35 +1,34 @@
error[E0038]: the trait `Bar` is not dyn compatible error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:20:5 --> $DIR/associated-consts.rs:8:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/associated-consts.rs:5:11
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | const X: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `X` to another trait
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/associated-consts.rs:10:5
| |
LL | t LL | t
| ^ `Bar` is not dyn compatible | ^ `Bar` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:10:8 --> $DIR/associated-consts.rs:5:11
| |
LL | trait Bar { LL | trait Bar {
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T); LL | const X: usize;
| ^^^ ...because method `bar` has generic type parameters | ^ ...because it contains this associated `const`
= help: consider moving `bar` to another trait = help: consider moving `X` to another trait
= note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:27:5
|
LL | t as &dyn Bar
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:10:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
= note: required for the cast from `&T` to `&dyn Bar` = note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -1,9 +1,6 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// from traits with generic methods, unless `where Self : Sized` is // from traits with generic methods, unless `where Self : Sized` is
// present. // present.
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Bar { trait Bar {
@ -16,18 +13,16 @@ trait Quux {
} }
fn make_bar<T:Bar>(t: &T) -> &dyn Bar { fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//[dyn_compatible_for_dispatch]~^ ERROR E0038 //~^ ERROR E0038
//[curr]~^^ ERROR E0038
} }
fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar { fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t as &dyn Bar t as &dyn Bar
//[dyn_compatible_for_dispatch]~^ ERROR E0038 //~^ ERROR E0038
//[curr]~^^ ERROR E0038 //~| ERROR E0038
//[curr]~| ERROR E0038
} }
fn make_quux<T:Quux>(t: &T) -> &dyn Quux { fn make_quux<T:Quux>(t: &T) -> &dyn Quux {

View file

@ -0,0 +1,85 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:15:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:7:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:21:40
|
LL | fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:7:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:17:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:7:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
= note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:23:10
|
LL | t as &dyn Bar
| ^^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:7:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/generics.rs:23:5
|
LL | t as &dyn Bar
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/generics.rs:7:8
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,12 +1,12 @@
error[E0038]: the trait `Bar` is not dyn compatible error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/mentions-Self.rs:22:31 --> $DIR/mentions-Self.rs:18:31
| |
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar { LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible | ^^^^^^^ `Bar` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:11:22 --> $DIR/mentions-Self.rs:7:22
| |
LL | trait Bar { LL | trait Bar {
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...
@ -15,14 +15,14 @@ LL | fn bar(&self, x: &Self);
= help: consider moving `bar` to another trait = help: consider moving `bar` to another trait
error[E0038]: the trait `Baz` is not dyn compatible error[E0038]: the trait `Baz` is not dyn compatible
--> $DIR/mentions-Self.rs:28:31 --> $DIR/mentions-Self.rs:24:31
| |
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz { LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
| ^^^^^^^ `Baz` is not dyn compatible | ^^^^^^^ `Baz` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:15:22 --> $DIR/mentions-Self.rs:11:22
| |
LL | trait Baz { LL | trait Baz {
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...
@ -31,14 +31,14 @@ LL | fn baz(&self) -> Self;
= help: consider moving `baz` to another trait = help: consider moving `baz` to another trait
error[E0038]: the trait `Bar` is not dyn compatible error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/mentions-Self.rs:24:5 --> $DIR/mentions-Self.rs:20:5
| |
LL | t LL | t
| ^ `Bar` is not dyn compatible | ^ `Bar` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:11:22 --> $DIR/mentions-Self.rs:7:22
| |
LL | trait Bar { LL | trait Bar {
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...
@ -48,14 +48,14 @@ LL | fn bar(&self, x: &Self);
= note: required for the cast from `&T` to `&dyn Bar` = note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Baz` is not dyn compatible error[E0038]: the trait `Baz` is not dyn compatible
--> $DIR/mentions-Self.rs:30:5 --> $DIR/mentions-Self.rs:26:5
| |
LL | t LL | t
| ^ `Baz` is not dyn compatible | ^ `Baz` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:15:22 --> $DIR/mentions-Self.rs:11:22
| |
LL | trait Baz { LL | trait Baz {
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...

View file

@ -1,10 +1,6 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// form traits that make use of `Self` in an argument or return // form traits that make use of `Self` in an argument or return
// position, unless `where Self : Sized` is present.. // position, unless `where Self : Sized` is present..
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Bar { trait Bar {
@ -20,13 +16,13 @@ trait Quux {
} }
fn make_bar<T:Bar>(t: &T) -> &dyn Bar { fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//~^ ERROR E0038 //~^ ERROR E0038
} }
fn make_baz<T:Baz>(t: &T) -> &dyn Baz { fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//~^ ERROR E0038 //~^ ERROR E0038
} }

View file

@ -0,0 +1,69 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/mentions-Self.rs:18:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:7:22
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar(&self, x: &Self);
| ^^^^^ ...because method `bar` references the `Self` type in this parameter
= help: consider moving `bar` to another trait
error[E0038]: the trait `Baz` is not dyn compatible
--> $DIR/mentions-Self.rs:24:31
|
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
| ^^^^^^^ `Baz` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:11:22
|
LL | trait Baz {
| --- this trait is not dyn compatible...
LL | fn baz(&self) -> Self;
| ^^^^ ...because method `baz` references the `Self` type in its return type
= help: consider moving `baz` to another trait
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/mentions-Self.rs:20:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:7:22
|
LL | trait Bar {
| --- this trait is not dyn compatible...
LL | fn bar(&self, x: &Self);
| ^^^^^ ...because method `bar` references the `Self` type in this parameter
= help: consider moving `bar` to another trait
= note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Baz` is not dyn compatible
--> $DIR/mentions-Self.rs:26:5
|
LL | t
| ^ `Baz` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:11:22
|
LL | trait Baz {
| --- this trait is not dyn compatible...
LL | fn baz(&self) -> Self;
| ^^^^ ...because method `baz` references the `Self` type in its return type
= help: consider moving `baz` to another trait
= note: required for the cast from `&T` to `&dyn Baz`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,28 +0,0 @@
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/no-static.rs:22:27
|
LL | let b: Box<dyn Foo> = Box::new(Bar);
| ^^^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/no-static.rs:9:8
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo() {}
| ^^^ ...because associated function `foo` has no `self` parameter
= help: only type `Bar` implements `Foo`; consider using it directly instead.
= note: required for the cast from `Box<Bar>` to `Box<dyn Foo>`
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self) {}
| +++++
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
LL | fn foo() where Self: Sized {}
| +++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,16 +1,12 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// from traits with static methods. // from traits with static methods.
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Foo { trait Foo {
fn foo() {} fn foo() {}
} }
fn diverges() -> Box<dyn Foo> { fn diverges() -> Box<dyn Foo> {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
loop { } loop { }
} }
@ -21,5 +17,5 @@ impl Foo for Bar {}
fn main() { fn main() {
let b: Box<dyn Foo> = Box::new(Bar); let b: Box<dyn Foo> = Box::new(Bar);
//~^ ERROR E0038 //~^ ERROR E0038
//[curr]~| ERROR E0038 //~| ERROR E0038
} }

View file

@ -0,0 +1,76 @@
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/no-static.rs:8:22
|
LL | fn diverges() -> Box<dyn Foo> {
| ^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/no-static.rs:5:8
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo() {}
| ^^^ ...because associated function `foo` has no `self` parameter
= help: only type `Bar` implements `Foo`; consider using it directly instead.
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self) {}
| +++++
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
LL | fn foo() where Self: Sized {}
| +++++++++++++++++
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/no-static.rs:18:12
|
LL | let b: Box<dyn Foo> = Box::new(Bar);
| ^^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/no-static.rs:5:8
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo() {}
| ^^^ ...because associated function `foo` has no `self` parameter
= help: only type `Bar` implements `Foo`; consider using it directly instead.
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self) {}
| +++++
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
LL | fn foo() where Self: Sized {}
| +++++++++++++++++
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/no-static.rs:18:27
|
LL | let b: Box<dyn Foo> = Box::new(Bar);
| ^^^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/no-static.rs:5:8
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo() {}
| ^^^ ...because associated function `foo` has no `self` parameter
= help: only type `Bar` implements `Foo`; consider using it directly instead.
= note: required for the cast from `Box<Bar>` to `Box<dyn Foo>`
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self) {}
| +++++
help: alternatively, consider constraining `foo` so it does not apply to trait objects
|
LL | fn foo() where Self: Sized {}
| +++++++++++++++++
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,19 +0,0 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/sized-2.rs:16:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/sized-2.rs:9:18
|
LL | trait Bar
| --- this trait is not dyn compatible...
LL | where Self : Sized
| ^^^^^ ...because it requires `Self: Sized`
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,9 +1,5 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// from traits where `Self : Sized`. // from traits where `Self : Sized`.
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Bar trait Bar
where Self : Sized where Self : Sized
@ -12,7 +8,7 @@ trait Bar
} }
fn make_bar<T:Bar>(t: &T) -> &dyn Bar { fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//~^ ERROR E0038 //~^ ERROR E0038
} }

View file

@ -1,37 +1,34 @@
error[E0038]: the trait `Bar` is not dyn compatible error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/mentions-Self.rs:24:5 --> $DIR/sized-2.rs:10:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/sized-2.rs:5:18
|
LL | trait Bar
| --- this trait is not dyn compatible...
LL | where Self : Sized
| ^^^^^ ...because it requires `Self: Sized`
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/sized-2.rs:12:5
| |
LL | t LL | t
| ^ `Bar` is not dyn compatible | ^ `Bar` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:11:22 --> $DIR/sized-2.rs:5:18
| |
LL | trait Bar { LL | trait Bar
| --- this trait is not dyn compatible... | --- this trait is not dyn compatible...
LL | fn bar(&self, x: &Self); LL | where Self : Sized
| ^^^^^ ...because method `bar` references the `Self` type in this parameter | ^^^^^ ...because it requires `Self: Sized`
= help: consider moving `bar` to another trait
= note: required for the cast from `&T` to `&dyn Bar` = note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Baz` is not dyn compatible
--> $DIR/mentions-Self.rs:30:5
|
LL | t
| ^ `Baz` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/mentions-Self.rs:15:22
|
LL | trait Baz {
| --- this trait is not dyn compatible...
LL | fn baz(&self) -> Self;
| ^^^^ ...because method `baz` references the `Self` type in its return type
= help: consider moving `baz` to another trait
= note: required for the cast from `&T` to `&dyn Baz`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0038`. For more information about this error, try `rustc --explain E0038`.

View file

@ -1,19 +0,0 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/sized.rs:14:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/sized.rs:8:12
|
LL | trait Bar: Sized {
| --- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,16 +1,12 @@
// Check that we correctly prevent users from making trait objects // Check that we correctly prevent users from making trait objects
// from traits where `Self : Sized`. // from traits where `Self : Sized`.
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Bar: Sized { trait Bar: Sized {
fn bar<T>(&self, t: T); fn bar<T>(&self, t: T);
} }
fn make_bar<T: Bar>(t: &T) -> &dyn Bar { fn make_bar<T: Bar>(t: &T) -> &dyn Bar {
//[curr]~^ ERROR E0038 //~^ ERROR E0038
t t
//~^ ERROR E0038 //~^ ERROR E0038
} }

View file

@ -0,0 +1,34 @@
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/sized.rs:8:32
|
LL | fn make_bar<T: Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/sized.rs:4:12
|
LL | trait Bar: Sized {
| --- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
error[E0038]: the trait `Bar` is not dyn compatible
--> $DIR/sized.rs:10:5
|
LL | t
| ^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/sized.rs:4:12
|
LL | trait Bar: Sized {
| --- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,27 +0,0 @@
error[E0038]: the trait `Qux` is not dyn compatible
--> $DIR/taint-const-eval.rs:11:33
|
LL | static FOO: &(dyn Qux + Sync) = "desc";
| ^^^^^^ `Qux` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/taint-const-eval.rs:8:8
|
LL | trait Qux {
| --- this trait is not dyn compatible...
LL | fn bar();
| ^^^ ...because associated function `bar` has no `self` parameter
= note: required for the cast from `&'static str` to `&'static (dyn Qux + Sync + 'static)`
help: consider turning `bar` into a method by giving it a `&self` argument
|
LL | fn bar(&self);
| +++++
help: alternatively, consider constraining `bar` so it does not apply to trait objects
|
LL | fn bar() where Self: Sized;
| +++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,16 +1,12 @@
// Test that we do not attempt to create dyn-incompatible trait objects in const eval. // Test that we do not attempt to create dyn-incompatible trait objects in const eval.
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
trait Qux { trait Qux {
fn bar(); fn bar();
} }
static FOO: &(dyn Qux + Sync) = "desc"; static FOO: &(dyn Qux + Sync) = "desc";
//~^ the trait `Qux` is not dyn compatible //~^ the trait `Qux` is not dyn compatible
//[curr]~| the trait `Qux` is not dyn compatible //~| the trait `Qux` is not dyn compatible
//[curr]~| the trait `Qux` is not dyn compatible //~| the trait `Qux` is not dyn compatible
fn main() {} fn main() {}

View file

@ -0,0 +1,74 @@
error[E0038]: the trait `Qux` is not dyn compatible
--> $DIR/taint-const-eval.rs:7:15
|
LL | static FOO: &(dyn Qux + Sync) = "desc";
| ^^^^^^^^^^^^^^ `Qux` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/taint-const-eval.rs:4:8
|
LL | trait Qux {
| --- this trait is not dyn compatible...
LL | fn bar();
| ^^^ ...because associated function `bar` has no `self` parameter
help: consider turning `bar` into a method by giving it a `&self` argument
|
LL | fn bar(&self);
| +++++
help: alternatively, consider constraining `bar` so it does not apply to trait objects
|
LL | fn bar() where Self: Sized;
| +++++++++++++++++
error[E0038]: the trait `Qux` is not dyn compatible
--> $DIR/taint-const-eval.rs:7:33
|
LL | static FOO: &(dyn Qux + Sync) = "desc";
| ^^^^^^ `Qux` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/taint-const-eval.rs:4:8
|
LL | trait Qux {
| --- this trait is not dyn compatible...
LL | fn bar();
| ^^^ ...because associated function `bar` has no `self` parameter
= note: required for the cast from `&'static str` to `&'static (dyn Qux + Sync + 'static)`
help: consider turning `bar` into a method by giving it a `&self` argument
|
LL | fn bar(&self);
| +++++
help: alternatively, consider constraining `bar` so it does not apply to trait objects
|
LL | fn bar() where Self: Sized;
| +++++++++++++++++
error[E0038]: the trait `Qux` is not dyn compatible
--> $DIR/taint-const-eval.rs:7:15
|
LL | static FOO: &(dyn Qux + Sync) = "desc";
| ^^^^^^^^^^^^^^ `Qux` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/taint-const-eval.rs:4:8
|
LL | trait Qux {
| --- this trait is not dyn compatible...
LL | fn bar();
| ^^^ ...because associated function `bar` has no `self` parameter
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider turning `bar` into a method by giving it a `&self` argument
|
LL | fn bar(&self);
| +++++
help: alternatively, consider constraining `bar` so it does not apply to trait objects
|
LL | fn bar() where Self: Sized;
| +++++++++++++++++
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,41 +0,0 @@
// 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() {}

View file

@ -1,88 +0,0 @@
error[E0038]: the trait `DynIncompatible1` is not dyn compatible
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:40
|
LL | fn takes_dyn_incompatible_ref<T>(obj: &dyn DynIncompatible1) {
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
|
LL | trait DynIncompatible1: Sized {}
| ---------------- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
error[E0038]: the trait `DynIncompatible2` is not dyn compatible
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:46
|
LL | fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 {
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:7:8
|
LL | trait DynIncompatible2 {
| ---------------- this trait is not dyn compatible...
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` is not dyn compatible
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:40
|
LL | fn takes_dyn_incompatible_box(obj: Box<dyn DynIncompatible3>) {
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8
|
LL | trait DynIncompatible3 {
| ---------------- this trait is not dyn compatible...
LL | fn foo<T>(&self);
| ^^^ ...because method `foo` has generic type parameters
= help: consider moving `foo` to another trait
error[E0038]: the trait `DynIncompatible4` is not dyn compatible
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:48
|
LL | fn return_dyn_incompatible_rc() -> std::rc::Rc<dyn DynIncompatible4> {
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:15:22
|
LL | trait DynIncompatible4 {
| ---------------- this trait is not dyn compatible...
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` is not dyn compatible
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:38:16
|
LL | impl Trait for dyn DynIncompatible1 {}
| ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25
|
LL | trait DynIncompatible1: Sized {}
| ---------------- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,8 +1,4 @@
// Test that Copy bounds inherited by trait are checked. // Test that Copy bounds inherited by trait are checked.
//
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
use std::any::Any; use std::any::Any;
@ -18,17 +14,15 @@ fn take_param<T:Foo>(foo: &T) { }
fn a() { fn a() {
let x: Box<_> = Box::new(3); let x: Box<_> = Box::new(3);
take_param(&x); //[curr]~ ERROR E0277 take_param(&x); //~ ERROR E0277
//[dyn_compatible_for_dispatch]~^ ERROR E0277
} }
fn b() { fn b() {
let x: Box<_> = Box::new(3); let x: Box<_> = Box::new(3);
let y = &x; let y = &x;
let z = &x as &dyn Foo; let z = &x as &dyn Foo;
//[curr]~^ ERROR E0038 //~^ ERROR E0038
//[curr]~| ERROR E0038 //~| ERROR E0038
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
} }
fn main() { } fn main() { }

View file

@ -1,5 +1,5 @@
error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
--> $DIR/kindck-inherited-copy-bound.rs:21:16 --> $DIR/kindck-inherited-copy-bound.rs:17:16
| |
LL | take_param(&x); LL | take_param(&x);
| ---------- ^^ the trait `Copy` is not implemented for `Box<{integer}>` | ---------- ^^ the trait `Copy` is not implemented for `Box<{integer}>`
@ -7,35 +7,50 @@ LL | take_param(&x);
| required by a bound introduced by this call | required by a bound introduced by this call
| |
note: required for `Box<{integer}>` to implement `Foo` note: required for `Box<{integer}>` to implement `Foo`
--> $DIR/kindck-inherited-copy-bound.rs:14:14 --> $DIR/kindck-inherited-copy-bound.rs:10:14
| |
LL | impl<T:Copy> Foo for T { LL | impl<T:Copy> Foo for T {
| ---- ^^^ ^ | ---- ^^^ ^
| | | |
| unsatisfied trait bound introduced here | unsatisfied trait bound introduced here
note: required by a bound in `take_param` note: required by a bound in `take_param`
--> $DIR/kindck-inherited-copy-bound.rs:17:17 --> $DIR/kindck-inherited-copy-bound.rs:13:17
| |
LL | fn take_param<T:Foo>(foo: &T) { } LL | fn take_param<T:Foo>(foo: &T) { }
| ^^^ required by this bound in `take_param` | ^^^ required by this bound in `take_param`
error[E0038]: the trait `Foo` is not dyn compatible error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/kindck-inherited-copy-bound.rs:28:13 --> $DIR/kindck-inherited-copy-bound.rs:23:19
|
LL | let z = &x as &dyn Foo;
| ^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/kindck-inherited-copy-bound.rs:6:13
|
LL | trait Foo : Copy {
| --- ^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/kindck-inherited-copy-bound.rs:23:13
| |
LL | let z = &x as &dyn Foo; LL | let z = &x as &dyn Foo;
| ^^ `Foo` is not dyn compatible | ^^ `Foo` is not dyn compatible
| |
note: for a trait to be dyn compatible it needs to allow building a vtable note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/kindck-inherited-copy-bound.rs:10:13 --> $DIR/kindck-inherited-copy-bound.rs:6:13
| |
LL | trait Foo : Copy { LL | trait Foo : Copy {
| --- ^^^^ ...because it requires `Self: Sized` | --- ^^^^ ...because it requires `Self: Sized`
| | | |
| this trait is not dyn compatible... | this trait is not dyn compatible...
= note: required for the cast from `&Box<i32>` to `&dyn Foo` = note: required for the cast from `&Box<{integer}>` to `&dyn Foo`
error: aborting due to 2 previous errors error: aborting due to 3 previous errors
Some errors have detailed explanations: E0038, E0277. Some errors have detailed explanations: E0038, E0277.
For more information about an error, try `rustc --explain E0038`. For more information about an error, try `rustc --explain E0038`.

View file

@ -1,23 +0,0 @@
// 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(dyn_compatible_for_dispatch)]
trait Trait: Sized {}
fn downcast_auto(t: &(dyn Trait + Send)) -> &dyn Trait {
t
}
fn downcast_lifetime<'a, 'b, 't>(t: &'a (dyn Trait + 't))
-> &'b (dyn Trait + 't)
where
'a: 'b,
't: 'a + 'b,
{
t
}
fn main() {}

View file

@ -1,15 +0,0 @@
warning: methods `good_virt` and `good_indirect` are never used
--> $DIR/manual-self-impl-for-unsafe-obj.rs:23:8
|
LL | trait Good {
| ---- methods in this trait
LL | fn good_virt(&self) -> char {
| ^^^^^^^^^
...
LL | fn good_indirect(&self) -> char {
| ^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: 1 warning emitted

View file

@ -1,15 +0,0 @@
warning: methods `good_virt` and `good_indirect` are never used
--> $DIR/manual-self-impl-for-unsafe-obj.rs:23:8
|
LL | trait Good {
| ---- methods in this trait
LL | fn good_virt(&self) -> char {
| ^^^^^^^^^
...
LL | fn good_indirect(&self) -> char {
| ^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: 1 warning emitted

View file

@ -1,69 +0,0 @@
// 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(dyn_compatible_for_dispatch)]
trait Bad {
fn stat() -> char {
'A'
}
fn virt(&self) -> char {
'B'
}
fn indirect(&self) -> char {
Self::stat()
}
}
trait Good {
fn good_virt(&self) -> char { //~ WARN methods `good_virt` and `good_indirect` are never used
panic!()
}
fn good_indirect(&self) -> char {
panic!()
}
}
impl<'a> Bad for dyn Bad + 'a {
fn stat() -> char {
'C'
}
fn virt(&self) -> char {
'D'
}
}
struct Struct {}
impl Bad for Struct {}
impl Good for Struct {}
fn main() {
let s = Struct {};
let mut res = String::new();
// Directly call static.
res.push(Struct::stat()); // "A"
res.push(<dyn Bad>::stat()); // "AC"
let good: &dyn Good = &s;
// These look similar enough...
let bad = unsafe { std::mem::transmute::<&dyn Good, &dyn Bad>(good) };
// Call virtual.
res.push(s.virt()); // "ACB"
res.push(bad.virt()); // "ACBD"
// Indirectly call static.
res.push(s.indirect()); // "ACBDA"
res.push(bad.indirect()); // "ACBDAC"
assert_eq!(&res, "ACBDAC");
}

View file

@ -1,37 +0,0 @@
// Check that we can statically dispatch methods for object
// unsafe trait objects, directly and indirectly
//
//@ check-pass
#![feature(dyn_compatible_for_dispatch)]
trait Statics {
fn plain() {}
fn generic<T>() {}
}
trait Trait: Sized {}
impl<'a> Statics for dyn Trait + 'a {}
fn static_poly<T: Statics + ?Sized>() {
T::plain();
T::generic::<usize>();
}
fn inferred_poly<T: Statics + ?Sized>(t: &T) {
static_poly::<T>();
T::plain();
T::generic::<usize>();
}
fn call(t: &dyn Trait) {
static_poly::<dyn Trait>();
inferred_poly(t);
}
fn main() {
static_poly::<dyn Trait>();
<dyn Trait>::plain();
<dyn Trait>::generic::<usize>()
}

View file

@ -1,15 +1,17 @@
// Doesn't trigger ICE when returning unsized trait that can be impl // Doesn't trigger ICE when returning unsized trait that can be impl
// issue https://github.com/rust-lang/rust/issues/125512 // issue https://github.com/rust-lang/rust/issues/125512
//@ edition:2021 //@ edition:2021
#![feature(dyn_compatible_for_dispatch)]
trait B { trait B {
fn f(a: A) -> A; fn f(a: A) -> A;
//~^ ERROR: expected a type, found a trait //~^ ERROR: expected a type, found a trait
//~| ERROR: expected a type, found a trait //~| ERROR: expected a type, found a trait
} }
trait A { trait A {
fn concrete(b: B) -> B; fn concrete(b: B) -> B;
//~^ ERROR: expected a type, found a trait //~^ ERROR: expected a type, found a trait
//~| ERROR: expected a type, found a trait //~| ERROR: expected a type, found a trait
} }
fn main() {} fn main() {}

View file

@ -1,5 +1,5 @@
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-return-unsized-can-impl-2.rs:11:20 --> $DIR/ice-return-unsized-can-impl-2.rs:12:20
| |
LL | fn concrete(b: B) -> B; LL | fn concrete(b: B) -> B;
| ^ | ^
@ -16,7 +16,7 @@ LL | fn concrete(b: impl B) -> B;
| ++++ | ++++
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-return-unsized-can-impl-2.rs:11:26 --> $DIR/ice-return-unsized-can-impl-2.rs:12:26
| |
LL | fn concrete(b: B) -> B; LL | fn concrete(b: B) -> B;
| ^ | ^

View file

@ -1,7 +1,6 @@
// Doesn't trigger ICE when returning unsized trait that can be impl // Doesn't trigger ICE when returning unsized trait that can be impl
// issue https://github.com/rust-lang/rust/issues/120482 // issue https://github.com/rust-lang/rust/issues/120482
//@ edition:2021 //@ edition:2021
#![feature(dyn_compatible_for_dispatch)]
trait B { trait B {
fn bar(&self, x: &Self); fn bar(&self, x: &Self);

View file

@ -1,5 +1,5 @@
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-return-unsized-can-impl.rs:11:15 --> $DIR/ice-return-unsized-can-impl.rs:10:15
| |
LL | fn g(new: B) -> B; LL | fn g(new: B) -> B;
| ^ | ^
@ -16,7 +16,7 @@ LL | fn g(new: impl B) -> B;
| ++++ | ++++
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-return-unsized-can-impl.rs:11:21 --> $DIR/ice-return-unsized-can-impl.rs:10:21
| |
LL | fn g(new: B) -> B; LL | fn g(new: B) -> B;
| ^ | ^

View file

@ -1,7 +1,7 @@
//@ edition:2021 //@ edition:2021
// Test that it doesn't trigger an ICE when using an unsized fn params. // Test that it doesn't trigger an ICE when using an unsized fn params.
// https://github.com/rust-lang/rust/issues/120241 // https://github.com/rust-lang/rust/issues/120241
#![feature(dyn_compatible_for_dispatch)]
#![feature(unsized_fn_params)] #![feature(unsized_fn_params)]
fn guard(_s: Copy) -> bool { fn guard(_s: Copy) -> bool {

View file

@ -1,7 +1,6 @@
//@ edition:2021 //@ edition:2021
// Test that it doesn't trigger an ICE when using an unsized fn params. // Test that it doesn't trigger an ICE when using an unsized fn params.
// https://github.com/rust-lang/rust/issues/120241 // https://github.com/rust-lang/rust/issues/120241
#![feature(dyn_compatible_for_dispatch)]
trait B { trait B {
fn f(a: A) -> A; fn f(a: A) -> A;

View file

@ -1,5 +1,5 @@
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-unsized-fn-params.rs:13:13 --> $DIR/ice-unsized-fn-params.rs:12:13
| |
LL | fn g(b: B) -> B; LL | fn g(b: B) -> B;
| ^ | ^
@ -16,7 +16,7 @@ LL | fn g(b: impl B) -> B;
| ++++ | ++++
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-unsized-fn-params.rs:13:19 --> $DIR/ice-unsized-fn-params.rs:12:19
| |
LL | fn g(b: B) -> B; LL | fn g(b: B) -> B;
| ^ | ^
@ -27,7 +27,7 @@ LL | fn g(b: B) -> impl B;
| ++++ | ++++
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-unsized-fn-params.rs:7:13 --> $DIR/ice-unsized-fn-params.rs:6:13
| |
LL | fn f(a: A) -> A; LL | fn f(a: A) -> A;
| ^ | ^
@ -44,7 +44,7 @@ LL | fn f(a: impl A) -> A;
| ++++ | ++++
error[E0782]: expected a type, found a trait error[E0782]: expected a type, found a trait
--> $DIR/ice-unsized-fn-params.rs:7:19 --> $DIR/ice-unsized-fn-params.rs:6:19
| |
LL | fn f(a: A) -> A; LL | fn f(a: A) -> A;
| ^ | ^

View file

@ -1,23 +0,0 @@
error[E0038]: the trait `Foo` is not dyn compatible
--> $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`
...
LL | let x = Rc::new(5usize) as Rc<dyn Foo>;
| ^^^^^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo(self: &Rc<Self>) -> usize;
| ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
= help: only type `usize` implements `Foo`; consider using it directly instead.
= note: required for the cast from `Rc<usize>` to `Rc<dyn Foo>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,7 +1,3 @@
//@ revisions: curr dyn_compatible_for_dispatch
#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))]
use std::rc::Rc; use std::rc::Rc;
trait Foo { trait Foo {
@ -31,9 +27,8 @@ impl Bar for usize {
fn make_foo() { fn make_foo() {
let x = Rc::new(5usize) as Rc<dyn Foo>; let x = Rc::new(5usize) as Rc<dyn Foo>;
//[curr]~^ ERROR E0038 //~^ ERROR E0038
//[curr]~| ERROR E0038 //~| ERROR E0038
//[dyn_compatible_for_dispatch]~^^^ ERROR E0038
} }
fn make_bar() { fn make_bar() {

View file

@ -0,0 +1,42 @@
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:29:32
|
LL | fn foo(self: &Rc<Self>) -> usize;
| --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
...
LL | let x = Rc::new(5usize) as Rc<dyn Foo>;
| ^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:4:18
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo(self: &Rc<Self>) -> usize;
| ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
= help: only type `usize` implements `Foo`; consider using it directly instead.
error[E0038]: the trait `Foo` is not dyn compatible
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:29:13
|
LL | fn foo(self: &Rc<Self>) -> usize;
| --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
...
LL | let x = Rc::new(5usize) as Rc<dyn Foo>;
| ^^^^^^^^^^^^^^^ `Foo` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/arbitrary-self-types-dyn-incompatible.rs:4:18
|
LL | trait Foo {
| --- this trait is not dyn compatible...
LL | fn foo(self: &Rc<Self>) -> usize;
| ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
= help: only type `usize` implements `Foo`; consider using it directly instead.
= note: required for the cast from `Rc<usize>` to `Rc<dyn Foo>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,12 +0,0 @@
#![feature(dyn_compatible_for_dispatch)]
trait Foo {
fn f() {}
}
impl Foo for dyn Sized {}
fn main() {
Foo::f();
//~^ ERROR cannot call associated function on trait without specifying the corresponding `impl` type
}

View file

@ -1,17 +0,0 @@
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> $DIR/issue-104328.rs:10:5
|
LL | fn f() {}
| --------- `Foo::f` defined here
...
LL | Foo::f();
| ^^^^^^^^ cannot call associated function of trait
|
help: use the fully-qualified path to the only available implementation
|
LL | <(dyn Sized + 'static) as Foo>::f();
| +++++++++++++++++++++++++ +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0790`.

View file

@ -1,18 +0,0 @@
// Check that we do not allow casts or coercions
// to dyn-incompatible trait objects inside a Box
#![feature(dyn_compatible_for_dispatch)]
trait Trait: Sized {}
struct S;
impl Trait for S {}
fn takes_box(t: Box<dyn Trait>) {}
fn main() {
Box::new(S) as Box<dyn Trait>; //~ ERROR E0038
let t_box: Box<dyn Trait> = Box::new(S); //~ ERROR E0038
takes_box(Box::new(S)); //~ ERROR E0038
}

View file

@ -1,54 +0,0 @@
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:16:33
|
LL | let t_box: Box<dyn Trait> = Box::new(S);
| ^^^^^^^^^^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `Box<S>` to `Box<dyn Trait>`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:17:15
|
LL | takes_box(Box::new(S));
| ^^^^^^^^^^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `Box<S>` to `Box<(dyn Trait + 'static)>`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:15:5
|
LL | Box::new(S) as Box<dyn Trait>;
| ^^^^^^^^^^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `Box<S>` to `Box<dyn Trait>`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,18 +0,0 @@
// Check that we do not allow casts or coercions
// to dyn-incompatible trait objects by ref
#![feature(dyn_compatible_for_dispatch)]
trait Trait: Sized {}
struct S;
impl Trait for S {}
fn takes_trait(t: &dyn Trait) {}
fn main() {
&S as &dyn Trait; //~ ERROR E0038
let t: &dyn Trait = &S; //~ ERROR E0038
takes_trait(&S); //~ ERROR E0038
}

View file

@ -1,54 +0,0 @@
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:16:25
|
LL | let t: &dyn Trait = &S;
| ^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:17:17
|
LL | takes_trait(&S);
| ^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:15:5
|
LL | &S as &dyn Trait;
| ^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: only type `S` implements `Trait`; consider using it directly instead.
= note: required for the cast from `&S` to `&dyn Trait`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0038`.

View file

@ -1,29 +0,0 @@
// Check that we do not allow coercions to object
// unsafe trait objects in match arms
#![feature(dyn_compatible_for_dispatch)]
trait Trait: Sized {}
struct S;
impl Trait for S {}
struct R;
impl Trait for R {}
fn opt() -> Option<()> {
Some(())
}
fn main() {
match opt() {
Some(()) => &S,
None => &R, //~ ERROR E0308
}
let t: &dyn Trait = match opt() {
Some(()) => &S, //~ ERROR E0038
None => &R, //~ ERROR E0038
};
}

View file

@ -1,60 +0,0 @@
error[E0308]: `match` arms have incompatible types
--> $DIR/wf-dyn-incompat-trait-obj-match.rs:23:17
|
LL | / match opt() {
LL | | Some(()) => &S,
| | -- this is found to be of type `&S`
LL | | None => &R,
| | ^^ expected `&S`, found `&R`
LL | | }
| |_____- `match` arms have incompatible types
|
= note: expected reference `&S`
found reference `&R`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-dyn-incompat-trait-obj-match.rs:26:21
|
LL | Some(()) => &S,
| ^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-dyn-incompat-trait-obj-match.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: the following types implement `Trait`:
S
R
consider defining an enum where each variant holds one of these types,
implementing `Trait` for this new enum and using it instead
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` is not dyn compatible
--> $DIR/wf-dyn-incompat-trait-obj-match.rs:27:17
|
LL | None => &R,
| ^^ `Trait` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> $DIR/wf-dyn-incompat-trait-obj-match.rs:6:14
|
LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait is not dyn compatible...
= help: the following types implement `Trait`:
S
R
consider defining an enum where each variant holds one of these types,
implementing `Trait` for this new enum and using it instead
= note: required for the cast from `&R` to `&dyn Trait`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0038, E0308.
For more information about an error, try `rustc --explain E0038`.