diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index d7ca52c590f1..65c25849c714 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -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` + /// inference for floating point literals. This used to apply in the case of `f32: From` /// (where `T` was inferred to be the same type as a floating point literal), as the only /// floating point type impl was `f32: From`. 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, }; } diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 476ee7638675..a5c9eaf9035a 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -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 -// -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 . +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")]); diff --git a/tests/ui/feature-gates/feature-gate-f16.e2015.stderr b/tests/ui/feature-gates/feature-gate-f16.e2015.stderr index 5d1ca8f6d047..b53f12af48fc 100644 --- a/tests/ui/feature-gates/feature-gate-f16.e2015.stderr +++ b/tests/ui/feature-gates/feature-gate-f16.e2015.stderr @@ -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 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` + = note: required for `f16` to implement `Into` + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-f16.e2018.stderr b/tests/ui/feature-gates/feature-gate-f16.e2018.stderr index 5d1ca8f6d047..b53f12af48fc 100644 --- a/tests/ui/feature-gates/feature-gate-f16.e2018.stderr +++ b/tests/ui/feature-gates/feature-gate-f16.e2018.stderr @@ -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 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` + = note: required for `f16` to implement `Into` + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-f16.rs b/tests/ui/feature-gates/feature-gate-f16.rs index f748c603efe9..6babc6c5c03c 100644 --- a/tests/ui/feature-gates/feature-gate-f16.rs +++ b/tests/ui/feature-gates/feature-gate-f16.rs @@ -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); } diff --git a/tests/ui/feature-gates/feature-gate-f32_from_f16.rs b/tests/ui/feature-gates/feature-gate-f32_from_f16.rs new file mode 100644 index 000000000000..5a7381b85b0f --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f32_from_f16.rs @@ -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` +} diff --git a/tests/ui/feature-gates/feature-gate-f32_from_f16.stderr b/tests/ui/feature-gates/feature-gate-f32_from_f16.stderr new file mode 100644 index 000000000000..ce3e8ffb3b0d --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f32_from_f16.stderr @@ -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` + = note: required for `f16` to implement `Into` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/float/f32-into-f32.next-solver.stderr b/tests/ui/float/f32-into-f32.next-solver.stderr index ea71e3652384..8df6ba4ad5ee 100644 --- a/tests/ui/float/f32-into-f32.next-solver.stderr +++ b/tests/ui/float/f32-into-f32.next-solver.stderr @@ -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 + = note: for more information, see issue #154024 = note: `#[warn(float_literal_f32_fallback)]` on by default warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: 4 warnings emitted diff --git a/tests/ui/float/f32-into-f32.old-solver.stderr b/tests/ui/float/f32-into-f32.old-solver.stderr index ea71e3652384..8df6ba4ad5ee 100644 --- a/tests/ui/float/f32-into-f32.old-solver.stderr +++ b/tests/ui/float/f32-into-f32.old-solver.stderr @@ -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 + = note: for more information, see issue #154024 = note: `#[warn(float_literal_f32_fallback)]` on by default warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: falling back to `f32` as the trait bound `f32: From` 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 + = note: for more information, see issue #154024 warning: 4 warnings emitted diff --git a/tests/ui/float/trait-f16-or-f32.stderr b/tests/ui/float/trait-f16-or-f32.stderr index 8af81231bd94..0117d787bc61 100644 --- a/tests/ui/float/trait-f16-or-f32.stderr +++ b/tests/ui/float/trait-f16-or-f32.stderr @@ -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 | diff --git a/tests/ui/inference/untyped-primitives.stderr b/tests/ui/inference/untyped-primitives.stderr index 48d62963221c..3467cef75218 100644 --- a/tests/ui/inference/untyped-primitives.stderr +++ b/tests/ui/inference/untyped-primitives.stderr @@ -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 + = note: for more information, see issue #154024 = note: `#[warn(float_literal_f32_fallback)]` on by default warning: 1 warning emitted