about summary refs log tree commit diff
path: root/tests/ui/self
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-03-12 08:06:47 +0100
committerGitHub <noreply@github.com>2025-03-12 08:06:47 +0100
commit143eb4f03eabc7543095b7d6827e62f1de1b0284 (patch)
treede7dc29da48e24507f6abbee3c6af8eef64dec18 /tests/ui/self
parent4198902e9a7648e4445ab73fdc129231afc33b40 (diff)
parentc170d0f12fa9866d39190bc70c8df614083c3d5a (diff)
downloadrust-143eb4f03eabc7543095b7d6827e62f1de1b0284.tar.gz
rust-143eb4f03eabc7543095b7d6827e62f1de1b0284.zip
Rollup merge of #138174 - compiler-errors:elaborate-unsize-self-pred, r=BoxyUwU
Elaborate trait assumption in `receiver_is_dispatchable`

Fixes #138172. See comment on the linked test.

Probably not a fix for the general problem, bc I think this may still be incomplete for other weird `where` clauses on the receiver. But 🤷, supertraits seems like an obvious one to fix.
Diffstat (limited to 'tests/ui/self')
-rw-r--r--tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs38
-rw-r--r--tests/ui/self/dyn-dispatch-requires-supertrait.rs38
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs
new file mode 100644
index 00000000000..55c070eb036
--- /dev/null
+++ b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs
@@ -0,0 +1,38 @@
+//@ check-pass
+
+#![feature(derive_coerce_pointee)]
+#![feature(arbitrary_self_types)]
+
+use std::ops::Deref;
+use std::marker::CoercePointee;
+use std::sync::Arc;
+
+trait MyTrait<T> {}
+
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct MyArc<T: ?Sized + MyTrait<u8>>(Arc<T>);
+
+impl<T: ?Sized + MyTrait<u8>> Deref for MyArc<T> {
+    type Target = T;
+    fn deref(&self) -> &T {
+        &self.0
+    }
+}
+
+trait Mirror {
+    type Assoc;
+}
+impl<T> Mirror for T {
+    type Assoc = T;
+}
+
+// This is variant on "tests/ui/self/dyn-dispatch-requires-supertrait.rs" but with
+// a supertrait that requires normalization to match the pred in the old solver.
+trait MyOtherTrait: MyTrait<<u8 as Mirror>::Assoc> {
+    fn foo(self: MyArc<Self>);
+}
+
+fn test(_: MyArc<dyn MyOtherTrait>) {}
+
+fn main() {}
diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait.rs b/tests/ui/self/dyn-dispatch-requires-supertrait.rs
new file mode 100644
index 00000000000..f2661c406fe
--- /dev/null
+++ b/tests/ui/self/dyn-dispatch-requires-supertrait.rs
@@ -0,0 +1,38 @@
+//@ check-pass
+
+#![feature(derive_coerce_pointee)]
+#![feature(arbitrary_self_types)]
+
+use std::ops::Deref;
+use std::marker::CoercePointee;
+use std::sync::Arc;
+
+trait MyTrait {}
+
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct MyArc<T>
+where
+    T: MyTrait + ?Sized,
+{
+    inner: Arc<T>
+}
+
+impl<T: MyTrait + ?Sized> Deref for MyArc<T> {
+    type Target = T;
+    fn deref(&self) -> &T {
+        &self.inner
+    }
+}
+
+// Proving that `MyArc<Self>` is dyn-dispatchable requires proving `MyArc<T>` implements
+// `DispatchFromDyn<MyArc<U>>`. The `DispatchFromDyn` impl that is generated from the
+// `CoercePointee` implementation requires the pointee impls `MyTrait`, but previously we
+// were only assuming the pointee impl'd `MyOtherTrait`. Elaboration comes to the rescue here.
+trait MyOtherTrait: MyTrait {
+    fn foo(self: MyArc<Self>);
+}
+
+fn test(_: MyArc<dyn MyOtherTrait>) {}
+
+fn main() {}