Skip to content

Commit 2feca1e

Browse files
authored
Rollup merge of rust-lang#129555 - RalfJung:const_float_bits_conv, r=dtolnay
stabilize const_float_bits_conv This stabilizes `const_float_bits_conv`, and thus fixes rust-lang#72447. With rust-lang#128596 having landed, this is entirely a libs-only question now. ```rust impl f32 { pub const fn to_bits(self) -> u32; pub const fn from_bits(v: u32) -> Self; pub const fn to_be_bytes(self) -> [u8; 4]; pub const fn to_le_bytes(self) -> [u8; 4] pub const fn to_ne_bytes(self) -> [u8; 4]; pub const fn from_be_bytes(bytes: [u8; 4]) -> Self; pub const fn from_le_bytes(bytes: [u8; 4]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self; } impl f64 { pub const fn to_bits(self) -> u64; pub const fn from_bits(v: u64) -> Self; pub const fn to_be_bytes(self) -> [u8; 8]; pub const fn to_le_bytes(self) -> [u8; 8] pub const fn to_ne_bytes(self) -> [u8; 8]; pub const fn from_be_bytes(bytes: [u8; 8]) -> Self; pub const fn from_le_bytes(bytes: [u8; 8]) -> Self; pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self; } ```` Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
2 parents fd0bc94 + a4c4e23 commit 2feca1e

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
#![feature(const_cell_into_inner)]
123123
#![feature(const_eval_select)]
124124
#![feature(const_exact_div)]
125-
#![feature(const_float_bits_conv)]
126125
#![feature(const_float_classify)]
127126
#![feature(const_fmt_arguments_new)]
128127
#![feature(const_hash)]
@@ -166,6 +165,8 @@
166165
#![feature(coverage_attribute)]
167166
#![feature(do_not_recommend)]
168167
#![feature(duration_consts_float)]
168+
#![feature(f128_const)]
169+
#![feature(f16_const)]
169170
#![feature(internal_impls_macro)]
170171
#![feature(ip)]
171172
#![feature(is_ascii_octdigit)]

