-
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
Type conversions #401
Type conversions #401
Conversation
Casting and coercions. Adds custom DST coercions for smart pointers. Otherwise, mostly descriptive, with a few bits of tidying up.
|
||
* `&mut T` to `&T`; | ||
|
||
* `*mut T` to `*const 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.
Finally! ❤️
Is this the opportunity to discuss possibly allowing numeric types to implicitly coerce when there's no loss of precision, e.g. |
@bstrie I think that is a big enough change that it deserves its own RFC |
``` | ||
|
||
The `Unsize` trait is a marker trait and a lang item. It should not be | ||
implemented by users and user implementations will be ignored. The compiler will |
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 think it would be better to ban such implementations than ignore them.
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.
That is a reasonable alternative. It would require an ad-hoc check in the type checker though
Does this make coercion an special case of casts? Eg, is is true that with the changes every implicit coercion can also be written as an explicit cast? |
Will generic integer literals be covered by this RFC? (Perhaps they aren't technically coercion...) I have a little frustration about generic literals with minus sign: fn main() {
for x in std::iter::range_step(3u32, 0, -1) {
println!("{}", x);
}
} I don't like |
@nodakai fwiw that's unrelated to generics, a plain |
@ben0x539 When you say "generics," you mean the fn main() {
0.f();
}
|
@nodakai Yeah, I thought you were talking about the |
I would like |
Merged. Discussion. Tracking. |
Casting and coercions. Adds custom DST coercions for smart pointers. Otherwise, mostly descriptive, with a few bits of tidying up.
Rendered