diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-05-23 15:11:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-23 15:11:05 +0200 |
| commit | cf7e3969cd816782111d6ec24e50376e6a8ffcd6 (patch) | |
| tree | 5ec45afb66a60a896fa8d89a5672f2b78643ef32 | |
| parent | f4bf64c3f0c82cbae2844ffc6f1a01b5e18ffe73 (diff) | |
| parent | 622244ac5832dbb2ab1e4f43ea8f1c33b6b01b3c (diff) | |
| download | rust-cf7e3969cd816782111d6ec24e50376e6a8ffcd6.tar.gz rust-cf7e3969cd816782111d6ec24e50376e6a8ffcd6.zip | |
Rollup merge of #97309 - JohnTitor:issue-90400, r=compiler-errors
Add some regression tests for #90400 This adds two regression tests taken from https://github.com/rust-lang/rust/issues/90400#issuecomment-954927836. Note that we cannot close the issue right now as the [original code](https://github.com/rust-lang/rust/issues/90400#issue-1039577786) still triggers an ICE. r? `@compiler-errors`
4 files changed, 106 insertions, 0 deletions
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<B>: FnOnce(); + + fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B>; +} + +struct MyFoo; + +impl Foo for MyFoo { + type FooFn<B> = impl FnOnce(); + + fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B> { + move || bar.bar() //~ ERROR: the trait bound `B: Bar` is not satisfied + } +} + +fn main() { + let boom: <MyFoo as Foo>::FooFn<u32> = 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 `<MyFoo as Foo>::foo` + --> $DIR/issue-90400-1.rs:22:15 + | +LL | fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B> { + | ^^^ required by this bound in `<MyFoo as Foo>::foo` +help: consider restricting type parameter `B` + | +LL | type FooFn<B: Bar> = 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<B>: Baz; + + fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B>; +} + +struct MyFoo; +impl Foo for MyFoo { + type FooFn<B> = impl Baz; + + fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B> { + MyBaz(bar) //~ ERROR: the trait bound `B: Bar` is not satisfied + } +} + +struct MyBaz<B: Bar>(B); +impl<B: Bar> Baz for MyBaz<B> { + fn baz(&self) {} +} + +fn main() { + let boom: <MyFoo as Foo>::FooFn<u32> = 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<B>` + --> $DIR/issue-90400-2.rs:31:14 + | +LL | impl<B: Bar> Baz for MyBaz<B> { + | ^^^ ^^^^^^^^ +help: consider restricting type parameter `B` + | +LL | type FooFn<B: Bar> = impl Baz; + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |
