Uh oh!
There was an error while loading. Please reload this page.
Make all coercion valid casts and add trivial cast lints - #23630
Conversation
There was a problem hiding this comment.
The lint names don't follow the conventions. trivial_cast -> trivial_casts, trivial_numeric_cast -> trivial_numeric_casts?
eddyb
commented
Mar 23, 2015
This seems to not interfere too much with my own DST branch (where I did a similar change to coercions to have both |
nikomatsakis
commented
Mar 23, 2015
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. |
nrc
commented
Mar 23, 2015
Yeah, should be |
nrc
commented
Mar 23, 2015
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. |
nikomatsakis
commented
Mar 23, 2015
r+ |
nrc
commented
Mar 23, 2015
@bors r=nikomatsakis c2fde5a |
bors
commented
Mar 23, 2015
🙀 |
nrc
commented
Mar 23, 2015
nrc
commented
Mar 23, 2015
@bors: try |
bors
commented
Mar 23, 2015
⌛ Trying commit c4f3029 with merge d8f41c5... |
bors
commented
Mar 23, 2015
💔 Test failed - try-bsd |
nrc
commented
Mar 24, 2015
@bors: try |
bors
commented
Mar 24, 2015
⌛ Trying commit 48287fe with merge 31738c0... |
bors
commented
Mar 24, 2015
💔 Test failed - try-mac |
nrc
commented
Mar 24, 2015
@bors: try |
bors
commented
Mar 24, 2015
⌛ Trying commit fc7e9b3 with merge 8381980... |
bors
commented
Mar 24, 2015
💔 Test failed - try-win-64 |
nrc
commented
Mar 24, 2015
@bors: try |
bors
commented
Mar 24, 2015
⌛ Trying commit 7315e0a with merge 2782e72... |
bors
commented
Mar 24, 2015
💔 Test failed - try-win-64 |
nrc
commented
Mar 24, 2015
@bors: try |
See notes on the first commit Closes#18601 r? @nikomatsakis cc @eddyb
bors
commented
Mar 24, 2015
bors
commented
Mar 24, 2015
💔 Test failed - try-mac |
nrc
commented
Mar 24, 2015
@bors: try |
nrc
commented
Mar 24, 2015
nrc
commented
Mar 24, 2015
@bors retry |
bors
commented
Mar 24, 2015
⌛ Trying commit a7b6af9 with merge 3f8058d... |
bors
commented
Mar 24, 2015
☔ 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; ```
nrc
commented
Mar 24, 2015
See notes on the first commit Closesrust-lang#18601 r? @nikomatsakis cc @eddyb
alexcrichton
commented
Mar 26, 2015
@nrc how would you feel about making the |
lilyball
commented
Mar 26, 2015
I just filed #23739 requesting that |
bluss
commented
Mar 26, 2015
Ah, breaking change needs to be exactly |
See notes on the first commit
Closes#18601
r? @nikomatsakis
cc @eddyb