-
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
Type inference failure for f32
#123824
Comments
f32
cc @tgross35: is it possible that adding the the |
It must be, but I don't know why since https://github.com/rust-lang/rust/pull/122470/files#diff-154dff23a2c2f4fb97915229fd9c27d73293940250088020bfd2074094186ce4R171 wasn't touched. Also reproduced locally |
When there is only one applicable impl it can guide inference, as soon as there are multiple it can't use those and instead goes to default-numeric-fallback which appears to be |
Correct. |
Just coming to the same conclusion - the literal is getting guided to f32 on stable since that's the only type that fits the fn main() {
let a = 3.14;
dbg!(std::any::type_name_of_val(&a)); // prints f32 on stable
let x = f32::from(a);
} |
I'll put up a PR to remove these impls for now but what is the correct longer term fix? cc @rust-lang/libs-api |
@rustbot label -needs-triage +A-inference +F-f16_and_f128 |
I did not remove the feature label lol (it wasn't even in the list), welldone GitHub 😆 |
Theoretically, type inference regressions are permitted as part of Rust's 1.0 stability guarantees. In practice, if the regressions are too bad, the changes usually get reverted and are subsequently blocked indefinitely iirc. However, we could make use of editions if the worst comes to the worst. See arrays & |
Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now. Fixes: <rust-lang#123824>
Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now. Fixes: <rust-lang#123824>
I put a fix up at #123830 and opened #123831 to further discuss what we want to do here. Thanks @P1n3appl3 for identifying this so quick! |
@P1n3appl3 if you get the chance, could you link some of the places that caused this failure? It would be good to have some references for how this behavior is being relied on in the wild. |
This was the one that we caught it on. It's a pretty simple case (that |
…ix, r=Nilstrieb Remove `From` impls for unstable types that break inference Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now. I added a test to make sure this doesn't quietly change in the future, even though the behavior is not technically guaranteed rust-lang#123824 (comment) Fixes: <rust-lang#123824>
Rollup merge of rust-lang#123830 - tgross35:f16-f128-from-inference-fix, r=Nilstrieb Remove `From` impls for unstable types that break inference Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now. I added a test to make sure this doesn't quietly change in the future, even though the behavior is not technically guaranteed rust-lang#123824 (comment) Fixes: <rust-lang#123824>
Hi! I'm from the Bevy project. We caught this bug with this run too, though the error originates from the Taffy crate (0.3.18). |
Awesome, thanks for the report! I started a list of known regressions at #123831, and there is a crater run going to figure out how best to deal with this behavior. The fix for this was merged so should be available on the next nightly (couple of hours?). |
Re-add `From<f16> for f64` This impl was originally added in rust-lang#122470 before being removed in rust-lang#123830 due to rust-lang#123831. However, the issue only affects `f32` (which currently only has one `From<{float}>` impl, `From<f32>`) as `f64` already has two `From<{float}>` impls (`From<f32>` and `From<f64>`) and is also the float literal fallback type anyway. Therefore it is safe to re-add `From<f16> for f64`. This PR also updates the FIXME link to point to the open issue rust-lang#123831 rather than the closed issue rust-lang#123824. Tracking issue: rust-lang#116909 `@rustbot` label +F-f16_and_f128 +T-libs-api
Re-add `From<f16> for f64` This impl was originally added in rust-lang#122470 before being removed in rust-lang#123830 due to rust-lang#123831. However, the issue only affects `f32` (which currently only has one `From<{float}>` impl, `From<f32>`) as `f64` already has two `From<{float}>` impls (`From<f32>` and `From<f64>`) and is also the float literal fallback type anyway. Therefore it is safe to re-add `From<f16> for f64`. This PR also updates the FIXME link to point to the open issue rust-lang#123831 rather than the closed issue rust-lang#123824. Tracking issue: rust-lang#116909 `@rustbot` label +F-f16_and_f128 +T-libs-api
After this rollup we started seeing the following compile failure:
I repro'd this locally on aa6a697 but we have CI that runs on every commit so we're fairly sure that it started with 4435924. Of the changes in that rollup #122470 is the only one that seemed to touch float stuff, but I'm not sure how adding some extra impls for
f16
andf128
would break inference in this case.The text was updated successfully, but these errors were encountered: