Skip to content

Commit 9ec4bdc

Browse files
committed
stabilize const_float_bits_conv
1 parent 717aec0 commit 9ec4bdc

17 files changed

+231
-107
lines changed

library/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)]

library/core/src/num/f128.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ impl f128 {
908908
/// ```
909909
#[inline]
910910
#[unstable(feature = "f128", issue = "116909")]
911-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
911+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
912912
#[must_use = "this returns the result of the operation, without modifying the original"]
913913
pub const fn to_bits(self) -> u128 {
914914
// SAFETY: `u128` is a plain old datatype so we can always transmute to it.
@@ -957,7 +957,7 @@ impl f128 {
957957
#[inline]
958958
#[must_use]
959959
#[unstable(feature = "f128", issue = "116909")]
960-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
960+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
961961
pub const fn from_bits(v: u128) -> Self {
962962
// It turns out the safety issues with sNaN were overblown! Hooray!
963963
// SAFETY: `u128` is a plain old datatype so we can always transmute from it.
@@ -984,7 +984,7 @@ impl f128 {
984984
/// ```
985985
#[inline]
986986
#[unstable(feature = "f128", issue = "116909")]
987-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
987+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
988988
#[must_use = "this returns the result of the operation, without modifying the original"]
989989
pub const fn to_be_bytes(self) -> [u8; 16] {
990990
self.to_bits().to_be_bytes()
@@ -1010,7 +1010,7 @@ impl f128 {
10101010
/// ```
10111011
#[inline]
10121012
#[unstable(feature = "f128", issue = "116909")]
1013-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1013+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10141014
#[must_use = "this returns the result of the operation, without modifying the original"]
10151015
pub const fn to_le_bytes(self) -> [u8; 16] {
10161016
self.to_bits().to_le_bytes()
@@ -1047,7 +1047,7 @@ impl f128 {
10471047
/// ```
10481048
#[inline]
10491049
#[unstable(feature = "f128", issue = "116909")]
1050-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1050+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10511051
#[must_use = "this returns the result of the operation, without modifying the original"]
10521052
pub const fn to_ne_bytes(self) -> [u8; 16] {
10531053
self.to_bits().to_ne_bytes()
@@ -1075,7 +1075,7 @@ impl f128 {
10751075
#[inline]
10761076
#[must_use]
10771077
#[unstable(feature = "f128", issue = "116909")]
1078-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1078+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
10791079
pub const fn from_be_bytes(bytes: [u8; 16]) -> Self {
10801080
Self::from_bits(u128::from_be_bytes(bytes))
10811081
}
@@ -1102,7 +1102,7 @@ impl f128 {
11021102
#[inline]
11031103
#[must_use]
11041104
#[unstable(feature = "f128", issue = "116909")]
1105-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1105+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
11061106
pub const fn from_le_bytes(bytes: [u8; 16]) -> Self {
11071107
Self::from_bits(u128::from_le_bytes(bytes))
11081108
}
@@ -1139,7 +1139,7 @@ impl f128 {
11391139
#[inline]
11401140
#[must_use]
11411141
#[unstable(feature = "f128", issue = "116909")]
1142-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1142+
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
11431143
pub const fn from_ne_bytes(bytes: [u8; 16]) -> Self {
11441144
Self::from_bits(u128::from_ne_bytes(bytes))
11451145
}

library/core/src/num/f16.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl f16 {
919919
/// ```
920920
#[inline]
921921
#[unstable(feature = "f16", issue = "116909")]
922-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
922+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
923923
#[must_use = "this returns the result of the operation, without modifying the original"]
924924
pub const fn to_bits(self) -> u16 {
925925
// SAFETY: `u16` is a plain old datatype so we can always transmute to it.
@@ -967,7 +967,7 @@ impl f16 {
967967
#[inline]
968968
#[must_use]
969969
#[unstable(feature = "f16", issue = "116909")]
970-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
970+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
971971
pub const fn from_bits(v: u16) -> Self {
972972
// It turns out the safety issues with sNaN were overblown! Hooray!
973973
// SAFETY: `u16` is a plain old datatype so we can always transmute from it.
@@ -993,7 +993,7 @@ impl f16 {
993993
/// ```
994994
#[inline]
995995
#[unstable(feature = "f16", issue = "116909")]
996-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
996+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
997997
#[must_use = "this returns the result of the operation, without modifying the original"]
998998
pub const fn to_be_bytes(self) -> [u8; 2] {
999999
self.to_bits().to_be_bytes()
@@ -1018,7 +1018,7 @@ impl f16 {
10181018
/// ```
10191019
#[inline]
10201020
#[unstable(feature = "f16", issue = "116909")]
1021-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1021+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10221022
#[must_use = "this returns the result of the operation, without modifying the original"]
10231023
pub const fn to_le_bytes(self) -> [u8; 2] {
10241024
self.to_bits().to_le_bytes()
@@ -1056,7 +1056,7 @@ impl f16 {
10561056
/// ```
10571057
#[inline]
10581058
#[unstable(feature = "f16", issue = "116909")]
1059-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1059+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10601060
#[must_use = "this returns the result of the operation, without modifying the original"]
10611061
pub const fn to_ne_bytes(self) -> [u8; 2] {
10621062
self.to_bits().to_ne_bytes()
@@ -1080,7 +1080,7 @@ impl f16 {
10801080
#[inline]
10811081
#[must_use]
10821082
#[unstable(feature = "f16", issue = "116909")]
1083-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1083+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
10841084
pub const fn from_be_bytes(bytes: [u8; 2]) -> Self {
10851085
Self::from_bits(u16::from_be_bytes(bytes))
10861086
}
@@ -1103,7 +1103,7 @@ impl f16 {
11031103
#[inline]
11041104
#[must_use]
11051105
#[unstable(feature = "f16", issue = "116909")]
1106-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1106+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
11071107
pub const fn from_le_bytes(bytes: [u8; 2]) -> Self {
11081108
Self::from_bits(u16::from_le_bytes(bytes))
11091109
}
@@ -1137,7 +1137,7 @@ impl f16 {
11371137
#[inline]
11381138
#[must_use]
11391139
#[unstable(feature = "f16", issue = "116909")]
1140-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1140+
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
11411141
pub const fn from_ne_bytes(bytes: [u8; 2]) -> Self {
11421142
Self::from_bits(u16::from_ne_bytes(bytes))
11431143
}

library/core/src/num/f32.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ impl f32 {
11131113
#[must_use = "this returns the result of the operation, \
11141114
without modifying the original"]
11151115
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1116-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1116+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11171117
#[inline]
11181118
pub const fn to_bits(self) -> u32 {
11191119
// SAFETY: `u32` is a plain old datatype so we can always transmute to it.
@@ -1157,7 +1157,7 @@ impl f32 {
11571157
/// assert_eq!(v, 12.5);
11581158
/// ```
11591159
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1160-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1160+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11611161
#[must_use]
11621162
#[inline]
11631163
pub const fn from_bits(v: u32) -> Self {
@@ -1181,7 +1181,7 @@ impl f32 {
11811181
#[must_use = "this returns the result of the operation, \
11821182
without modifying the original"]
11831183
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1184-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1184+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11851185
#[inline]
11861186
pub const fn to_be_bytes(self) -> [u8; 4] {
11871187
self.to_bits().to_be_bytes()
@@ -1202,7 +1202,7 @@ impl f32 {
12021202
#[must_use = "this returns the result of the operation, \
12031203
without modifying the original"]
12041204
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1205-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1205+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12061206
#[inline]
12071207
pub const fn to_le_bytes(self) -> [u8; 4] {
12081208
self.to_bits().to_le_bytes()
@@ -1236,7 +1236,7 @@ impl f32 {
12361236
#[must_use = "this returns the result of the operation, \
12371237
without modifying the original"]
12381238
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1239-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1239+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12401240
#[inline]
12411241
pub const fn to_ne_bytes(self) -> [u8; 4] {
12421242
self.to_bits().to_ne_bytes()
@@ -1254,7 +1254,7 @@ impl f32 {
12541254
/// assert_eq!(value, 12.5);
12551255
/// ```
12561256
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1257-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1257+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12581258
#[must_use]
12591259
#[inline]
12601260
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self {
@@ -1273,7 +1273,7 @@ impl f32 {
12731273
/// assert_eq!(value, 12.5);
12741274
/// ```
12751275
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1276-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1276+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12771277
#[must_use]
12781278
#[inline]
12791279
pub const fn from_le_bytes(bytes: [u8; 4]) -> Self {
@@ -1303,7 +1303,7 @@ impl f32 {
13031303
/// assert_eq!(value, 12.5);
13041304
/// ```
13051305
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1306-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1306+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
13071307
#[must_use]
13081308
#[inline]
13091309
pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self {

library/core/src/num/f64.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ impl f64 {
11091109
#[must_use = "this returns the result of the operation, \
11101110
without modifying the original"]
11111111
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1112-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1112+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11131113
#[inline]
11141114
pub const fn to_bits(self) -> u64 {
11151115
// SAFETY: `u64` is a plain old datatype so we can always transmute to it.
@@ -1153,7 +1153,7 @@ impl f64 {
11531153
/// assert_eq!(v, 12.5);
11541154
/// ```
11551155
#[stable(feature = "float_bits_conv", since = "1.20.0")]
1156-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1156+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11571157
#[must_use]
11581158
#[inline]
11591159
pub const fn from_bits(v: u64) -> Self {
@@ -1177,7 +1177,7 @@ impl f64 {
11771177
#[must_use = "this returns the result of the operation, \
11781178
without modifying the original"]
11791179
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1180-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1180+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
11811181
#[inline]
11821182
pub const fn to_be_bytes(self) -> [u8; 8] {
11831183
self.to_bits().to_be_bytes()
@@ -1198,7 +1198,7 @@ impl f64 {
11981198
#[must_use = "this returns the result of the operation, \
11991199
without modifying the original"]
12001200
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1201-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1201+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12021202
#[inline]
12031203
pub const fn to_le_bytes(self) -> [u8; 8] {
12041204
self.to_bits().to_le_bytes()
@@ -1232,7 +1232,7 @@ impl f64 {
12321232
#[must_use = "this returns the result of the operation, \
12331233
without modifying the original"]
12341234
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1235-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1235+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12361236
#[inline]
12371237
pub const fn to_ne_bytes(self) -> [u8; 8] {
12381238
self.to_bits().to_ne_bytes()
@@ -1250,7 +1250,7 @@ impl f64 {
12501250
/// assert_eq!(value, 12.5);
12511251
/// ```
12521252
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1253-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1253+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12541254
#[must_use]
12551255
#[inline]
12561256
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self {
@@ -1269,7 +1269,7 @@ impl f64 {
12691269
/// assert_eq!(value, 12.5);
12701270
/// ```
12711271
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1272-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1272+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
12731273
#[must_use]
12741274
#[inline]
12751275
pub const fn from_le_bytes(bytes: [u8; 8]) -> Self {
@@ -1299,7 +1299,7 @@ impl f64 {
12991299
/// assert_eq!(value, 12.5);
13001300
/// ```
13011301
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
1302-
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
1302+
#[rustc_const_stable(feature = "const_float_bits_conv", since = "CURRENT_RUSTC_VERSION")]
13031303
#[must_use]
13041304
#[inline]
13051305
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self {

src/tools/clippy/clippy_lints/src/transmute/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
619619
| transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context)
620620
| transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, &self.msrv)
621621
| transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg)
622-
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context)
622+
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg)
623623
| transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg)
624-
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context)
625-
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context)
624+
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg)
625+
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg)
626626
| (unsound_collection_transmute::check(cx, e, from_ty, to_ty)
627627
|| transmute_undefined_repr::check(cx, e, from_ty, to_ty))
628628
| (eager_transmute::check(cx, e, arg, from_ty, to_ty));

src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ pub(super) fn check<'tcx>(
1515
from_ty: Ty<'tcx>,
1616
to_ty: Ty<'tcx>,
1717
mut arg: &'tcx Expr<'_>,
18-
const_context: bool,
1918
) -> bool {
2019
match (&from_ty.kind(), &to_ty.kind()) {
21-
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) if !const_context => {
20+
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) => {
2221
span_lint_and_then(
2322
cx,
2423
TRANSMUTE_FLOAT_TO_INT,

src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ pub(super) fn check<'tcx>(
1414
from_ty: Ty<'tcx>,
1515
to_ty: Ty<'tcx>,
1616
arg: &'tcx Expr<'_>,
17-
const_context: bool,
1817
) -> bool {
1918
match (&from_ty.kind(), &to_ty.kind()) {
20-
(ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context => {
19+
(ty::Int(_) | ty::Uint(_), ty::Float(_)) => {
2120
span_lint_and_then(
2221
cx,
2322
TRANSMUTE_INT_TO_FLOAT,

src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs

-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ pub(super) fn check<'tcx>(
1414
from_ty: Ty<'tcx>,
1515
to_ty: Ty<'tcx>,
1616
arg: &'tcx Expr<'_>,
17-
const_context: bool,
1817
) -> bool {
1918
match (&from_ty.kind(), &to_ty.kind()) {
2019
(ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => {
2120
if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) {
2221
return false;
2322
}
24-
if matches!(from_ty.kind(), ty::Float(_)) && const_context {
25-
// TODO: Remove when const_float_bits_conv is stabilized
26-
// rust#72447
27-
return false;
28-
}
2923

3024
span_lint_and_then(
3125
cx,

0 commit comments

Comments
 (0)