about summary refs log tree commit diff
path: root/src/test/ui/impl-trait
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-01-26 17:20:48 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-02-02 15:40:11 +0000
commit5a374dc813c8c6a1d10b3c6cc7fdeaa9aafbcc65 (patch)
tree886688e9b1f1a0ccea355e4dbb7336f584659a64 /src/test/ui/impl-trait
parentcbfd7362924a97caef6e29dd5db7569764c8d507 (diff)
downloadrust-5a374dc813c8c6a1d10b3c6cc7fdeaa9aafbcc65.tar.gz
rust-5a374dc813c8c6a1d10b3c6cc7fdeaa9aafbcc65.zip
Add some tests to show what happens when you compare two opaque types that are both within the defining scope
Diffstat (limited to 'src/test/ui/impl-trait')
-rw-r--r--src/test/ui/impl-trait/two_tait_defining_each_other.rs20
-rw-r--r--src/test/ui/impl-trait/two_tait_defining_each_other2.rs16
-rw-r--r--src/test/ui/impl-trait/two_tait_defining_each_other2.stderr8
-rw-r--r--src/test/ui/impl-trait/two_tait_defining_each_other3.rs20
4 files changed, 64 insertions, 0 deletions
diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other.rs b/src/test/ui/impl-trait/two_tait_defining_each_other.rs
new file mode 100644
index 00000000000..eb8d24832eb
--- /dev/null
+++ b/src/test/ui/impl-trait/two_tait_defining_each_other.rs
@@ -0,0 +1,20 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+type A = impl Foo;
+type B = impl Foo;
+
+trait Foo {}
+
+fn muh(x: A) -> B {
+    if false {
+        return Bar; // B's hidden type is Bar
+    }
+    x // A's hidden type is `Bar`, because all the hidden types of `B` are compared with each other
+}
+
+struct Bar;
+impl Foo for Bar {}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other2.rs b/src/test/ui/impl-trait/two_tait_defining_each_other2.rs
new file mode 100644
index 00000000000..88a76089b82
--- /dev/null
+++ b/src/test/ui/impl-trait/two_tait_defining_each_other2.rs
@@ -0,0 +1,16 @@
+#![feature(type_alias_impl_trait)]
+
+type A = impl Foo;
+//~^ ERROR could not find defining uses
+type B = impl Foo;
+
+trait Foo {}
+
+fn muh(x: A) -> B {
+    x // B's hidden type is A (opaquely)
+}
+
+struct Bar;
+impl Foo for Bar {}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr b/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr
new file mode 100644
index 00000000000..5a0cff527b6
--- /dev/null
+++ b/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr
@@ -0,0 +1,8 @@
+error: could not find defining uses
+  --> $DIR/two_tait_defining_each_other2.rs:3:10
+   |
+LL | type A = impl Foo;
+   |          ^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other3.rs b/src/test/ui/impl-trait/two_tait_defining_each_other3.rs
new file mode 100644
index 00000000000..c289b43c425
--- /dev/null
+++ b/src/test/ui/impl-trait/two_tait_defining_each_other3.rs
@@ -0,0 +1,20 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+type A = impl Foo;
+type B = impl Foo;
+
+trait Foo {}
+
+fn muh(x: A) -> B {
+    if false {
+        return x;  // B's hidden type is A (opaquely)
+    }
+    Bar // A's hidden type is `Bar`, because all the return types are compared with each other
+}
+
+struct Bar;
+impl Foo for Bar {}
+
+fn main() {}