From 8ca7aac3eb51e4ca3a3ae48659f88e8f3dea380b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 10:28:52 -0400 Subject: [PATCH] Add tests for shortcomings of associated type bounds --- .../cant-see-copy-bound-from-child-rigid-2.rs | 18 ++++++++++++++++++ ...nt-see-copy-bound-from-child-rigid-2.stderr | 13 +++++++++++++ .../cant-see-copy-bound-from-child-rigid.rs | 18 ++++++++++++++++++ ...cant-see-copy-bound-from-child-rigid.stderr | 14 ++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs create mode 100644 tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr create mode 100644 tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs create mode 100644 tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs new file mode 100644 index 0000000000000..1768b006622e2 --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs @@ -0,0 +1,18 @@ +trait Id { + type This: ?Sized; +} +impl Id for T { + type This = T; +} + +trait Trait { + type Assoc: Id; +} + +// We can't see use the `T::Assoc::This: Copy` bound to prove `T::Assoc: Copy` +fn foo(x: T::Assoc) -> (T::Assoc, T::Assoc) { + (x, x) + //~^ ERROR use of moved value +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr new file mode 100644 index 0000000000000..cd0e026905c9a --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr @@ -0,0 +1,13 @@ +error[E0382]: use of moved value: `x` + --> $DIR/cant-see-copy-bound-from-child-rigid-2.rs:14:9 + | +LL | fn foo(x: T::Assoc) -> (T::Assoc, T::Assoc) { + | - move occurs because `x` has type `::Assoc`, which does not implement the `Copy` trait +LL | (x, x) + | - ^ value used here after move + | | + | value moved here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs new file mode 100644 index 0000000000000..6b3fd7e898d18 --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs @@ -0,0 +1,18 @@ +trait Id { + type This: ?Sized; +} + +trait Trait { + type Assoc: Id; +} + +// We can't see use the `T::Assoc::This: Copy` bound to prove `T::Assoc: Copy` +fn foo(x: T::Assoc) -> (T::Assoc, T::Assoc) +where + T::Assoc: Id, +{ + (x, x) + //~^ ERROR use of moved value +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr new file mode 100644 index 0000000000000..3ed73918de313 --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr @@ -0,0 +1,14 @@ +error[E0382]: use of moved value: `x` + --> $DIR/cant-see-copy-bound-from-child-rigid.rs:14:9 + | +LL | fn foo(x: T::Assoc) -> (T::Assoc, T::Assoc) + | - move occurs because `x` has type `::Assoc`, which does not implement the `Copy` trait +... +LL | (x, x) + | - ^ value used here after move + | | + | value moved here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`.