summaryrefslogtreecommitdiff
path: root/tests/ui
diff options
context:
space:
mode:
authorwhtahy <whtahy@users.noreply.github.com>2023-04-18 21:30:21 -0400
committerwhtahy <whtahy@users.noreply.github.com>2023-04-22 00:47:07 -0400
commit232d685e6149227abb28c8fef05b00c4f50bbd28 (patch)
tree9a6c377403f65926398396a6d4f51026cf83b49e /tests/ui
parent2fb20985a000a8f1cd891ef484f7265a55c1612f (diff)
downloadrust-232d685e6149227abb28c8fef05b00c4f50bbd28.tar.gz
add known-bug test for unsound issue 57893
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs b/tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs
new file mode 100644
index 00000000000..bb46498f90e
--- /dev/null
+++ b/tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs
@@ -0,0 +1,25 @@
+// check-pass
+// known-bug: #57893
+
+// Should fail. Because we see an impl that uses a certain associated type, we
+// type-check assuming that impl is used. However, this conflicts with the
+// "implicit impl" that we get for trait objects, violating coherence.
+
+trait Object<U> {
+ type Output;
+}
+
+impl<T: ?Sized, U> Object<U> for T {
+ type Output = U;
+}
+
+fn foo<T: ?Sized, U>(x: <T as Object<U>>::Output) -> U {
+ x
+}
+
+#[allow(dead_code)]
+fn transmute<T, U>(x: T) -> U {
+ foo::<dyn Object<U, Output = T>, U>(x)
+}
+
+fn main() {}