Skip to content

Commit dfb6807

Browse files
committed
mark From<f16> for f32 as an unstable instance
1 parent 7aad5c0 commit dfb6807

11 files changed

Lines changed: 101 additions & 25 deletions

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,7 +5667,7 @@ declare_lint! {
56675667
/// ### Explanation
56685668
///
56695669
/// Rust allows traits that are only implemented for a single floating point type to guide type
5670-
/// inferrence for floating point literals. This used to apply in the case of `f32: From<T>`
5670+
/// inference for floating point literals. This used to apply in the case of `f32: From<T>`
56715671
/// (where `T` was inferred to be the same type as a floating point literal), as the only
56725672
/// floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding
56735673
/// support for `f16`, there are now two implementations for floating point types:
@@ -5681,14 +5681,15 @@ declare_lint! {
56815681
/// to the literal, which will fix the problem.
56825682
///
56835683
/// This is a [future-incompatible] lint to transition this to a hard error in the future. See
5684-
/// [issue #FIXME] for more details.
5684+
/// [issue #154024] for more details.
56855685
///
5686-
/// [issue #FIXME]: https://github.com/rust-lang/rust/issues/FIXME
5686+
/// [issue #154024]: https://github.com/rust-lang/rust/issues/154024
5687+
/// [future-incompatible]: ../index.md#future-incompatible-lints
56875688
pub FLOAT_LITERAL_F32_FALLBACK,
56885689
Warn,
56895690
"detects unsuffixed floating point literals whose type fallback to `f32`",
56905691
@future_incompatible = FutureIncompatibleInfo {
5691-
reason: fcw!(FutureReleaseError #0),
5692+
reason: fcw!(FutureReleaseError #154024),
56925693
report_in_deps: false,
56935694
};
56945695
}

library/core/src/convert/num.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0
172172
impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
173173

174174
// float -> float
175-
// FIXME(f16,f128): adding additional `From<{float}>` impls to `f32` breaks inference. See
176-
// <https://github.com/rust-lang/rust/issues/123831>
177-
impl_from!(f16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
175+
176+
// FIXME(f16): adding the additional `From<{float}>` impl to `f32` would break inference in cases
177+
// like `f32::from(1.0)`. The type checker has a custom workaround to keep that and similar code
178+
// compiling even with the second `From<16> for f32` instance. We keep this instance unstable for
179+
// now so that we can later remove the workaround.
180+
//
181+
// See also <https://github.com/rust-lang/rust/issues/123831>.
182+
impl_from!(f16 => f32, #[unstable(feature = "f32_from_f16", issue = "154005")], #[unstable_feature_bound(f32_from_f16)]);
178183
impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
179184
impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
180185
impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);

tests/ui/feature-gates/feature-gate-f16.e2015.stderr

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f16` is unstable
22-
--> $DIR/feature-gate-f16.rs:16:11
22+
--> $DIR/feature-gate-f16.rs:19:11
2323
|
2424
LL | fn foo(a: f16) {}
2525
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f16` is unstable
32-
--> $DIR/feature-gate-f16.rs:19:8
32+
--> $DIR/feature-gate-f16.rs:22:8
3333
|
3434
LL | a: f16,
3535
| ^^^
@@ -58,6 +58,27 @@ LL | let c = 0f16;
5858
= help: add `#![feature(f16)]` to the crate attributes to enable
5959
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6060

61-
error: aborting due to 6 previous errors
61+
error[E0658]: the type `f16` is unstable
62+
--> $DIR/feature-gate-f16.rs:13:18
63+
|
64+
LL | let d: f32 = 1.0f16.into();
65+
| ^^^^^^
66+
|
67+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
68+
= help: add `#![feature(f16)]` to the crate attributes to enable
69+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
70+
71+
error[E0658]: use of unstable library feature `f32_from_f16`
72+
--> $DIR/feature-gate-f16.rs:13:25
73+
|
74+
LL | let d: f32 = 1.0f16.into();
75+
| ^^^^
76+
|
77+
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
78+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
79+
= note: required for `f32` to implement `From<f16>`
80+
= note: required for `f16` to implement `Into<f32>`
81+
82+
error: aborting due to 8 previous errors
6283

6384
For more information about this error, try `rustc --explain E0658`.

tests/ui/feature-gates/feature-gate-f16.e2018.stderr

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f16` is unstable
22-
--> $DIR/feature-gate-f16.rs:16:11
22+
--> $DIR/feature-gate-f16.rs:19:11
2323
|
2424
LL | fn foo(a: f16) {}
2525
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f16` is unstable
32-
--> $DIR/feature-gate-f16.rs:19:8
32+
--> $DIR/feature-gate-f16.rs:22:8
3333
|
3434
LL | a: f16,
3535
| ^^^
@@ -58,6 +58,27 @@ LL | let c = 0f16;
5858
= help: add `#![feature(f16)]` to the crate attributes to enable
5959
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6060

61-
error: aborting due to 6 previous errors
61+
error[E0658]: the type `f16` is unstable
62+
--> $DIR/feature-gate-f16.rs:13:18
63+
|
64+
LL | let d: f32 = 1.0f16.into();
65+
| ^^^^^^
66+
|
67+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
68+
= help: add `#![feature(f16)]` to the crate attributes to enable
69+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
70+
71+
error[E0658]: use of unstable library feature `f32_from_f16`
72+
--> $DIR/feature-gate-f16.rs:13:25
73+
|
74+
LL | let d: f32 = 1.0f16.into();
75+
| ^^^^
76+
|
77+
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
78+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
79+
= note: required for `f32` to implement `From<f16>`
80+
= note: required for `f16` to implement `Into<f32>`
81+
82+
error: aborting due to 8 previous errors
6283

6384
For more information about this error, try `rustc --explain E0658`.

tests/ui/feature-gates/feature-gate-f16.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub fn main() {
1010
let a: f16 = 100.0; //~ ERROR the type `f16` is unstable
1111
let b = 0.0f16; //~ ERROR the type `f16` is unstable
1212
let c = 0f16; //~ ERROR the type `f16` is unstable
13+
let d: f32 = 1.0f16.into();
14+
//~^ ERROR the type `f16` is unstable
15+
//~| ERROR use of unstable library feature `f32_from_f16`
1316
foo(1.23);
1417
}
1518

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(f16)]
2+
#![allow(unused)]
3+
4+
pub fn main() {
5+
let _: f32 = 1.0f16.into();
6+
//~^ ERROR use of unstable library feature `f32_from_f16`
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0658]: use of unstable library feature `f32_from_f16`
2+
--> $DIR/feature-gate-f32_from_f16.rs:5:25
3+
|
4+
LL | let _: f32 = 1.0f16.into();
5+
| ^^^^
6+
|
7+
= help: add `#![feature(f32_from_f16)]` to the crate attributes to enable
8+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9+
= note: required for `f32` to implement `From<f16>`
10+
= note: required for `f16` to implement `Into<f32>`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0658`.

tests/ui/float/f32-into-f32.next-solver.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | foo(1.0);
55
| ^^^ help: explicitly specify the type as `f32`: `1.0_f32`
66
|
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
8+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
99
= note: `#[warn(float_literal_f32_fallback)]` on by default
1010

1111
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
@@ -15,7 +15,7 @@ LL | foo(-(2.5));
1515
| ^^^ help: explicitly specify the type as `f32`: `2.5_f32`
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
18+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
1919

2020
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
2121
--> $DIR/f32-into-f32.rs:15:9
@@ -24,7 +24,7 @@ LL | foo(1e5);
2424
| ^^^ help: explicitly specify the type as `f32`: `1e5_f32`
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
27+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
2828

2929
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
3030
--> $DIR/f32-into-f32.rs:19:14
@@ -33,7 +33,7 @@ LL | let x = -4.0;
3333
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
3434
|
3535
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
36+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
3737

3838
warning: 4 warnings emitted
3939

tests/ui/float/f32-into-f32.old-solver.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | foo(1.0);
55
| ^^^ help: explicitly specify the type as `f32`: `1.0_f32`
66
|
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
8+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
99
= note: `#[warn(float_literal_f32_fallback)]` on by default
1010

1111
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
@@ -15,7 +15,7 @@ LL | foo(-(2.5));
1515
| ^^^ help: explicitly specify the type as `f32`: `2.5_f32`
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
18+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
1919

2020
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
2121
--> $DIR/f32-into-f32.rs:15:9
@@ -24,7 +24,7 @@ LL | foo(1e5);
2424
| ^^^ help: explicitly specify the type as `f32`: `1e5_f32`
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
27+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
2828

2929
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
3030
--> $DIR/f32-into-f32.rs:19:14
@@ -33,7 +33,7 @@ LL | let x = -4.0;
3333
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
3434
|
3535
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36-
= note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
36+
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
3737

3838
warning: 4 warnings emitted
3939

tests/ui/float/trait-f16-or-f32.stderr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ LL | foo(1.0);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the following other types implement trait `Trait`:
10-
f16
11-
f32
9+
help: the following other types implement trait `Trait`
10+
--> $DIR/trait-f16-or-f32.rs:6:1
11+
|
12+
LL | impl Trait for f16 {}
13+
| ^^^^^^^^^^^^^^^^^^ `f16`
14+
LL | impl Trait for f32 {}
15+
| ^^^^^^^^^^^^^^^^^^ `f32`
1216
note: required by a bound in `foo`
1317
--> $DIR/trait-f16-or-f32.rs:9:16
1418
|

0 commit comments

Comments
 (0)