-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make all coercion valid casts and add trivial cast lints #23630
Conversation
@@ -23,6 +23,8 @@ | |||
html_root_url = "http://doc.rust-lang.org/nightly/", | |||
html_playground_url = "http://play.rust-lang.org/")] | |||
|
|||
#![allow(trivial_cast)] | |||
#![allow(trivial_numeric_cast)] |
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.
The lint names don't follow the conventions. trivial_cast
-> trivial_casts
, trivial_numeric_cast
-> trivial_numeric_casts
?
This seems to not interfere too much with my own DST branch (where I did a similar change to coercions to have both |
I'm wondering if we want the lints to default to warn, in the absence of type ascription? I guess it is very rare to need to convert to a trait object, and one can typically use an intermediate variable, and that seems like the only case where one might require a cast today (other than the trivial numeric case, which is already separated). I agree that the lint names seem wrong. |
Yeah, should be |
Type ascription doesn't let you do any more, it is just more convenient, given there's an implementation that just needs rebasing and an accepted RFC, I would expect it to land very soon in any case. |
r+ |
@bors r=nikomatsakis c2fde5a |
🙀 |
@bors: try |
⌛ Trying commit c4f3029 with merge d8f41c5... |
💔 Test failed - try-bsd |
@bors: try |
⌛ Trying commit 48287fe with merge 31738c0... |
💔 Test failed - try-mac |
@bors: try |
⌛ Trying commit fc7e9b3 with merge 8381980... |
💔 Test failed - try-win-64 |
@bors: try |
⌛ Trying commit 7315e0a with merge 2782e72... |
💔 Test failed - try-win-64 |
@bors: try |
See notes on the first commit Closes #18601 r? @nikomatsakis cc @eddyb
💔 Test failed - try-mac |
@bors: try |
@bors retry |
⌛ Trying commit a7b6af9 with merge 3f8058d... |
☔ The latest upstream changes (presumably #23654) made this pull request unmergeable. Please resolve the merge conflicts. |
This permits all coercions to be performed in casts, but adds lints to warn in those cases. Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference. [breaking change] * Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed. * The unused casts lint has gone. * Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are: - You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_` - Casts do not influence inference of integer types. E.g., the following used to type check: ``` let x = 42; let y = &x as *const u32; ``` Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information: ``` let x: u32 = 42; let y = &x as *const u32; ```
See notes on the first commit Closes rust-lang#18601 r? @nikomatsakis cc @eddyb
@nrc how would you feel about making the |
I just filed #23739 requesting that |
Ah, breaking change needs to be exactly |
See notes on the first commit
Closes #18601
r? @nikomatsakis
cc @eddyb