Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CoerceUnsized and DispatchFromDyn for ManuallyDrop #56193

Open
mikeyhew opened this issue Nov 24, 2018 · 2 comments
Open

Implement CoerceUnsized and DispatchFromDyn for ManuallyDrop #56193

mikeyhew opened this issue Nov 24, 2018 · 2 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@mikeyhew
Copy link
Contributor

Add the following impls:

impl<T: ?Sized, U: ?Sized> CoerceUnsized<ManuallyDrop<T>> for ManuallyDrop<U>
where
    T: CoerceUnsized<U>,
{}

impl<T: ?Sized, U: ?Sized> DispatchFromDyn<ManuallyDrop<T>> for ManuallyDrop<U>
where
    T: DispatchFromDyn<U>,
{}

And add a test case that is allowed by these impls.

This will allow ManuallyDrop<Box<T>> to be unsized to ManuallyDrop<Box<dyn Trait>>, and allow ManuallyDrop<Box<Self>> to be used as a trait-object-safe method receiver with the arbitrary_self_types feature. And similarly for other pointer types besides Box.

Example test case:

trait Trait {
    fn foo(self: ManuallyDrop<Box<Self>>) -> i32;
}

impl Trait for i32 {
    fn foo(self: ManuallyDrop<Box<Self>>) -> i32 {
        self
    }
}

fn main() {
    let x = ManuallyDrop::new(Box::new(5i32)) as ManuallyDrop<Box<dyn Trait>>;
    assert_eq!(x.foo(), 5);
}

This affects stable code, by allowing unsize coercions that were not previously allowed (e.g. from ManuallyDrop<Box<T> to ManuallyDrop<Box<U>> where T: Unsize<U>), so I guess it requires an FCP.

@eddyb
Copy link
Member

eddyb commented Nov 24, 2018

cc @nikomatsakis @alexcrichton

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Nov 25, 2018
@steveklabnik
Copy link
Member

Triage: no idea where this is at today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants