diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-02-23 13:14:59 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-03-28 17:08:50 +0000 |
| commit | dc35d584a971e9a2d7a0c54be6abac779f2bf9b5 (patch) | |
| tree | 23cfdabec7e57d087f4d032b16d6eafe0360b662 | |
| parent | e82b0cde4ef5c8f7dfd451eb8ea1c57d4c153bf8 (diff) | |
| download | rust-dc35d584a971e9a2d7a0c54be6abac779f2bf9b5.tar.gz rust-dc35d584a971e9a2d7a0c54be6abac779f2bf9b5.zip | |
Show that the behaviour is the same for RPIT and TAIT
9 files changed, 230 insertions, 0 deletions
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.rs b/src/test/ui/impl-trait/nested-return-type2-tait.rs new file mode 100644 index 00000000000..f2217f699fb --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait.rs @@ -0,0 +1,32 @@ +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +// the fact that `R` is the `::Output` projection on `F` causes +// an intermediate inference var to be generated which is then later +// compared against the actually found `Assoc` type. +impl<R: Duh, F: FnMut() -> R> Trait for F { + type Assoc = R; +} + +type Sendable = impl Send; + +// The `Sendable` here is then later compared against the inference var +// created, causing the inference var to be set to `Sendable` instead of +// the hidden type. We already have obligations registered on the inference +// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque +// type does not implement `Duh`, even if its hidden type does. So we error out. +fn foo() -> impl Trait<Assoc = Sendable> { + //~^ ERROR `Sendable: Duh` is not satisfied + //~| ERROR `Sendable: Duh` is not satisfied + || 42 +} + +fn main() { +} diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.stderr b/src/test/ui/impl-trait/nested-return-type2-tait.stderr new file mode 100644 index 00000000000..776c06b20df --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait.stderr @@ -0,0 +1,32 @@ +error[E0277]: the trait bound `Sendable: Duh` is not satisfied + --> $DIR/nested-return-type2-tait.rs:25:13 + | +LL | fn foo() -> impl Trait<Assoc = Sendable> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Duh` is not implemented for `Sendable` + | +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait.rs:28:5: 28:10]` + --> $DIR/nested-return-type2-tait.rs:14:31 + | +LL | impl<R: Duh, F: FnMut() -> R> Trait for F { + | ^^^^^ ^ + +error[E0277]: the trait bound `Sendable: Duh` is not satisfied + --> $DIR/nested-return-type2-tait.rs:25:42 + | +LL | fn foo() -> impl Trait<Assoc = Sendable> { + | __________________________________________^ +LL | | +LL | | +LL | | || 42 +LL | | } + | |_^ the trait `Duh` is not implemented for `Sendable` + | +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait.rs:28:5: 28:10]` + --> $DIR/nested-return-type2-tait.rs:14:31 + | +LL | impl<R: Duh, F: FnMut() -> R> Trait for F { + | ^^^^^ ^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.rs b/src/test/ui/impl-trait/nested-return-type2-tait2.rs new file mode 100644 index 00000000000..af8e0663054 --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait2.rs @@ -0,0 +1,32 @@ +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +// the fact that `R` is the `::Output` projection on `F` causes +// an intermediate inference var to be generated which is then later +// compared against the actually found `Assoc` type. +impl<R: Duh, F: FnMut() -> R> Trait for F { + type Assoc = R; +} + +type Sendable = impl Send; +type Traitable = impl Trait<Assoc = Sendable>; + +// The `impl Send` here is then later compared against the inference var +// created, causing the inference var to be set to `impl Send` instead of +// the hidden type. We already have obligations registered on the inference +// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque +// type does not implement `Duh`, even if its hidden type does. So we error out. +fn foo() -> Traitable { + || 42 + //~^ ERROR `Sendable: Duh` is not satisfied +} + +fn main() { +} diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.stderr b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr new file mode 100644 index 00000000000..4993202e253 --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `Sendable: Duh` is not satisfied + --> $DIR/nested-return-type2-tait2.rs:27:5 + | +LL | || 42 + | ^^^^^ the trait `Duh` is not implemented for `Sendable` + | +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:10]` + --> $DIR/nested-return-type2-tait2.rs:14:31 + | +LL | impl<R: Duh, F: FnMut() -> R> Trait for F { + | ^^^^^ ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.rs b/src/test/ui/impl-trait/nested-return-type2-tait3.rs new file mode 100644 index 00000000000..74fd8a9dda0 --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait3.rs @@ -0,0 +1,31 @@ +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +// the fact that `R` is the `::Output` projection on `F` causes +// an intermediate inference var to be generated which is then later +// compared against the actually found `Assoc` type. +impl<R: Duh, F: FnMut() -> R> Trait for F { + type Assoc = R; +} + +type Traitable = impl Trait<Assoc = impl Send>; + +// The `impl Send` here is then later compared against the inference var +// created, causing the inference var to be set to `impl Send` instead of +// the hidden type. We already have obligations registered on the inference +// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque +// type does not implement `Duh`, even if its hidden type does. So we error out. +fn foo() -> Traitable { + || 42 + //~^ ERROR `impl Send: Duh` is not satisfied +} + +fn main() { +} diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.stderr b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr new file mode 100644 index 00000000000..efeaf059a3b --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `impl Send: Duh` is not satisfied + --> $DIR/nested-return-type2-tait3.rs:26:5 + | +LL | || 42 + | ^^^^^ the trait `Duh` is not implemented for `impl Send` + | +note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:10]` + --> $DIR/nested-return-type2-tait3.rs:14:31 + | +LL | impl<R: Duh, F: FnMut() -> R> Trait for F { + | ^^^^^ ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/impl-trait/nested-return-type3-tait.rs b/src/test/ui/impl-trait/nested-return-type3-tait.rs new file mode 100644 index 00000000000..3936f4dbbb4 --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type3-tait.rs @@ -0,0 +1,24 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +impl<F: Duh> Trait for F { + type Assoc = F; +} + +type Sendable = impl Send; + +fn foo() -> impl Trait<Assoc = Sendable> { + 42 +} + +fn main() { +} diff --git a/src/test/ui/impl-trait/nested-return-type3-tait2.rs b/src/test/ui/impl-trait/nested-return-type3-tait2.rs new file mode 100644 index 00000000000..56778ed90dc --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type3-tait2.rs @@ -0,0 +1,25 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +impl<F: Duh> Trait for F { + type Assoc = F; +} + +type Sendable = impl Send; +type Traitable = impl Trait<Assoc = Sendable>; + +fn foo() -> Traitable { + 42 +} + +fn main() { +} diff --git a/src/test/ui/impl-trait/nested-return-type3-tait3.rs b/src/test/ui/impl-trait/nested-return-type3-tait3.rs new file mode 100644 index 00000000000..04c6c92b1a3 --- /dev/null +++ b/src/test/ui/impl-trait/nested-return-type3-tait3.rs @@ -0,0 +1,24 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +trait Duh {} + +impl Duh for i32 {} + +trait Trait { + type Assoc: Duh; +} + +impl<F: Duh> Trait for F { + type Assoc = F; +} + +type Traitable = impl Trait<Assoc = impl Send>; + +fn foo() -> Traitable { + 42 +} + +fn main() { +} |
