about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-10-10 10:23:05 +0900
committerGitHub <noreply@github.com>2022-10-10 10:23:05 +0900
commita4e55772625722721d50414f1dcc3388463dbcb6 (patch)
treecb91f12f6a94784d821866731d83e54f3e7f259a /src/test
parent303ebd5b0400073a82d68053fc789de72dabe2b5 (diff)
parentf5fd66e0c208262fc493175a63f6d2f41130ed8c (diff)
Rollup merge of #102845 - cjgillot:gat-object, r=fee1-dead
Elaborate trait ref to compute object safety.

instead of building them manually from supertraits and associated items.

This allows to have the correct substs for GATs.

Fixes https://github.com/rust-lang/rust/issues/102751
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs15
-rw-r--r--src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr43
2 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs
new file mode 100644
index 00000000000..14e00d2ef32
--- /dev/null
+++ b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs
@@ -0,0 +1,15 @@
+//~ ERROR the parameter type `Self` may not live long enough
+
+trait GatTrait {
+    type Gat<'a>
+    where
+        Self: 'a;
+}
+
+trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+    fn c(&self) -> dyn SuperTrait<T>;
+    //~^ ERROR associated item referring to unboxed trait object for its own trait
+    //~| ERROR the trait `SuperTrait` cannot be made into an object
+}
+
+fn main() {}
diff --git a/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr
new file mode 100644
index 00000000000..c1aaad31e81
--- /dev/null
+++ b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr
@@ -0,0 +1,43 @@
+error[E0311]: the parameter type `Self` may not live long enough
+   |
+   = help: consider adding an explicit lifetime bound `Self: 'a`...
+   = note: ...so that the type `Self` will meet its required lifetime bounds...
+note: ...that is required by this bound
+  --> $DIR/object-safety-supertrait-mentions-GAT.rs:9:39
+   |
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+   |                                       ^^^^^^^^^^^
+
+error: associated item referring to unboxed trait object for its own trait
+  --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
+   |
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+   |       ---------- in this trait
+LL |     fn c(&self) -> dyn SuperTrait<T>;
+   |                    ^^^^^^^^^^^^^^^^^
+   |
+help: you might have meant to use `Self` to refer to the implementing type
+   |
+LL |     fn c(&self) -> Self;
+   |                    ~~~~
+
+error[E0038]: the trait `SuperTrait` cannot be made into an object
+  --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
+   |
+LL |     fn c(&self) -> dyn SuperTrait<T>;
+   |                    ^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
+   |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+  --> $DIR/object-safety-supertrait-mentions-GAT.rs:4:10
+   |
+LL |     type Gat<'a>
+   |          ^^^ ...because it contains the generic associated type `Gat`
+...
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+   |       ---------- this trait cannot be made into an object...
+   = help: consider moving `Gat` to another trait
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0038, E0311.
+For more information about an error, try `rustc --explain E0038`.