diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 60e7788f2c05..fc58b66ad35e 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -100,6 +100,15 @@ declare_features! ( Some("renamed to `doc_notable_trait`")), /// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). (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 (removed, effects, "1.84.0", Some(102090), Some("removed, redundant with `#![feature(const_trait_impl)]`")), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index fe643e9a7d1d..66c26a541f17 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -270,14 +270,6 @@ 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, "1.83.0", Some(43561)), /// Allows using the `#[fundamental]` attribute. (unstable, fundamental, "1.0.0", Some(29635)), /// Allows using `#[link_name="llvm.*"]`. diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 1bc60087ab5e..0245d4c9fe4b 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -199,11 +199,7 @@ fn check_object_overlap<'tcx>( for component_def_id in component_def_ids { if !tcx.is_dyn_compatible(component_def_id) { - // 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-dyn-compatible.rs`. - // With the feature enabled, the trait is not implemented automatically, - // so this is valid. + // This is a WF error tested by `coherence-impl-trait-for-trait-dyn-compatible.rs`. } else { let mut supertrait_def_ids = elaborate::supertrait_def_ids(tcx, component_def_id); if supertrait_def_ids diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 740f44ebcade..d4502be6ccfe 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -538,10 +538,10 @@ fn receiver_for_self_ty<'tcx>( /// a pointer. /// /// 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 ). -/// Instead, we fudge a little by introducing a new type parameter `U` such that +/// a new check that `Trait` is dyn-compatible, creating a cycle. +/// Instead, we emulate a placeholder by introducing a new type parameter `U` such that /// `Self: Unsize` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. +/// /// Written as a chalk-style query: /// ```ignore (not-rust) /// forall (U: Trait + ?Sized) { @@ -572,8 +572,6 @@ 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 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, rustc_span::sym::RustaceansAreAwesome); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 5b362b2356e8..11b6b826efe5 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -859,13 +859,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } if let Some(principal) = data.principal() { - 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) - } else { - return; - } + principal.with_self_ty(self.tcx(), self_ty) } else { // Only auto trait bounds exist. return; diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 7f3e3ce47816..18906a6a8ce0 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -904,19 +904,14 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { // FIXME(#27579) RFC also considers adding trait // obligations that don't refer to Self and // checking those - - let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch(); - - if !defer_to_coercion { - if let Some(principal) = data.principal_def_id() { - self.out.push(traits::Obligation::with_depth( - tcx, - self.cause(ObligationCauseCode::WellFormed(None)), - self.recursion_depth, - self.param_env, - ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)), - )); - } + if let Some(principal) = data.principal_def_id() { + self.out.push(traits::Obligation::with_depth( + tcx, + self.cause(ObligationCauseCode::WellFormed(None)), + self.recursion_depth, + self.param_env, + ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)), + )); } } diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 1cb47353469f..253e13375c73 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -3827,7 +3827,6 @@ ui/suggestions/issue-103646.rs ui/suggestions/issue-104086-suggest-let.rs ui/suggestions/issue-104287.rs ui/suggestions/issue-104327.rs -ui/suggestions/issue-104328.rs ui/suggestions/issue-104961.rs ui/suggestions/issue-105226.rs ui/suggestions/issue-105494.rs diff --git a/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs b/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs deleted file mode 100644 index 16baf0958a67..000000000000 --- a/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs +++ /dev/null @@ -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: S) { - s.call(); -} - -fn takes_t_obj(t: &dyn Trait) { - takes_t(t); //~ ERROR E0277 -} - -fn main() {} diff --git a/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr b/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr deleted file mode 100644 index 4f898ec127b9..000000000000 --- a/tests/ui/coherence/coherence-unsafe-trait-object-impl.stderr +++ /dev/null @@ -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: 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`. diff --git a/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.rs b/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.rs index 5a67d34d6e5a..dac5429f678e 100644 --- a/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.rs +++ b/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.rs @@ -1,10 +1,7 @@ -//@ check-pass - // 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. #![feature(generic_const_exprs)] -#![feature(dyn_compatible_for_dispatch)] #![allow(incomplete_features)] trait X { @@ -13,6 +10,7 @@ trait X { const _: () = { fn f2<'a>(arg: Box = &'a ()>>) {} + //~^ ERROR the trait `X` is not dyn compatible }; fn main() {} diff --git a/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.stderr b/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.stderr new file mode 100644 index 000000000000..7d563e3b6054 --- /dev/null +++ b/tests/ui/const-generics/issues/cg-in-dyn-issue-128176.stderr @@ -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 = &'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 + --> $DIR/cg-in-dyn-issue-128176.rs:8:10 + | +LL | trait X { + | - this trait is not dyn compatible... +LL | type Y; + | ^ ...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`. diff --git a/tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index 704d833f00ba..000000000000 --- a/tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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 - --> $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`. diff --git a/tests/ui/dyn-compatibility/associated-consts.rs b/tests/ui/dyn-compatibility/associated-consts.rs index fc7b372b782a..10d151d9a8b5 100644 --- a/tests/ui/dyn-compatibility/associated-consts.rs +++ b/tests/ui/dyn-compatibility/associated-consts.rs @@ -1,16 +1,12 @@ // Check that we correctly prevent users from making trait objects // from traits with associated consts. -// -//@ revisions: curr dyn_compatible_for_dispatch - -#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar { const X: usize; } fn make_bar(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t //~^ ERROR E0038 } diff --git a/tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/associated-consts.stderr similarity index 61% rename from tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/associated-consts.stderr index b3565a766fe1..beaf263af07e 100644 --- a/tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/associated-consts.stderr @@ -1,35 +1,34 @@ error[E0038]: the trait `Bar` is not dyn compatible - --> $DIR/generics.rs:20:5 + --> $DIR/associated-consts.rs:8:31 | -LL | t - | ^ `Bar` is not dyn compatible +LL | fn make_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 - --> $DIR/generics.rs:10:8 + --> $DIR/associated-consts.rs:5:11 | LL | trait Bar { | --- this trait is not dyn compatible... -LL | fn bar(&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` +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/generics.rs:27:5 + --> $DIR/associated-consts.rs:10:5 | -LL | t as &dyn Bar +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 - --> $DIR/generics.rs:10:8 + --> $DIR/associated-consts.rs:5:11 | LL | trait Bar { | --- this trait is not dyn compatible... -LL | fn bar(&self, t: T); - | ^^^ ...because method `bar` has generic type parameters - = help: consider moving `bar` to another trait +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 2 previous errors diff --git a/tests/ui/dyn-compatibility/generics.rs b/tests/ui/dyn-compatibility/generics.rs index b51555aa500c..dcce17f925bc 100644 --- a/tests/ui/dyn-compatibility/generics.rs +++ b/tests/ui/dyn-compatibility/generics.rs @@ -1,9 +1,6 @@ // Check that we correctly prevent users from making trait objects // from traits with generic methods, 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 { @@ -16,18 +13,16 @@ trait Quux { } fn make_bar(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t - //[dyn_compatible_for_dispatch]~^ ERROR E0038 - //[curr]~^^ ERROR E0038 + //~^ ERROR E0038 } fn make_bar_explicit(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t as &dyn Bar - //[dyn_compatible_for_dispatch]~^ ERROR E0038 - //[curr]~^^ ERROR E0038 - //[curr]~| ERROR E0038 + //~^ ERROR E0038 + //~| ERROR E0038 } fn make_quux(t: &T) -> &dyn Quux { diff --git a/tests/ui/dyn-compatibility/generics.stderr b/tests/ui/dyn-compatibility/generics.stderr new file mode 100644 index 000000000000..c01930105419 --- /dev/null +++ b/tests/ui/dyn-compatibility/generics.stderr @@ -0,0 +1,85 @@ +error[E0038]: the trait `Bar` is not dyn compatible + --> $DIR/generics.rs:15:31 + | +LL | fn make_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 + --> $DIR/generics.rs:7:8 + | +LL | trait Bar { + | --- this trait is not dyn compatible... +LL | fn bar(&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: &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 + --> $DIR/generics.rs:7:8 + | +LL | trait Bar { + | --- this trait is not dyn compatible... +LL | fn bar(&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 + --> $DIR/generics.rs:7:8 + | +LL | trait Bar { + | --- this trait is not dyn compatible... +LL | fn bar(&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 + --> $DIR/generics.rs:7:8 + | +LL | trait Bar { + | --- this trait is not dyn compatible... +LL | fn bar(&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 + --> $DIR/generics.rs:7:8 + | +LL | trait Bar { + | --- this trait is not dyn compatible... +LL | fn bar(&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`. diff --git a/tests/ui/dyn-compatibility/mentions-Self.curr.stderr b/tests/ui/dyn-compatibility/mentions-Self.curr.stderr index 2d3fe5ce636c..6d1ae90152e6 100644 --- a/tests/ui/dyn-compatibility/mentions-Self.curr.stderr +++ b/tests/ui/dyn-compatibility/mentions-Self.curr.stderr @@ -1,12 +1,12 @@ 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: &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 - --> $DIR/mentions-Self.rs:11:22 + --> $DIR/mentions-Self.rs:7:22 | LL | trait Bar { | --- this trait is not dyn compatible... @@ -15,14 +15,14 @@ LL | fn bar(&self, x: &Self); = help: consider moving `bar` to another trait 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: &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 - --> $DIR/mentions-Self.rs:15:22 + --> $DIR/mentions-Self.rs:11:22 | LL | trait Baz { | --- this trait is not dyn compatible... @@ -31,14 +31,14 @@ LL | fn baz(&self) -> Self; = help: consider moving `baz` to another trait error[E0038]: the trait `Bar` is not dyn compatible - --> $DIR/mentions-Self.rs:24:5 + --> $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 - --> $DIR/mentions-Self.rs:11:22 + --> $DIR/mentions-Self.rs:7:22 | LL | trait Bar { | --- 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` error[E0038]: the trait `Baz` is not dyn compatible - --> $DIR/mentions-Self.rs:30:5 + --> $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 - --> $DIR/mentions-Self.rs:15:22 + --> $DIR/mentions-Self.rs:11:22 | LL | trait Baz { | --- this trait is not dyn compatible... diff --git a/tests/ui/dyn-compatibility/mentions-Self.rs b/tests/ui/dyn-compatibility/mentions-Self.rs index 84c229e252d3..ce210f4776f7 100644 --- a/tests/ui/dyn-compatibility/mentions-Self.rs +++ b/tests/ui/dyn-compatibility/mentions-Self.rs @@ -1,10 +1,6 @@ // Check that we correctly prevent users from making trait objects // form traits that make use of `Self` in an argument or return // 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 { @@ -20,13 +16,13 @@ trait Quux { } fn make_bar(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t //~^ ERROR E0038 } fn make_baz(t: &T) -> &dyn Baz { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t //~^ ERROR E0038 } diff --git a/tests/ui/dyn-compatibility/mentions-Self.stderr b/tests/ui/dyn-compatibility/mentions-Self.stderr new file mode 100644 index 000000000000..6d1ae90152e6 --- /dev/null +++ b/tests/ui/dyn-compatibility/mentions-Self.stderr @@ -0,0 +1,69 @@ +error[E0038]: the trait `Bar` is not dyn compatible + --> $DIR/mentions-Self.rs:18:31 + | +LL | fn make_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 + --> $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: &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 + --> $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 + --> $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 + --> $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`. diff --git a/tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index d5ad45103346..000000000000 --- a/tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error[E0038]: the trait `Foo` is not dyn compatible - --> $DIR/no-static.rs:22:27 - | -LL | let b: Box = 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 - --> $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` to `Box` -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`. diff --git a/tests/ui/dyn-compatibility/no-static.rs b/tests/ui/dyn-compatibility/no-static.rs index 54af16fe18eb..9bd871619728 100644 --- a/tests/ui/dyn-compatibility/no-static.rs +++ b/tests/ui/dyn-compatibility/no-static.rs @@ -1,16 +1,12 @@ // Check that we correctly prevent users from making trait objects // from traits with static methods. -// -//@ revisions: curr dyn_compatible_for_dispatch - -#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Foo { fn foo() {} } fn diverges() -> Box { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 loop { } } @@ -21,5 +17,5 @@ impl Foo for Bar {} fn main() { let b: Box = Box::new(Bar); //~^ ERROR E0038 - //[curr]~| ERROR E0038 + //~| ERROR E0038 } diff --git a/tests/ui/dyn-compatibility/no-static.stderr b/tests/ui/dyn-compatibility/no-static.stderr new file mode 100644 index 000000000000..814ab0d53c3f --- /dev/null +++ b/tests/ui/dyn-compatibility/no-static.stderr @@ -0,0 +1,76 @@ +error[E0038]: the trait `Foo` is not dyn compatible + --> $DIR/no-static.rs:8:22 + | +LL | fn diverges() -> Box { + | ^^^^^^^ `Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $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 = 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 + --> $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 = 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 + --> $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` to `Box` +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`. diff --git a/tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index 1fbc10c0c3f8..000000000000 --- a/tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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 - --> $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`. diff --git a/tests/ui/dyn-compatibility/sized-2.rs b/tests/ui/dyn-compatibility/sized-2.rs index f5edd287f24d..f61d49ee8dff 100644 --- a/tests/ui/dyn-compatibility/sized-2.rs +++ b/tests/ui/dyn-compatibility/sized-2.rs @@ -1,9 +1,5 @@ // Check that we correctly prevent users from making trait objects // from traits where `Self : Sized`. -// -//@ revisions: curr dyn_compatible_for_dispatch - -#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar where Self : Sized @@ -12,7 +8,7 @@ trait Bar } fn make_bar(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t //~^ ERROR E0038 } diff --git a/tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/sized-2.stderr similarity index 52% rename from tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/sized-2.stderr index 91c26a860259..1834d906bb89 100644 --- a/tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/sized-2.stderr @@ -1,36 +1,33 @@ error[E0038]: the trait `Bar` is not dyn compatible - --> $DIR/mentions-Self.rs:24:5 + --> $DIR/sized-2.rs:10:31 | -LL | t - | ^ `Bar` is not dyn compatible +LL | fn make_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 - --> $DIR/mentions-Self.rs:11:22 + --> $DIR/sized-2.rs:5:18 | -LL | trait Bar { +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` +LL | where Self : Sized + | ^^^^^ ...because it requires `Self: Sized` -error[E0038]: the trait `Baz` is not dyn compatible - --> $DIR/mentions-Self.rs:30:5 +error[E0038]: the trait `Bar` is not dyn compatible + --> $DIR/sized-2.rs:12:5 | LL | t - | ^ `Baz` is not dyn compatible + | ^ `Bar` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit - --> $DIR/mentions-Self.rs:15:22 + --> $DIR/sized-2.rs:5:18 | -LL | trait Baz { +LL | trait Bar | --- 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` +LL | where Self : Sized + | ^^^^^ ...because it requires `Self: Sized` + = note: required for the cast from `&T` to `&dyn Bar` error: aborting due to 2 previous errors diff --git a/tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index 350c8992c6f9..000000000000 --- a/tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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 - --> $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`. diff --git a/tests/ui/dyn-compatibility/sized.rs b/tests/ui/dyn-compatibility/sized.rs index 4c4fe3f8f259..eb5279c17e62 100644 --- a/tests/ui/dyn-compatibility/sized.rs +++ b/tests/ui/dyn-compatibility/sized.rs @@ -1,16 +1,12 @@ // Check that we correctly prevent users from making trait objects // 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 { fn bar(&self, t: T); } fn make_bar(t: &T) -> &dyn Bar { - //[curr]~^ ERROR E0038 + //~^ ERROR E0038 t //~^ ERROR E0038 } diff --git a/tests/ui/dyn-compatibility/sized.stderr b/tests/ui/dyn-compatibility/sized.stderr new file mode 100644 index 000000000000..c66e299cf6f5 --- /dev/null +++ b/tests/ui/dyn-compatibility/sized.stderr @@ -0,0 +1,34 @@ +error[E0038]: the trait `Bar` is not dyn compatible + --> $DIR/sized.rs:8:32 + | +LL | fn make_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 + --> $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 + --> $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`. diff --git a/tests/ui/dyn-compatibility/taint-const-eval.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/taint-const-eval.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index 0bc7d0b14d3d..000000000000 --- a/tests/ui/dyn-compatibility/taint-const-eval.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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 - --> $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`. diff --git a/tests/ui/dyn-compatibility/taint-const-eval.rs b/tests/ui/dyn-compatibility/taint-const-eval.rs index 2feae58080bc..7ea763e18469 100644 --- a/tests/ui/dyn-compatibility/taint-const-eval.rs +++ b/tests/ui/dyn-compatibility/taint-const-eval.rs @@ -1,16 +1,12 @@ // 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 { fn bar(); } static FOO: &(dyn Qux + Sync) = "desc"; //~^ the trait `Qux` is not dyn compatible -//[curr]~| the trait `Qux` is not dyn compatible -//[curr]~| the trait `Qux` is not dyn compatible +//~| the trait `Qux` is not dyn compatible +//~| the trait `Qux` is not dyn compatible fn main() {} diff --git a/tests/ui/dyn-compatibility/taint-const-eval.stderr b/tests/ui/dyn-compatibility/taint-const-eval.stderr new file mode 100644 index 000000000000..942c20db6ce0 --- /dev/null +++ b/tests/ui/dyn-compatibility/taint-const-eval.stderr @@ -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 + --> $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 + --> $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 + --> $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`. diff --git a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs deleted file mode 100644 index e38ab66dbe54..000000000000 --- a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs +++ /dev/null @@ -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(&self); -} - -trait DynIncompatible4 { - fn foo(&self, s: &Self); -} - -fn takes_dyn_incompatible_ref(obj: &dyn DynIncompatible1) { - //~^ ERROR E0038 -} - -fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 { - //~^ ERROR E0038 - loop {} -} - -fn takes_dyn_incompatible_box(obj: Box) { - //~^ ERROR E0038 -} - -fn return_dyn_incompatible_rc() -> std::rc::Rc { - //~^ ERROR E0038 - loop {} -} - -trait Trait {} - -impl Trait for dyn DynIncompatible1 {} -//~^ ERROR E0038 - -fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr deleted file mode 100644 index 2c3edd6e6a5f..000000000000 --- a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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(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 - --> $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 - --> $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) { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8 - | -LL | trait DynIncompatible3 { - | ---------------- this trait is not dyn compatible... -LL | fn foo(&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 { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $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 - --> $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`. diff --git a/tests/ui/kindck/kindck-inherited-copy-bound.rs b/tests/ui/kindck/kindck-inherited-copy-bound.rs index dda95229ddf0..20d54a3fb106 100644 --- a/tests/ui/kindck/kindck-inherited-copy-bound.rs +++ b/tests/ui/kindck/kindck-inherited-copy-bound.rs @@ -1,8 +1,4 @@ // 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; @@ -18,17 +14,15 @@ fn take_param(foo: &T) { } fn a() { let x: Box<_> = Box::new(3); - take_param(&x); //[curr]~ ERROR E0277 - //[dyn_compatible_for_dispatch]~^ ERROR E0277 + take_param(&x); //~ ERROR E0277 } fn b() { let x: Box<_> = Box::new(3); let y = &x; let z = &x as &dyn Foo; - //[curr]~^ ERROR E0038 - //[curr]~| ERROR E0038 - //[dyn_compatible_for_dispatch]~^^^ ERROR E0038 + //~^ ERROR E0038 + //~| ERROR E0038 } fn main() { } diff --git a/tests/ui/kindck/kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr b/tests/ui/kindck/kindck-inherited-copy-bound.stderr similarity index 55% rename from tests/ui/kindck/kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr rename to tests/ui/kindck/kindck-inherited-copy-bound.stderr index 296f011193e9..edfa7ae7769d 100644 --- a/tests/ui/kindck/kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/kindck/kindck-inherited-copy-bound.stderr @@ -1,5 +1,5 @@ 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); | ---------- ^^ 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 | 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 Foo for T { | ---- ^^^ ^ | | | unsatisfied trait bound introduced here 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(foo: &T) { } | ^^^ required by this bound in `take_param` 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 + --> $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; | ^^ `Foo` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit - --> $DIR/kindck-inherited-copy-bound.rs:10:13 + --> $DIR/kindck-inherited-copy-bound.rs:6:13 | LL | trait Foo : Copy { | --- ^^^^ ...because it requires `Self: Sized` | | | this trait is not dyn compatible... - = note: required for the cast from `&Box` 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. For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs deleted file mode 100644 index b1b2dcf3eb9f..000000000000 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs +++ /dev/null @@ -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() {} diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr deleted file mode 100644 index 1489791b20d6..000000000000 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr +++ /dev/null @@ -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 - diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr deleted file mode 100644 index 1489791b20d6..000000000000 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr +++ /dev/null @@ -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 - diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs deleted file mode 100644 index 425dc130d458..000000000000 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs +++ /dev/null @@ -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(::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"); -} diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs deleted file mode 100644 index c38928a9f44e..000000000000 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs +++ /dev/null @@ -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() {} -} - -trait Trait: Sized {} - -impl<'a> Statics for dyn Trait + 'a {} - -fn static_poly() { - T::plain(); - T::generic::(); -} - -fn inferred_poly(t: &T) { - static_poly::(); - T::plain(); - T::generic::(); -} - -fn call(t: &dyn Trait) { - static_poly::(); - inferred_poly(t); -} - -fn main() { - static_poly::(); - ::plain(); - ::generic::() -} diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs index e57e9ce4844a..567d37e1b820 100644 --- a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs +++ b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs @@ -1,15 +1,17 @@ // Doesn't trigger ICE when returning unsized trait that can be impl // issue https://github.com/rust-lang/rust/issues/125512 //@ edition:2021 -#![feature(dyn_compatible_for_dispatch)] + trait B { fn f(a: A) -> A; //~^ ERROR: expected a type, found a trait //~| ERROR: expected a type, found a trait } + trait A { fn concrete(b: B) -> B; //~^ ERROR: expected a type, found a trait //~| ERROR: expected a type, found a trait } + fn main() {} diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr index ac19f91881df..f2942820e288 100644 --- a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr +++ b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr @@ -1,5 +1,5 @@ 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; | ^ @@ -16,7 +16,7 @@ LL | fn concrete(b: impl B) -> B; | ++++ 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; | ^ diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl.rs b/tests/ui/rust-2021/ice-return-unsized-can-impl.rs index 055b11b4424a..8b83b7b537a2 100644 --- a/tests/ui/rust-2021/ice-return-unsized-can-impl.rs +++ b/tests/ui/rust-2021/ice-return-unsized-can-impl.rs @@ -1,7 +1,6 @@ // Doesn't trigger ICE when returning unsized trait that can be impl // issue https://github.com/rust-lang/rust/issues/120482 //@ edition:2021 -#![feature(dyn_compatible_for_dispatch)] trait B { fn bar(&self, x: &Self); diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr b/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr index 463c6892ca26..cfee506e29b7 100644 --- a/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr +++ b/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr @@ -1,5 +1,5 @@ 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; | ^ @@ -16,7 +16,7 @@ LL | fn g(new: impl B) -> B; | ++++ 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; | ^ diff --git a/tests/ui/rust-2021/ice-unsized-fn-params-2.rs b/tests/ui/rust-2021/ice-unsized-fn-params-2.rs index 2b4f7bd088fb..8af56ffe80de 100644 --- a/tests/ui/rust-2021/ice-unsized-fn-params-2.rs +++ b/tests/ui/rust-2021/ice-unsized-fn-params-2.rs @@ -1,7 +1,7 @@ //@ edition:2021 // Test that it doesn't trigger an ICE when using an unsized fn params. // https://github.com/rust-lang/rust/issues/120241 -#![feature(dyn_compatible_for_dispatch)] + #![feature(unsized_fn_params)] fn guard(_s: Copy) -> bool { diff --git a/tests/ui/rust-2021/ice-unsized-fn-params.rs b/tests/ui/rust-2021/ice-unsized-fn-params.rs index 6d8c1c3f152f..6ed67698e96e 100644 --- a/tests/ui/rust-2021/ice-unsized-fn-params.rs +++ b/tests/ui/rust-2021/ice-unsized-fn-params.rs @@ -1,7 +1,6 @@ //@ edition:2021 // Test that it doesn't trigger an ICE when using an unsized fn params. // https://github.com/rust-lang/rust/issues/120241 -#![feature(dyn_compatible_for_dispatch)] trait B { fn f(a: A) -> A; diff --git a/tests/ui/rust-2021/ice-unsized-fn-params.stderr b/tests/ui/rust-2021/ice-unsized-fn-params.stderr index c31500ba8004..4d900711ed6e 100644 --- a/tests/ui/rust-2021/ice-unsized-fn-params.stderr +++ b/tests/ui/rust-2021/ice-unsized-fn-params.stderr @@ -1,5 +1,5 @@ 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; | ^ @@ -16,7 +16,7 @@ LL | fn g(b: impl B) -> B; | ++++ 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; | ^ @@ -27,7 +27,7 @@ LL | fn g(b: B) -> impl B; | ++++ 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; | ^ @@ -44,7 +44,7 @@ LL | fn f(a: impl A) -> A; | ++++ 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; | ^ diff --git a/tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr b/tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr deleted file mode 100644 index d324f4641cf2..000000000000 --- a/tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr +++ /dev/null @@ -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) -> usize; - | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` -... -LL | let x = Rc::new(5usize) as Rc; - | ^^^^^^^^^^^^^^^ `Foo` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18 - | -LL | trait Foo { - | --- this trait is not dyn compatible... -LL | fn foo(self: &Rc) -> 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` to `Rc` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/self/arbitrary-self-types-dyn-incompatible.rs b/tests/ui/self/arbitrary-self-types-dyn-incompatible.rs index 940b2f1e8e2f..0477d9d79c77 100644 --- a/tests/ui/self/arbitrary-self-types-dyn-incompatible.rs +++ b/tests/ui/self/arbitrary-self-types-dyn-incompatible.rs @@ -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; trait Foo { @@ -31,9 +27,8 @@ impl Bar for usize { fn make_foo() { let x = Rc::new(5usize) as Rc; - //[curr]~^ ERROR E0038 - //[curr]~| ERROR E0038 - //[dyn_compatible_for_dispatch]~^^^ ERROR E0038 + //~^ ERROR E0038 + //~| ERROR E0038 } fn make_bar() { diff --git a/tests/ui/self/arbitrary-self-types-dyn-incompatible.stderr b/tests/ui/self/arbitrary-self-types-dyn-incompatible.stderr new file mode 100644 index 000000000000..9fb4c80329d5 --- /dev/null +++ b/tests/ui/self/arbitrary-self-types-dyn-incompatible.stderr @@ -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) -> usize; + | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` +... +LL | let x = Rc::new(5usize) as Rc; + | ^^^^^^^^^^^ `Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:4:18 + | +LL | trait Foo { + | --- this trait is not dyn compatible... +LL | fn foo(self: &Rc) -> 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) -> usize; + | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` +... +LL | let x = Rc::new(5usize) as Rc; + | ^^^^^^^^^^^^^^^ `Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:4:18 + | +LL | trait Foo { + | --- this trait is not dyn compatible... +LL | fn foo(self: &Rc) -> 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` to `Rc` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/suggestions/issue-104328.rs b/tests/ui/suggestions/issue-104328.rs deleted file mode 100644 index 2b0fbdb8d35b..000000000000 --- a/tests/ui/suggestions/issue-104328.rs +++ /dev/null @@ -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 -} diff --git a/tests/ui/suggestions/issue-104328.stderr b/tests/ui/suggestions/issue-104328.stderr deleted file mode 100644 index 3c5e6f16289e..000000000000 --- a/tests/ui/suggestions/issue-104328.stderr +++ /dev/null @@ -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`. diff --git a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs deleted file mode 100644 index 26292a1d218c..000000000000 --- a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs +++ /dev/null @@ -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) {} - -fn main() { - Box::new(S) as Box; //~ ERROR E0038 - let t_box: Box = Box::new(S); //~ ERROR E0038 - takes_box(Box::new(S)); //~ ERROR E0038 -} diff --git a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr deleted file mode 100644 index f3e4f2a63e98..000000000000 --- a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr +++ /dev/null @@ -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 = 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 - --> $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` to `Box` - -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 - --> $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` 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; - | ^^^^^^^^^^^ `Trait` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $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` to `Box` - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs deleted file mode 100644 index ec4bb2897f9d..000000000000 --- a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs +++ /dev/null @@ -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 -} diff --git a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr deleted file mode 100644 index 716d0e78ff11..000000000000 --- a/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr +++ /dev/null @@ -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 - --> $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 - --> $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 - --> $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`. diff --git a/tests/ui/wf/wf-dyn-incompat-trait-obj-match.rs b/tests/ui/wf/wf-dyn-incompat-trait-obj-match.rs deleted file mode 100644 index 6eba6b7abecd..000000000000 --- a/tests/ui/wf/wf-dyn-incompat-trait-obj-match.rs +++ /dev/null @@ -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 - }; -} diff --git a/tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr b/tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr deleted file mode 100644 index a7405ce4caa9..000000000000 --- a/tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr +++ /dev/null @@ -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 - --> $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 - --> $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`.