-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
DST custom coercions. #982
Conversation
|
||
* If the impl is for a built-in pointer type, we check nothing, otherwise... | ||
* The compiler checks that the `Self` type is a struct or tuple struct and that | ||
the `Target` type is a simple substitution of type parameters from the `Self` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite know what "simple substitution of type parameters" means... but I think we want to check that both of them are applications of the same base type constructor. e.g. Foo<X>
and Foo<Y>
are ok, but not Foo<X>
and Bar<Y>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that there exists some Ts
(where Ts
= a sequence of T
) and some Xs
such that Target = [Ts/Xs]Self
and Self
is not in Xs
. Which I think subsumes your requirement, but also precludes some pathalogical cases such as Target = Foo<T1, T2>
, Self = Foo<X, X>
.
I read over the revised version -- it seems pretty good to me, I left a few comments. |
|
||
``` | ||
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {} | ||
impl<T: ?Sized+CoerceUnsized<U>, U: ?Sized> NonZero<U> for NonZero<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be implementing CoerceUnsized<NonZero<U>>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
I do, I had forgotten this was not merged yet. |
Hear ye, hear ye. This RFC is now in final comment period until June 2nd. |
This RFC has been accepted. It is not yet merged to allow @nrc to incorporate final comments reflecting the current design. (It has been partially implemented in the meantime.) -- Language design subteam |
Custom coercions allow smart pointers to fully participate in the DST system. In particular, they allow practical use of `Rc<T>` and `Arc<T>` where `T` is unsized. This RFC subsumes part of [RFC 401 coercions](https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md).
@nikomatsakis updated |
Merged. Tracking issue is rust-lang/rust#18598 |
Custom coercions allow smart pointers to fully participate in the DST system.
In particular, they allow practical use of
Rc<T>
andArc<T>
whereT
is unsized.This RFC subsumes part of RFC 401 coercions.
Rendered
[edited to add rendered link]