diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-07 21:30:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-07 21:30:59 +0100 |
| commit | c49fc911f451b6e27dcd7fbfac77ab2902fd3ae5 (patch) | |
| tree | eb6bbc0989ed43a212b2a8af8fb189ad6858db8f /tests/ui/self | |
| parent | 64e06c0f5578829373743884b708d494136c3e8f (diff) | |
| parent | 999695bab9779db8b9c6dc5fc2135777562eae47 (diff) | |
| download | rust-c49fc911f451b6e27dcd7fbfac77ab2902fd3ae5.tar.gz rust-c49fc911f451b6e27dcd7fbfac77ab2902fd3ae5.zip | |
Rollup merge of #135179 - compiler-errors:arbitrary-self-types-object, r=BoxyUwU
Make sure to use `Receiver` trait when extracting object method candidate In method confirmation, the `extract_existential_trait_ref` function re-extracts the object type by derefing until it reaches an object. If we're assembling methods via the `Receiver` trait, make sure we re-do our work also using the receiver trait. Fixes #135155 cc ``@adetaylor``
Diffstat (limited to 'tests/ui/self')
| -rw-r--r-- | tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs b/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs new file mode 100644 index 00000000000..f9e346ea11e --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs @@ -0,0 +1,33 @@ +//@ check-pass + +#![feature(derive_coerce_pointee)] +#![feature(arbitrary_self_types)] + +use std::marker::CoercePointee; +use std::ops::Receiver; + +// `CoercePointee` isn't needed here, it's just a simpler +// (and more conceptual) way of deriving `DispatchFromDyn`. +// You could think of `MyDispatcher` as a smart pointer +// that just doesn't deref to its target type. +#[derive(CoercePointee)] +#[repr(transparent)] +struct MyDispatcher<T: ?Sized>(*const T); + +impl<T: ?Sized> Receiver for MyDispatcher<T> { + type Target = T; +} +struct Test; + +trait Trait { + fn test(self: MyDispatcher<Self>); +} + +impl Trait for Test { + fn test(self: MyDispatcher<Self>) { + todo!() + } +} +fn main() { + MyDispatcher::<dyn Trait>(core::ptr::null_mut::<Test>()).test(); +} |
