diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-1.rs b/src/test/ui/type-alias-impl-trait/issue-90400-1.rs new file mode 100644 index 00000000000..8550a3e8637 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-90400-1.rs @@ -0,0 +1,30 @@ +// Regression test for #90400, +// taken from https://github.com/rust-lang/rust/issues/90400#issuecomment-954927836 + +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +trait Bar { + fn bar(&self); +} + +trait Foo { + type FooFn: FnOnce(); + + fn foo(&self, bar: B) -> Self::FooFn; +} + +struct MyFoo; + +impl Foo for MyFoo { + type FooFn = impl FnOnce(); + + fn foo(&self, bar: B) -> Self::FooFn { + move || bar.bar() //~ ERROR: the trait bound `B: Bar` is not satisfied + } +} + +fn main() { + let boom: ::FooFn = unsafe { core::mem::zeroed() }; + boom(); +} diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr b/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr new file mode 100644 index 00000000000..428a1074031 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `B: Bar` is not satisfied + --> $DIR/issue-90400-1.rs:23:9 + | +LL | move || bar.bar() + | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` + | +note: required by a bound in `::foo` + --> $DIR/issue-90400-1.rs:22:15 + | +LL | fn foo(&self, bar: B) -> Self::FooFn { + | ^^^ required by this bound in `::foo` +help: consider restricting type parameter `B` + | +LL | type FooFn = impl FnOnce(); + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-2.rs b/src/test/ui/type-alias-impl-trait/issue-90400-2.rs new file mode 100644 index 00000000000..2b369bb8a2b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-90400-2.rs @@ -0,0 +1,38 @@ +// Regression test for #90400, +// taken from https://github.com/rust-lang/rust/issues/90400#issuecomment-954927836 + +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +trait Bar { + fn bar(&self); +} + +trait Baz { + fn baz(&self); +} + +trait Foo { + type FooFn: Baz; + + fn foo(&self, bar: B) -> Self::FooFn; +} + +struct MyFoo; +impl Foo for MyFoo { + type FooFn = impl Baz; + + fn foo(&self, bar: B) -> Self::FooFn { + MyBaz(bar) //~ ERROR: the trait bound `B: Bar` is not satisfied + } +} + +struct MyBaz(B); +impl Baz for MyBaz { + fn baz(&self) {} +} + +fn main() { + let boom: ::FooFn = unsafe { core::mem::zeroed() }; + boom.baz(); +} diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr b/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr new file mode 100644 index 00000000000..5da05a4390f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `B: Bar` is not satisfied + --> $DIR/issue-90400-2.rs:26:9 + | +LL | MyBaz(bar) + | ^^^^^^^^^^ the trait `Bar` is not implemented for `B` + | +note: required because of the requirements on the impl of `Baz` for `MyBaz` + --> $DIR/issue-90400-2.rs:31:14 + | +LL | impl Baz for MyBaz { + | ^^^ ^^^^^^^^ +help: consider restricting type parameter `B` + | +LL | type FooFn = impl Baz; + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.