core/src/num/f128.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl f128 {
914914
/// ```
915915
#[inline]
916916
#[unstable(feature = "f128", issue = "116909")]
917-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
917+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
918918
#[must_use = "this returns the result of the operation, without modifying the original"]
919919
pub const fn to_bits(self) -> u128 {
920920
// SAFETY: `u128` is a plain old datatype so we can always transmute to it.
@@ -963,7 +963,7 @@ impl f128 {
963963
#[inline]
964964
#[must_use]
965965
#[unstable(feature = "f128", issue = "116909")]
966-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
966+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
967967
pub const fn from_bits(v: u128) -> Self {
968968
// It turns out the safety issues with sNaN were overblown! Hooray!
969969
// SAFETY: `u128` is a plain old datatype so we can always transmute from it.
@@ -990,7 +990,7 @@ impl f128 {
990990
/// ```
991991
#[inline]
992992
#[unstable(feature = "f128", issue = "116909")]
993-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
993+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
994994
#[must_use = "this returns the result of the operation, without modifying the original"]
995995
pub const fn to_be_bytes(self) -> [u8; 16] {
996996
self.to_bits().to_be_bytes()
@@ -1016,7 +1016,7 @@ impl f128 {
10161016
/// ```
10171017
#[inline]
10181018
#[unstable(feature = "f128", issue = "116909")]
1019-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1019+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10201020
#[must_use = "this returns the result of the operation, without modifying the original"]
10211021
pub const fn to_le_bytes(self) -> [u8; 16] {
10221022
self.to_bits().to_le_bytes()
@@ -1053,7 +1053,7 @@ impl f128 {
10531053
/// ```
10541054
#[inline]
10551055
#[unstable(feature = "f128", issue = "116909")]
1056-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1056+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10571057
#[must_use = "this returns the result of the operation, without modifying the original"]
10581058
pub const fn to_ne_bytes(self) -> [u8; 16] {
10591059
self.to_bits().to_ne_bytes()
@@ -1081,7 +1081,7 @@ impl f128 {
10811081
#[inline]
10821082
#[must_use]
10831083
#[unstable(feature = "f128", issue = "116909")]
1084-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1084+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10851085
pub const fn from_be_bytes(bytes: [u8; 16]) -> Self {
10861086
Self::from_bits(u128::from_be_bytes(bytes))
10871087
}
@@ -1108,7 +1108,7 @@ impl f128 {
11081108
#[inline]
11091109
#[must_use]
11101110
#[unstable(feature = "f128", issue = "116909")]
1111-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1111+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
11121112
pub const fn from_le_bytes(bytes: [u8; 16]) -> Self {
11131113
Self::from_bits(u128::from_le_bytes(bytes))
11141114
}
@@ -1145,7 +1145,7 @@ impl f128 {
11451145
#[inline]
11461146
#[must_use]
11471147
#[unstable(feature = "f128", issue = "116909")]
1148-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1148+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
11491149
pub const fn from_ne_bytes(bytes: [u8; 16]) -> Self {
11501150
Self::from_bits(u128::from_ne_bytes(bytes))
11511151
}

core/src/num/f16.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl f16 {
925925
/// ```
926926
#[inline]
927927
#[unstable(feature = "f16", issue = "116909")]
928-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
928+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
929929
#[must_use = "this returns the result of the operation, without modifying the original"]
930930
pub const fn to_bits(self) -> u16 {
931931
// SAFETY: `u16` is a plain old datatype so we can always transmute to it.
@@ -973,7 +973,7 @@ impl f16 {
973973
#[inline]
974974
#[must_use]
975975
#[unstable(feature = "f16", issue = "116909")]
976-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
976+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
977977
pub const fn from_bits(v: u16) -> Self {
978978
// It turns out the safety issues with sNaN were overblown! Hooray!
979979
// SAFETY: `u16` is a plain old datatype so we can always transmute from it.
@@ -999,7 +999,7 @@ impl f16 {
999999
/// ```
10001000
#[inline]
10011001
#[unstable(feature = "f16", issue = "116909")]
1002-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1002+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10031003
#[must_use = "this returns the result of the operation, without modifying the original"]
10041004
pub const fn to_be_bytes(self) -> [u8; 2] {
10051005
self.to_bits().to_be_bytes()
@@ -1024,7 +1024,7 @@ impl f16 {
10241024
/// ```
10251025
#[inline]
10261026
#[unstable(feature = "f16", issue = "116909")]
1027-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1027+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10281028
#[must_use = "this returns the result of the operation, without modifying the original"]
10291029
pub const fn to_le_bytes(self) -> [u8; 2] {
10301030
self.to_bits().to_le_bytes()
@@ -1062,7 +1062,7 @@ impl f16 {
10621062
/// ```
10631063
#[inline]
10641064
#[unstable(feature = "f16", issue = "116909")]
1065-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1065+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10661066
#[must_use = "this returns the result of the operation, without modifying the original"]
10671067
pub const fn to_ne_bytes(self) -> [u8; 2] {
10681068
self.to_bits().to_ne_bytes()
@@ -1086,7 +1086,7 @@ impl f16 {
10861086
#[inline]
10871087
#[must_use]
10881088
#[unstable(feature = "f16", issue = "116909")]
1089-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1089+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10901090
pub const fn from_be_bytes(bytes: [u8; 2]) -> Self {
10911091
Self::from_bits(u16::from_be_bytes(bytes))
10921092
}
@@ -1109,7 +1109,7 @@ impl f16 {
11091109
#[inline]
11101110
#[must_use]
11111111
#[unstable(feature = "f16", issue = "116909")]
1112-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1112+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
11131113
pub const fn from_le_bytes(bytes: [u8; 2]) -> Self {
11141114
Self::from_bits(u16::from_le_bytes(bytes))
11151115
}
@@ -1143,7 +1143,7 @@ impl f16 {
11431143
#[inline]
11441144
#[must_use]
11451145
#[unstable(feature = "f16", issue = "116909")]
1146-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1146+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
11471147
pub const fn from_ne_bytes(bytes: [u8; 2]) -> Self {
11481148
Self::from_bits(u16::from_ne_bytes(bytes))
11491149
}

core/src/num/f32.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ impl f32 {
11151115
#[must_use = "this returns the result of the operation, \
11161116
without modifying the original"]
11171117
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1118-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1118+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11191119
#[inline]
11201120
pub const fn to_bits(self) -> u32 {
11211121
// SAFETY: `u32` is a plain old datatype so we can always transmute to it.
@@ -1159,7 +1159,7 @@ impl f32 {
11591159
/// assert_eq!(v, 12.5);
11601160
/// ```
11611161
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1162-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1162+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11631163
#[must_use]
11641164
#[inline]
11651165
pub const fn from_bits(v: u32) -> Self {
@@ -1183,7 +1183,7 @@ impl f32 {
11831183
#[must_use = "this returns the result of the operation, \
11841184
without modifying the original"]
11851185
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1186-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1186+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11871187
#[inline]
11881188
pub const fn to_be_bytes(self) -> [u8; 4] {
11891189
self.to_bits().to_be_bytes()
@@ -1204,7 +1204,7 @@ impl f32 {
12041204
#[must_use = "this returns the result of the operation, \
12051205
without modifying the original"]
12061206
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1207-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1207+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12081208
#[inline]
12091209
pub const fn to_le_bytes(self) -> [u8; 4] {
12101210
self.to_bits().to_le_bytes()
@@ -1238,7 +1238,7 @@ impl f32 {
12381238
#[must_use = "this returns the result of the operation, \
12391239
without modifying the original"]
12401240
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1241-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1241+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12421242
#[inline]
12431243
pub const fn to_ne_bytes(self) -> [u8; 4] {
12441244
self.to_bits().to_ne_bytes()
@@ -1256,7 +1256,7 @@ impl f32 {
12561256
/// assert_eq!(value, 12.5);
12571257
/// ```
12581258
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1259-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1259+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12601260
#[must_use]
12611261
#[inline]
12621262
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self {
@@ -1275,7 +1275,7 @@ impl f32 {
12751275
/// assert_eq!(value, 12.5);
12761276
/// ```
12771277
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1278-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1278+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12791279
#[must_use]
12801280
#[inline]
12811281
pub const fn from_le_bytes(bytes: [u8; 4]) -> Self {
@@ -1305,7 +1305,7 @@ impl f32 {
13051305
/// assert_eq!(value, 12.5);
13061306
/// ```
13071307
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1308-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1308+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
13091309
#[must_use]
13101310
#[inline]
13111311
pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self {

core/src/num/f64.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl f64 {
11111111
#[must_use = "this returns the result of the operation, \
11121112
without modifying the original"]
11131113
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1114-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1114+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11151115
#[inline]
11161116
pub const fn to_bits(self) -> u64 {
11171117
// SAFETY: `u64` is a plain old datatype so we can always transmute to it.
@@ -1155,7 +1155,7 @@ impl f64 {
11551155
/// assert_eq!(v, 12.5);
11561156
/// ```
11571157
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1158-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1158+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11591159
#[must_use]
11601160
#[inline]
11611161
pub const fn from_bits(v: u64) -> Self {
@@ -1179,7 +1179,7 @@ impl f64 {
11791179
#[must_use = "this returns the result of the operation, \
11801180
without modifying the original"]
11811181
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1182-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1182+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11831183
#[inline]
11841184
pub const fn to_be_bytes(self) -> [u8; 8] {
11851185
self.to_bits().to_be_bytes()
@@ -1200,7 +1200,7 @@ impl f64 {
12001200
#[must_use = "this returns the result of the operation, \
12011201
without modifying the original"]
12021202
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1203-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1203+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12041204
#[inline]
12051205
pub const fn to_le_bytes(self) -> [u8; 8] {
12061206
self.to_bits().to_le_bytes()
@@ -1234,7 +1234,7 @@ impl f64 {
12341234
#[must_use = "this returns the result of the operation, \
12351235
without modifying the original"]
12361236
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1237-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1237+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12381238
#[inline]
12391239
pub const fn to_ne_bytes(self) -> [u8; 8] {
12401240
self.to_bits().to_ne_bytes()
@@ -1252,7 +1252,7 @@ impl f64 {
12521252
/// assert_eq!(value, 12.5);
12531253
/// ```
12541254
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1255-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1255+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12561256
#[must_use]
12571257
#[inline]
12581258
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self {
@@ -1271,7 +1271,7 @@ impl f64 {
12711271
/// assert_eq!(value, 12.5);
12721272
/// ```
12731273
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1274-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1274+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12751275
#[must_use]
12761276
#[inline]
12771277
pub const fn from_le_bytes(bytes: [u8; 8]) -> Self {
@@ -1301,7 +1301,7 @@ impl f64 {
13011301
/// assert_eq!(value, 12.5);
13021302
/// ```
13031303
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1304-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1304+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
13051305
#[must_use]
13061306
#[inline]
13071307
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self {

0 commit comments

Comments
 (0)