-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove From
impls for unstable types that break inference
#123830
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
Merged
Merged
+11
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now. Fixes: <rust-lang#123824>
f48cd1c
to
9bcc988
Compare
This only changes unstable API so I think it ok for somebody from libs (rather than libs-api) to review. @rustbot label +F-f16_and_f128 |
@bors r+ rollup |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 12, 2024
…iaskrgr Rollup of 3 pull requests Successful merges: - rust-lang#123796 (Remove unused cargo-platform dependency from tidy) - rust-lang#123830 (Remove `From` impls for unstable types that break inference) - rust-lang#123842 (fix typo in pin.rs) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 12, 2024
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>
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 5, 2024
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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 16, 2024
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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 28, 2025
Fallback `{float}` to `f32` when `f32: From<{float}>` and add `impl From<f16> for f32` Currently, the following code compiles: ```rust fn foo::<T: Into<f32>>(_: T) {} fn main() { foo(1.0); } ``` This is because the only `From<{float}>` impl for `f32` is currently `From<f32>`. However, once `impl From<f16> for f32` is added this is no longer the case. This would cause the float literal to fallback to `f64`, subsequently causing a type error as `f32` does not implement `From<f64>`. While this kind of change to type inference isn't technically a breaking change according to Rust's breaking change policy, the previous attempt to add `impl From<f16> for f32` was removed rust-lang#123830 due to the large number of crates affected (by my count, there were root regressions in 42 crates and 52 GitHub repos, not including duplicates). This PR solves this problem by using `f32` as the fallback type for `{float}` when there is a trait predicate of `f32: From<{float}>`. This allows adding `impl From<f16> for f32` without affecting the code that currently compiles (such as the example above; this PR shouldn't affect what is possible on stable). This PR also allows adding a future-incompatibility warning if the lang team wants one; alternatively this could be expanded in the future into something more general like `@tgross35` suggested in rust-lang#123831 (comment). I think it would be also possible to disallow the `f32` fallback in a future edition. This will need a crater check. For reference, I've based the implementation loosely on the existing `calculate_diverging_fallback`. This first commit adds the `f32` fallback and the second adds `impl From<f16> for f32`. I think this falls under the types team, so r? types Fixes: rust-lang#123831 Tracking issue: rust-lang#116909 `@rustbot` label +T-lang +T-types +T-libs-api +F-f16_and_f128 To decide on whether a future-incompatibility warning is desired or otherwise (see above): `@rustbot` label +I-lang-nominated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
F-f16_and_f128
`#![feature(f16)]`, `#![feature(f128)]`
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding additional
From
implementations that fitf32::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 #123824 (comment)
Fixes: #123824