diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 34a7c3b7c01de..20049d2d9f017 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -319,8 +319,11 @@ fn orphan_check<'tcx>( } // (1) Instantiate all generic params with fresh inference vars. - let infcx = - tcx.infer_ctxt().enable_next_solver_overflow_fcw(false).build(TypingMode::Coherence); + let infcx = tcx + .infer_ctxt() + .with_next_trait_solver(tcx.next_trait_solver_in_coherence()) + .enable_next_solver_overflow_fcw(false) + .build(TypingMode::Coherence); let cause = traits::ObligationCause::dummy(); let args = infcx.fresh_args_for_item(cause.span, impl_def_id.to_def_id()); let trait_ref = trait_ref.instantiate(tcx, args).skip_norm_wip(); diff --git a/tests/crashes/148621.rs b/tests/crashes/148621.rs deleted file mode 100644 index ca0253e488620..0000000000000 --- a/tests/crashes/148621.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ known-bug: #148621 -type Foo = impl std::fmt::Debug; - -trait Identity { - type T; -} - -impl Clone for Foo<<() as Identity>::T> { - fn clone(&self) -> Self { - loop {} - } -} - -fn main() {} diff --git a/tests/crashes/149703.rs b/tests/ui/coherence/const-trait-impl-orphanck.rs similarity index 61% rename from tests/crashes/149703.rs rename to tests/ui/coherence/const-trait-impl-orphanck.rs index 40d78484307a6..eb28f74992927 100644 --- a/tests/crashes/149703.rs +++ b/tests/ui/coherence/const-trait-impl-orphanck.rs @@ -1,4 +1,4 @@ -//@ known-bug: #149703 +//! Regression test for #149703. #![feature(const_trait_impl)] trait Z { type Assoc; @@ -8,5 +8,6 @@ impl Z for T { type Assoc = (); } impl From<::Assoc> for T {} +//~^ ERROR type parameter `T` must be used as an argument to some local type fn main() {} diff --git a/tests/ui/coherence/const-trait-impl-orphanck.stderr b/tests/ui/coherence/const-trait-impl-orphanck.stderr new file mode 100644 index 0000000000000..6dd1d63dc51e8 --- /dev/null +++ b/tests/ui/coherence/const-trait-impl-orphanck.stderr @@ -0,0 +1,12 @@ +error[E0210]: type parameter `T` must be used as an argument to some local type (e.g., `MyStruct`) + --> $DIR/const-trait-impl-orphanck.rs:10:6 + | +LL | impl From<::Assoc> for T {} + | ^ uncovered type parameter + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local + = note: only traits defined in the current crate can be implemented for a type parameter + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0210`. diff --git a/tests/ui/impl-trait/unpin-for-future.stderr b/tests/ui/impl-trait/unpin-for-future.stderr index 22278aa1eb333..379f7f3614b8e 100644 --- a/tests/ui/impl-trait/unpin-for-future.stderr +++ b/tests/ui/impl-trait/unpin-for-future.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Unpin for MyFut {} | ^^^^^^^^^^^^^^^----- | | - | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate + | `MyFut` is not defined in the current crate | = note: impl doesn't have any local type before any uncovered type parameters = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules diff --git a/tests/ui/pin-ergonomics/impl-unpin.tait.stderr b/tests/ui/pin-ergonomics/impl-unpin.tait.stderr index 5d9392745df3d..7fb1c6973834d 100644 --- a/tests/ui/pin-ergonomics/impl-unpin.tait.stderr +++ b/tests/ui/pin-ergonomics/impl-unpin.tait.stderr @@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Unpin for FooAlias {} | ^^^^^^^^^^^^^^^-------- | | - | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate + | `FooAlias` is not defined in the current crate | = note: impl doesn't have any local type before any uncovered type parameters = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules @@ -16,7 +16,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar LL | impl Unpin for BarAlias {} | ^^^^^^^^^^^^^^^-------- | | - | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate + | `BarAlias` is not defined in the current crate | = note: impl doesn't have any local type before any uncovered type parameters = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules diff --git a/tests/ui/type-alias-impl-trait/coherence/coherence.classic.stderr b/tests/ui/type-alias-impl-trait/coherence/coherence.classic.stderr deleted file mode 100644 index e99d4636b1343..0000000000000 --- a/tests/ui/type-alias-impl-trait/coherence/coherence.classic.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence.rs:17:1 - | -LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------- - | | - | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate - | - = note: impl doesn't have any local type before any uncovered type parameters - = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules - = note: define and implement a trait or new type instead - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0117`. diff --git a/tests/ui/type-alias-impl-trait/coherence/coherence.rs b/tests/ui/type-alias-impl-trait/coherence/coherence.rs index eb27c2708042a..7a6ef6c391468 100644 --- a/tests/ui/type-alias-impl-trait/coherence/coherence.rs +++ b/tests/ui/type-alias-impl-trait/coherence/coherence.rs @@ -1,6 +1,4 @@ //@ aux-build:foreign-crate.rs -//@ revisions: classic next -//@[next] compile-flags: -Znext-solver #![feature(type_alias_impl_trait)] extern crate foreign_crate; diff --git a/tests/ui/type-alias-impl-trait/coherence/coherence.next.stderr b/tests/ui/type-alias-impl-trait/coherence/coherence.stderr similarity index 96% rename from tests/ui/type-alias-impl-trait/coherence/coherence.next.stderr rename to tests/ui/type-alias-impl-trait/coherence/coherence.stderr index 6d14594e33a0f..ac763d78ff93d 100644 --- a/tests/ui/type-alias-impl-trait/coherence/coherence.next.stderr +++ b/tests/ui/type-alias-impl-trait/coherence/coherence.stderr @@ -1,5 +1,5 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence.rs:17:1 + --> $DIR/coherence.rs:15:1 | LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------- diff --git a/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.rs b/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.rs new file mode 100644 index 0000000000000..d7d4068bfbb19 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.rs @@ -0,0 +1,17 @@ +// regression test for #148621 +type Foo = impl std::fmt::Debug; //~ ERROR `impl Trait` in type aliases is unstable +//~| ERROR unconstrained opaque type + +trait Identity { + type T; +} + +impl Clone for Foo<<() as Identity>::T> { //~ ERROR type parameter `Q` must be used as an argument to some local type +//~| ERROR the type parameter `Q` is not constrained by the impl trait, self type, or predicates + fn clone(&self) -> Self { + //~^ ERROR the trait bound `(): Identity` is not satisfied + loop {} + } +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.stderr b/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.stderr new file mode 100644 index 0000000000000..7ec550856b712 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/coherence/orphanck-tait-with-projection-arg.stderr @@ -0,0 +1,49 @@ +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/orphanck-tait-with-projection-arg.rs:2:15 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0210]: type parameter `Q` must be used as an argument to some local type (e.g., `MyStruct`) + --> $DIR/orphanck-tait-with-projection-arg.rs:9:6 + | +LL | impl Clone for Foo<<() as Identity>::T> { + | ^ uncovered type parameter + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local + = note: only traits defined in the current crate can be implemented for a type parameter + +error[E0207]: the type parameter `Q` is not constrained by the impl trait, self type, or predicates + --> $DIR/orphanck-tait-with-projection-arg.rs:9:6 + | +LL | impl Clone for Foo<<() as Identity>::T> { + | ^ unconstrained type parameter + +error: unconstrained opaque type + --> $DIR/orphanck-tait-with-projection-arg.rs:2:15 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate + +error[E0277]: the trait bound `(): Identity` is not satisfied + --> $DIR/orphanck-tait-with-projection-arg.rs:11:14 + | +LL | fn clone(&self) -> Self { + | ^^^^^ the trait `Identity` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/orphanck-tait-with-projection-arg.rs:5:1 + | +LL | trait Identity { + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0207, E0210, E0277, E0658. +For more information about an error, try `rustc --explain E0207`.