Skip to content

Commit 681b48e

Browse files
committed
unstable impl of From<{i64, u64}> for f128
1 parent b711f95 commit 681b48e

4 files changed

Lines changed: 77 additions & 12 deletions

File tree

library/core/src/convert/num.rs

Lines changed: 4 additions & 6 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.")]
@@ -157,8 +157,7 @@ impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
157157
impl_from!(i16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
158158
impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
159159
impl_from!(i32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160-
// FIXME(f128): This impl would allow using `f128` on stable before it is stabilised.
161-
// impl_from!(i64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160+
impl_from!(i64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
162161

163162
// unsigned integer -> float
164163
impl_from!(u8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
@@ -170,8 +169,7 @@ impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
170169
impl_from!(u16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
171170
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172171
impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
173-
// FIXME(f128): This impl would allow using `f128` on stable before it is stabilised.
174-
// impl_from!(u64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172+
impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
175173

176174
// float -> float
177175
// FIXME(f16,f128): adding additional `From<{float}>` impls to `f32` breaks inference. See

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,27 @@ LL | let a: f128 = 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 `f128` is unstable
22-
--> $DIR/feature-gate-f128.rs:16:11
22+
--> $DIR/feature-gate-f128.rs:13:12
23+
|
24+
LL | let d: f128 = 1i64.into();
25+
| ^^^^
26+
|
27+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
28+
= help: add `#![feature(f128)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: the type `f128` is unstable
32+
--> $DIR/feature-gate-f128.rs:16:12
33+
|
34+
LL | let e: f128 = 1u64.into();
35+
| ^^^^
36+
|
37+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
38+
= help: add `#![feature(f128)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: the type `f128` is unstable
42+
--> $DIR/feature-gate-f128.rs:21:11
2343
|
2444
LL | fn foo(a: f128) {}
2545
| ^^^^
@@ -29,7 +49,7 @@ LL | fn foo(a: f128) {}
2949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3050

3151
error[E0658]: the type `f128` is unstable
32-
--> $DIR/feature-gate-f128.rs:19:8
52+
--> $DIR/feature-gate-f128.rs:24:8
3353
|
3454
LL | a: f128,
3555
| ^^^^
@@ -58,6 +78,17 @@ LL | let c = 0f128;
5878
= help: add `#![feature(f128)]` to the crate attributes to enable
5979
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6080

61-
error: aborting due to 6 previous errors
81+
error[E0658]: use of unstable library feature `f128`
82+
--> $DIR/feature-gate-f128.rs:13:24
83+
|
84+
LL | let d: f128 = 1i64.into();
85+
| ^^^^
86+
|
87+
= help: add `#![feature(f128)]` to the crate attributes to enable
88+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
89+
= note: required for `f128` to implement `From<i64>`
90+
= note: required for `i64` to implement `Into<f128>`
91+
92+
error: aborting due to 9 previous errors
6293

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

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,27 @@ LL | let a: f128 = 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 `f128` is unstable
22-
--> $DIR/feature-gate-f128.rs:16:11
22+
--> $DIR/feature-gate-f128.rs:13:12
23+
|
24+
LL | let d: f128 = 1i64.into();
25+
| ^^^^
26+
|
27+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
28+
= help: add `#![feature(f128)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: the type `f128` is unstable
32+
--> $DIR/feature-gate-f128.rs:16:12
33+
|
34+
LL | let e: f128 = 1u64.into();
35+
| ^^^^
36+
|
37+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
38+
= help: add `#![feature(f128)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: the type `f128` is unstable
42+
--> $DIR/feature-gate-f128.rs:21:11
2343
|
2444
LL | fn foo(a: f128) {}
2545
| ^^^^
@@ -29,7 +49,7 @@ LL | fn foo(a: f128) {}
2949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3050

3151
error[E0658]: the type `f128` is unstable
32-
--> $DIR/feature-gate-f128.rs:19:8
52+
--> $DIR/feature-gate-f128.rs:24:8
3353
|
3454
LL | a: f128,
3555
| ^^^^
@@ -58,6 +78,17 @@ LL | let c = 0f128;
5878
= help: add `#![feature(f128)]` to the crate attributes to enable
5979
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6080

61-
error: aborting due to 6 previous errors
81+
error[E0658]: use of unstable library feature `f128`
82+
--> $DIR/feature-gate-f128.rs:13:24
83+
|
84+
LL | let d: f128 = 1i64.into();
85+
| ^^^^
86+
|
87+
= help: add `#![feature(f128)]` to the crate attributes to enable
88+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
89+
= note: required for `f128` to implement `From<i64>`
90+
= note: required for `i64` to implement `Into<f128>`
91+
92+
error: aborting due to 9 previous errors
6293

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ pub fn main() {
1010
let a: f128 = 100.0; //~ ERROR the type `f128` is unstable
1111
let b = 0.0f128; //~ ERROR the type `f128` is unstable
1212
let c = 0f128; //~ ERROR the type `f128` is unstable
13+
let d: f128 = 1i64.into();
14+
//~^ ERROR the type `f128` is unstable
15+
//~| ERROR use of unstable library feature `f128`
16+
let e: f128 = 1u64.into();
17+
//~^ ERROR the type `f128` is unstable
1318
foo(1.23);
1419
}
1520

0 commit comments

Comments
 (0)