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 for Unique<T> #1343

Closed
rphmeier opened this issue Oct 29, 2015 · 1 comment
Closed

Implement CoerceUnsized for Unique<T> #1343

rphmeier opened this issue Oct 29, 2015 · 1 comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@rphmeier
Copy link

It's implemented for raw pointers, references, boxes, Rc, Arc, NonZero, and Shared. Is there a specific reason it can't be implemented for Unique?

As it stands, you can't actually reimplement something like Box the same way the standard library does. Somehow, even though a Box is just a wrapper around Unique, it can be coerced to an unsized type due to some compiler magic.

The following is paraphrased from the Box source, but does not compile:

use std::marker::Unsize;
use std::ops::CoerceUnsized;
use std::ptr::Unique;

pub struct MyBox<T: ?Sized>(Unique<T>);

impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<MyBox<U>> for MyBox<T> {}

fn main() { }
@apasel422
Copy link
Contributor

This should be easy to implement now. I think it was previously blocked on #1234.

bors added a commit to rust-lang/rust that referenced this issue Oct 30, 2015
bors added a commit to rust-lang/rust that referenced this issue Oct 31, 2015
@Centril Centril added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants