forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#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 rust-lang#135155 cc ``@adetaylor``
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |