about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-12 15:32:25 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-12 15:32:25 +0000
commitffe543933054a62d4aa8b292513bb1fb5d488188 (patch)
treedffe5cbaf6a4b7ea5d698800b91b5803bc928795
parentbbe9a9c20bac888efae2c7f033fb6cb3925a65b7 (diff)
downloadrust-ffe543933054a62d4aa8b292513bb1fb5d488188.tar.gz
rust-ffe543933054a62d4aa8b292513bb1fb5d488188.zip
Add test for walking order dependent opaque type behaviour
-rw-r--r--tests/ui/impl-trait/associated-type-undefine.rs28
-rw-r--r--tests/ui/impl-trait/associated-type-undefine.stderr20
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/associated-type-undefine.rs b/tests/ui/impl-trait/associated-type-undefine.rs
new file mode 100644
index 00000000000..c8f07021fbf
--- /dev/null
+++ b/tests/ui/impl-trait/associated-type-undefine.rs
@@ -0,0 +1,28 @@
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo: Sized {
+    type Bar;
+    type Gat<T: Foo>;
+    fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>);
+}
+
+impl Foo for u32 {
+    type Bar = ();
+    type Gat<T: Foo> = ();
+    fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
+        ((), ())
+    }
+}
+
+impl Foo for () {
+    type Bar = impl Sized;
+    type Gat<T: Foo> = <T as Foo>::Bar;
+    // Because we encounter `Gat<u32>` first, we never walk into another `Gat`
+    // again, thus missing the opaque type that we could be defining.
+    fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
+        ((), ())
+        //~^ ERROR: mismatched types
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/associated-type-undefine.stderr b/tests/ui/impl-trait/associated-type-undefine.stderr
new file mode 100644
index 00000000000..5d9d525eb93
--- /dev/null
+++ b/tests/ui/impl-trait/associated-type-undefine.stderr
@@ -0,0 +1,20 @@
+error[E0308]: mismatched types
+  --> $DIR/associated-type-undefine.rs:23:14
+   |
+LL |     type Bar = impl Sized;
+   |                ---------- the expected opaque type
+...
+LL |         ((), ())
+   |              ^^ expected opaque type, found `()`
+   |
+   = note: expected opaque type `<() as Foo>::Bar`
+                found unit type `()`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+  --> $DIR/associated-type-undefine.rs:22:8
+   |
+LL |     fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
+   |        ^^^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0308`.