Skip to content

Commit

Permalink
Rollup merge of #123830 - tgross35:f16-f128-from-inference-fix, r=Nil…
Browse files Browse the repository at this point in the history
…strieb

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 #123824 (comment)

Fixes: <#123824>
  • Loading branch information
matthiaskrgr authored Apr 12, 2024
2 parents b467edd + 9bcc988 commit bcf24d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);

// float -> float
impl_from!(f16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
// FIXME(f16_f128): adding additional `From` impls for existing types breaks inference. See
// <https://github.com/rust-lang/rust/issues/123824>
impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/inference/untyped-primitives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ check-pass
// issue: rust-lang/rust#123824
// This test is a sanity check and does not enforce any stable API, so may be
// removed at a future point.

fn main() {
let x = f32::from(3.14);
let y = f64::from(3.14);
}

0 comments on commit bcf24d6

Please sign in to comment.