Skip to content

Commit 48aefdc

Browse files
committed
mark From<f16> for f32 as an unstable instance
1 parent 2193b7e commit 48aefdc

9 files changed

Lines changed: 79 additions & 25 deletions

File tree

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,7 +5636,7 @@ declare_lint! {
56365636
/// ### Explanation
56375637
///
56385638
/// Rust allows traits that are only implemented for a single floating point type to guide type
5639-
/// inferrence for floating point literals. This used to apply in the case of `f32: From<T>`
5639+
/// inference for floating point literals. This used to apply in the case of `f32: From<T>`
56405640
/// (where `T` was inferred to be the same type as a floating point literal), as the only
56415641
/// floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding
56425642
/// support for `f16`, there are now two implementations for floating point types:
@@ -5657,7 +5657,7 @@ declare_lint! {
56575657
Warn,
56585658
"detects unsuffixed floating point literals whose type fallback to `f32`",
56595659
@future_incompatible = FutureIncompatibleInfo {
5660-
reason: fcw!(FutureReleaseError #0),
5660+
reason: fcw!(FutureReleaseError #154024),
56615661
report_in_deps: false,
56625662
};
56635663
}

library/core/src/convert/num.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl_from_bool!(i8 i16 i32 i64 i128 isize);
7070

7171
/// Implement `From<$small>` for `$large`
7272
macro_rules! impl_from {
73-
($small:ty => $large:ty, #[$attr:meta]) => {
74-
#[$attr]
73+
($small:ty => $large:ty, $(#[$attrs:meta]),+) => {
74+
$(#[$attrs])+
7575
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
7676
impl const From<$small> for $large {
7777
#[doc = concat!("Converts from [`", stringify!($small), "`] to [`", stringify!($large), "`] losslessly.")]
@@ -174,9 +174,14 @@ impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0
174174
// impl_from!(u64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
175175

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

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
|

tests/ui/inference/untyped-primitives.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = f32::from(3.14);
55
| ^^^^ help: explicitly specify the type as `f32`: `3.14_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 #FIXME <https://github.com/rust-lang/rust/issues/FIXME>
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: 1 warning emitted

0 commit comments

Comments
 (0)