-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 {Cell, RefCell, UnsafeCell}
#35627
Conversation
LGTM. cc @rust-lang/lang Do we want such impls? While the feature is unstable, they would be usable in coercions from stable code. |
Would it be possible to add a few tests to the repo as well ensuring that we don't regress this functionality? |
@alexcrichton Done. |
Thanks! I think though that libcore doesn't actually have tests run, so could they be moved to libcoretest? |
@alexcrichton They're not actually tests -- they'll cause compilation to fail if we regress the functionality. This is similar to other assertions that types are covariant or |
Oh gah, right! Carry on! |
Usually, I'd be cautious about impls that let us skirt stability, but the DST coercions have been around for ages and I don't think there are problems with them, but we could do with more testing, so maybe this would help that? |
☔ The latest upstream changes (presumably #35666) made this pull request unmergeable. Please resolve the merge conflicts. |
I don't know that these impls make sense for
|
I guess you could copy things in and out if you permitted dynamically sized stack frames (as I sort of want to permit now, in order to generally loosen the rules on DST). But no reason to jump the gun there. :) |
@nikomatsakis See the link in my original post for an example of where this is useful for |
@nikomatsakis What's being added here is the ability to coerce More concretely, |
Ah, right, thanks for the correction. =) In that case, I have no objection. It is sort of nifty that this works. Seems like it'd be a variance error, but since there's no aliasing... |
Discussed during @rust-lang/libs triage discussion was also that this is good to merge, thanks @apasel422! @bors: r+ |
📌 Commit 1fd791a has been approved by |
⌛ Testing commit 1fd791a with merge 43204ff... |
Implement `CoerceUnsized` for `{Cell, RefCell, UnsafeCell}` These impls are analogous to the one for `NonZero`. It's occasionally useful to be able to coerce the cell types when they're being used inside another abstraction. See Manishearth/rust-gc#17 for an example. r? @eddyb
These impls are analogous to the one for
NonZero
. It's occasionally useful to be able to coerce the cell types when they're being used inside another abstraction. See Manishearth/rust-gc#17 for an example.r? @eddyb