mark From<f16> for f32 as an unstable instance

This commit is contained in:
Folkert de Vries
2026-03-17 17:06:29 +01:00
parent 7aad5c0784
commit dfb680751e
11 changed files with 101 additions and 25 deletions
+5 -4
View File
@@ -5667,7 +5667,7 @@
/// ### Explanation
///
/// Rust allows traits that are only implemented for a single floating point type to guide type
/// inferrence for floating point literals. This used to apply in the case of `f32: From<T>`
/// inference for floating point literals. This used to apply in the case of `f32: From<T>`
/// (where `T` was inferred to be the same type as a floating point literal), as the only
/// floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding
/// support for `f16`, there are now two implementations for floating point types:
@@ -5681,14 +5681,15 @@
/// to the literal, which will fix the problem.
///
/// This is a [future-incompatible] lint to transition this to a hard error in the future. See
/// [issue #FIXME] for more details.
/// [issue #154024] for more details.
///
/// [issue #FIXME]: https://github.com/rust-lang/rust/issues/FIXME
/// [issue #154024]: https://github.com/rust-lang/rust/issues/154024
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub FLOAT_LITERAL_F32_FALLBACK,
Warn,
"detects unsuffixed floating point literals whose type fallback to `f32`",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError #0),
reason: fcw!(FutureReleaseError #154024),
report_in_deps: false,
};
}
+8 -3
View File
@@ -172,9 +172,14 @@ fn from(small: $small) -> Self {
impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
// float -> float
// FIXME(f16,f128): adding additional `From<{float}>` impls to `f32` breaks inference. See
// <https://github.com/rust-lang/rust/issues/123831>
impl_from!(f16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
// FIXME(f16): adding the additional `From<{float}>` impl to `f32` would break inference in cases
// like `f32::from(1.0)`. The type checker has a custom workaround to keep that and similar code
// compiling even with the second `From<16> for f32` instance. We keep this instance unstable for
// now so that we can later remove the workaround.
//
// See also <https://github.com/rust-lang/rust/issues/123831>.
impl_from!(f16 => f32, #[unstable(feature = "f32_from_f16", issue = "154005")], #[unstable_feature_bound(f32_from_f16)]);
impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
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")]);
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:16:11
--> $DIR/feature-gate-f16.rs:19:11
|
LL | fn foo(a: f16) {}
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:19:8
--> $DIR/feature-gate-f16.rs:22:8
|
LL | a: f16,
| ^^^
@@ -58,6 +58,27 @@ LL | let c = 0f16;
= help: add `#![feature(f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 6 previous errors
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:13:18
|
LL | let d: f32 = 1.0f16.into();
| ^^^^^^
|
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
= help: add `#![feature(f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `f32_from_f16`
--> $DIR/feature-gate-f16.rs:13:25
|
LL | let d: f32 = 1.0f16.into();
| ^^^^
|
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `f32` to implement `From<f16>`
= note: required for `f16` to implement `Into<f32>`
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0658`.
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:16:11
--> $DIR/feature-gate-f16.rs:19:11
|
LL | fn foo(a: f16) {}
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:19:8
--> $DIR/feature-gate-f16.rs:22:8
|
LL | a: f16,
| ^^^
@@ -58,6 +58,27 @@ LL | let c = 0f16;
= help: add `#![feature(f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 6 previous errors
error[E0658]: the type `f16` is unstable
--> $DIR/feature-gate-f16.rs:13:18
|
LL | let d: f32 = 1.0f16.into();
| ^^^^^^
|
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
= help: add `#![feature(f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `f32_from_f16`
--> $DIR/feature-gate-f16.rs:13:25
|
LL | let d: f32 = 1.0f16.into();
| ^^^^
|
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `f32` to implement `From<f16>`
= note: required for `f16` to implement `Into<f32>`
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0658`.
@@ -10,6 +10,9 @@ pub fn main() {
let a: f16 = 100.0; //~ ERROR the type `f16` is unstable
let b = 0.0f16; //~ ERROR the type `f16` is unstable
let c = 0f16; //~ ERROR the type `f16` is unstable
let d: f32 = 1.0f16.into();
//~^ ERROR the type `f16` is unstable
//~| ERROR use of unstable library feature `f32_from_f16`
foo(1.23);
}
@@ -0,0 +1,7 @@
#![feature(f16)]
#![allow(unused)]
pub fn main() {
let _: f32 = 1.0f16.into();
//~^ ERROR use of unstable library feature `f32_from_f16`
}
@@ -0,0 +1,14 @@
error[E0658]: use of unstable library feature `f32_from_f16`
--> $DIR/feature-gate-f32_from_f16.rs:5:25
|
LL | let _: f32 = 1.0f16.into();
| ^^^^
|
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `f32` to implement `From<f16>`
= note: required for `f16` to implement `Into<f32>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0658`.
@@ -5,7 +5,7 @@ LL | foo(1.0);
| ^^^ help: explicitly specify the type as `f32`: `1.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
= note: `#[warn(float_literal_f32_fallback)]` on by default
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
@@ -15,7 +15,7 @@ LL | foo(-(2.5));
| ^^^ help: explicitly specify the type as `f32`: `2.5_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:15:9
@@ -24,7 +24,7 @@ LL | foo(1e5);
| ^^^ help: explicitly specify the type as `f32`: `1e5_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
@@ -33,7 +33,7 @@ LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: 4 warnings emitted
@@ -5,7 +5,7 @@ LL | foo(1.0);
| ^^^ help: explicitly specify the type as `f32`: `1.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
= note: `#[warn(float_literal_f32_fallback)]` on by default
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
@@ -15,7 +15,7 @@ LL | foo(-(2.5));
| ^^^ help: explicitly specify the type as `f32`: `2.5_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:15:9
@@ -24,7 +24,7 @@ LL | foo(1e5);
| ^^^ help: explicitly specify the type as `f32`: `1e5_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
@@ -33,7 +33,7 @@ LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: 4 warnings emitted
+7 -3
View File
@@ -6,9 +6,13 @@ LL | foo(1.0);
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Trait`:
f16
f32
help: the following other types implement trait `Trait`
--> $DIR/trait-f16-or-f32.rs:6:1
|
LL | impl Trait for f16 {}
| ^^^^^^^^^^^^^^^^^^ `f16`
LL | impl Trait for f32 {}
| ^^^^^^^^^^^^^^^^^^ `f32`
note: required by a bound in `foo`
--> $DIR/trait-f16-or-f32.rs:9:16
|
+1 -1
View File
@@ -5,7 +5,7 @@ LL | let x = f32::from(3.14);
| ^^^^ help: explicitly specify the type as `f32`: `3.14_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #FIXME <https://github.com/rust-lang/rust/issues/FIXME>
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
= note: `#[warn(float_literal_f32_fallback)]` on by default
warning: 1 warning emitted