about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-06-15 13:29:13 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-07-05 07:46:05 +0000
commitce3cff47e0216e6fed4fb87e31d9d24307e6c49a (patch)
tree3a122813adbd707a0c5e0a2daecacbd0d0c20470
parent62fbbac2d98eb4cc1804f92a7d31713cd676b497 (diff)
downloadrust-ce3cff47e0216e6fed4fb87e31d9d24307e6c49a.tar.gz
rust-ce3cff47e0216e6fed4fb87e31d9d24307e6c49a.zip
Add more tests
-rw-r--r--tests/ui/object-safety/assoc_type_bounds_sized.rs13
-rw-r--r--tests/ui/object-safety/assoc_type_bounds_sized_others.rs25
-rw-r--r--tests/ui/object-safety/assoc_type_bounds_sized_others.stderr21
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/ui/object-safety/assoc_type_bounds_sized.rs b/tests/ui/object-safety/assoc_type_bounds_sized.rs
index 546cde37f63..6d10ceeb1b4 100644
--- a/tests/ui/object-safety/assoc_type_bounds_sized.rs
+++ b/tests/ui/object-safety/assoc_type_bounds_sized.rs
@@ -1,3 +1,6 @@
+//! This test checks that associated types only need to be
+//! mentioned in trait objects, if they don't require `Self: Sized`.
+
 // check-pass
 
 trait Foo {
@@ -8,4 +11,14 @@ trait Foo {
 
 fn foo(_: &dyn Foo) {}
 
+trait Other: Sized {}
+
+trait Boo {
+    type Assoc
+    where
+        Self: Other;
+}
+
+fn boo(_: &dyn Boo) {}
+
 fn main() {}
diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_others.rs b/tests/ui/object-safety/assoc_type_bounds_sized_others.rs
new file mode 100644
index 00000000000..647b72a759f
--- /dev/null
+++ b/tests/ui/object-safety/assoc_type_bounds_sized_others.rs
@@ -0,0 +1,25 @@
+//! This test checks that even if some associated types have
+//! `where Self: Sized` bounds, those without still need to be
+//! mentioned in trait objects.
+
+trait Foo {
+    type Bar
+    where
+        Self: Sized;
+    type Bop;
+}
+
+fn foo(_: &dyn Foo) {}
+//~^ ERROR the value of the associated type `Bop` (from trait `Foo`) must be specified
+
+trait Bar {
+    type Bop;
+    type Bar
+    where
+        Self: Sized;
+}
+
+fn bar(_: &dyn Bar) {}
+//~^ ERROR the value of the associated type `Bop` (from trait `Bar`) must be specified
+
+fn main() {}
diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_others.stderr b/tests/ui/object-safety/assoc_type_bounds_sized_others.stderr
new file mode 100644
index 00000000000..e4c44334b34
--- /dev/null
+++ b/tests/ui/object-safety/assoc_type_bounds_sized_others.stderr
@@ -0,0 +1,21 @@
+error[E0191]: the value of the associated type `Bop` (from trait `Foo`) must be specified
+  --> $DIR/assoc_type_bounds_sized_others.rs:12:16
+   |
+LL |     type Bop;
+   |     -------- `Bop` defined here
+...
+LL | fn foo(_: &dyn Foo) {}
+   |                ^^^ help: specify the associated type: `Foo<Bop = Type>`
+
+error[E0191]: the value of the associated type `Bop` (from trait `Bar`) must be specified
+  --> $DIR/assoc_type_bounds_sized_others.rs:22:16
+   |
+LL |     type Bop;
+   |     -------- `Bop` defined here
+...
+LL | fn bar(_: &dyn Bar) {}
+   |                ^^^ help: specify the associated type: `Bar<Bop = Type>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0191`.