From 232d685e6149227abb28c8fef05b00c4f50bbd28 Mon Sep 17 00:00:00 2001 From: whtahy Date: Tue, 18 Apr 2023 21:30:21 -0400 Subject: [PATCH] add known-bug test for unsound issue 57893 --- .../indirect-impl-for-trait-obj-coherence.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/coherence/indirect-impl-for-trait-obj-coherence.rs 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 { + type Output; +} + +impl Object for T { + type Output = U; +} + +fn foo(x: >::Output) -> U { + x +} + +#[allow(dead_code)] +fn transmute(x: T) -> U { + foo::, U>(x) +} + +fn main() {}