]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #69373 - tspiteri:const_int_conversion, r=oli-obk
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 11 Mar 2020 09:36:18 +0000 (10:36 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Mar 2020 09:36:18 +0000 (10:36 +0100)
Stabilize const for integer {to,from}_{be,le,ne}_bytes methods

All of these functions can be implemented simply and naturally as const functions, e.g. `u32::from_le_bytes` can be implemented as
```rust
(bytes[0] as u32)
    | (bytes[1] as u32) << 8
    | (bytes[2] as u32) << 16
    | (bytes[3] as u32) << 24
```
So stabilizing the constness will not expose that internally they are implemented using transmute which is not const in stable.

1  2 
src/libcore/lib.rs
src/libcore/num/mod.rs

diff --combined src/libcore/lib.rs
index 81a3c419db86fe005a994a2928b0a59ff9ece45a,00909094cd0f50b3ffd8fa48d763a36afb28dd41..f4874c772135e0c0d73c72754efbfee6245da6ca
@@@ -90,6 -90,7 +90,6 @@@
  #![feature(custom_inner_attributes)]
  #![feature(decl_macro)]
  #![feature(doc_cfg)]
 -#![feature(doc_spotlight)]
  #![feature(extern_types)]
  #![feature(fundamental)]
  #![feature(intrinsics)]
  #![feature(rtm_target_feature)]
  #![feature(f16c_target_feature)]
  #![feature(hexagon_target_feature)]
- #![feature(const_int_conversion)]
  #![feature(const_transmute)]
  #![feature(structural_match)]
  #![feature(abi_unadjusted)]
  #![feature(associated_type_bounds)]
  #![feature(const_type_id)]
  #![feature(const_caller_location)]
 -#![feature(assoc_int_consts)]
  #![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303
  
  #[prelude_import]
@@@ -157,6 -158,10 +156,6 @@@ mod internal_macros
  #[macro_use]
  mod int_macros;
  
 -#[path = "num/uint_macros.rs"]
 -#[macro_use]
 -mod uint_macros;
 -
  #[path = "num/i128.rs"]
  pub mod i128;
  #[path = "num/i16.rs"]
@@@ -261,9 -266,6 +260,9 @@@ mod bool
  mod tuple;
  mod unit;
  
 +#[stable(feature = "core_primitive", since = "1.43.0")]
 +pub mod primitive;
 +
  // Pull in the `core_arch` crate directly into libcore. The contents of
  // `core_arch` are in a different repository: rust-lang/stdarch.
  //
diff --combined src/libcore/num/mod.rs
index 889ce2f211e14229f079e477e97207cb1ba9e24f,b64abc319360eb27b903631dca70977a4996c33a..caffa6c509aaa5071dcfd1ce9c9249a42c73c64f
@@@ -266,10 -266,11 +266,10 @@@ macro_rules! int_impl 
  Basic usage:
  
  ```
 -#![feature(assoc_int_consts)]
  ", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");",
  $EndFeature, "
  ```"),
 -            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
 +            #[stable(feature = "assoc_int_consts", since = "1.43.0")]
              pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
          }
  
  Basic usage:
  
  ```
 -#![feature(assoc_int_consts)]
  ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");",
  $EndFeature, "
  ```"),
 -            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
 +            #[stable(feature = "assoc_int_consts", since = "1.43.0")]
              pub const MAX: Self = !Self::MIN;
          }
  
 -        doc_comment! {
 -            "Returns the smallest value that can be represented by this integer type.",
 -            #[stable(feature = "rust1", since = "1.0.0")]
 -            #[inline(always)]
 -            #[rustc_promotable]
 -            #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
 -            pub const fn min_value() -> Self {
 -                Self::MIN
 -            }
 -        }
 -
 -        doc_comment! {
 -            "Returns the largest value that can be represented by this integer type.",
 -            #[stable(feature = "rust1", since = "1.0.0")]
 -            #[inline(always)]
 -            #[rustc_promotable]
 -            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 -            pub const fn max_value() -> Self {
 -                Self::MAX
 -            }
 -        }
 -
          doc_comment! {
              concat!("Converts a string slice in a given base to an integer.
  
@@@ -345,7 -369,7 +345,7 @@@ $EndFeature, 
  Basic usage:
  
  ```
 -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, "
 +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 1);", $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
              #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
@@@ -682,8 -706,8 +682,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!((", stringify!($SelfT),
 -"::max_value() - 2).checked_add(1), Some(", stringify!($SelfT), "::max_value() - 1));
 -assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);",
 +"::MAX - 2).checked_add(1), Some(", stringify!($SelfT), "::MAX - 1));
 +assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -707,8 -731,8 +707,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!((", stringify!($SelfT),
 -"::min_value() + 2).checked_sub(1), Some(", stringify!($SelfT), "::min_value() + 1));
 -assert_eq!((", stringify!($SelfT), "::min_value() + 2).checked_sub(3), None);",
 +"::MIN + 2).checked_sub(1), Some(", stringify!($SelfT), "::MIN + 1));
 +assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(3), None);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -732,8 -756,8 +732,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(", stringify!($SelfT),
 -"::max_value().checked_mul(1), Some(", stringify!($SelfT), "::max_value()));
 -assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);",
 +"::MAX.checked_mul(1), Some(", stringify!($SelfT), "::MAX));
 +assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -757,8 -781,8 +757,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!((", stringify!($SelfT),
 -"::min_value() + 1).checked_div(-1), Some(", stringify!($Max), "));
 -assert_eq!(", stringify!($SelfT), "::min_value().checked_div(-1), None);
 +"::MIN + 1).checked_div(-1), Some(", stringify!($Max), "));
 +assert_eq!(", stringify!($SelfT), "::MIN.checked_div(-1), None);
  assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);",
  $EndFeature, "
  ```"),
@@@ -787,8 -811,8 +787,8 @@@ Basic usage
  
  ```
  assert_eq!((", stringify!($SelfT),
 -"::min_value() + 1).checked_div_euclid(-1), Some(", stringify!($Max), "));
 -assert_eq!(", stringify!($SelfT), "::min_value().checked_div_euclid(-1), None);
 +"::MIN + 1).checked_div_euclid(-1), Some(", stringify!($Max), "));
 +assert_eq!(", stringify!($SelfT), "::MIN.checked_div_euclid(-1), None);
  assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);
  ```"),
              #[stable(feature = "euclidean_division", since = "1.38.0")]
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".checked_rem(2), Some(1));
  assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);
  assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);",
@@@ -844,6 -869,8 +844,6 @@@ if `rhs == 0` or the division results i
  Basic usage:
  
  ```
 -use std::", stringify!($SelfT), ";
 -
  assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));
  assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);
  assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".checked_neg(), Some(-5));
  assert_eq!(", stringify!($SelfT), "::MIN.checked_neg(), None);",
  $EndFeature, "
@@@ -941,7 -969,8 +941,7 @@@ $EndFeature, 
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!((-5", stringify!($SelfT), ").checked_abs(), Some(5));
  assert_eq!(", stringify!($SelfT), "::MIN.checked_abs(), None);",
  $EndFeature, "
@@@ -968,7 -997,7 +968,7 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));
 -assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);",
 +assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);",
  $EndFeature, "
  ```"),
  
@@@ -1010,10 -1039,10 +1010,10 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101);
 -assert_eq!(", stringify!($SelfT), "::max_value().saturating_add(100), ", stringify!($SelfT),
 -"::max_value());
 -assert_eq!(", stringify!($SelfT), "::min_value().saturating_add(-1), ", stringify!($SelfT),
 -"::min_value());",
 +assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(100), ", stringify!($SelfT),
 +"::MAX);
 +assert_eq!(", stringify!($SelfT), "::MIN.saturating_add(-1), ", stringify!($SelfT),
 +"::MIN);",
  $EndFeature, "
  ```"),
  
@@@ -1037,10 -1066,10 +1037,10 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".saturating_sub(127), -27);
 -assert_eq!(", stringify!($SelfT), "::min_value().saturating_sub(100), ", stringify!($SelfT),
 -"::min_value());
 -assert_eq!(", stringify!($SelfT), "::max_value().saturating_sub(-1), ", stringify!($SelfT),
 -"::max_value());",
 +assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub(100), ", stringify!($SelfT),
 +"::MIN);
 +assert_eq!(", stringify!($SelfT), "::MAX.saturating_sub(-1), ", stringify!($SelfT),
 +"::MAX);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -1065,10 -1094,10 +1065,10 @@@ Basic usage
  ", $Feature, "#![feature(saturating_neg)]
  assert_eq!(100", stringify!($SelfT), ".saturating_neg(), -100);
  assert_eq!((-100", stringify!($SelfT), ").saturating_neg(), 100);
 -assert_eq!(", stringify!($SelfT), "::min_value().saturating_neg(), ", stringify!($SelfT),
 -"::max_value());
 -assert_eq!(", stringify!($SelfT), "::max_value().saturating_neg(), ", stringify!($SelfT),
 -"::min_value() + 1);",
 +assert_eq!(", stringify!($SelfT), "::MIN.saturating_neg(), ", stringify!($SelfT),
 +"::MAX);
 +assert_eq!(", stringify!($SelfT), "::MAX.saturating_neg(), ", stringify!($SelfT),
 +"::MIN + 1);",
  $EndFeature, "
  ```"),
  
@@@ -1092,10 -1121,10 +1092,10 @@@ Basic usage
  ", $Feature, "#![feature(saturating_neg)]
  assert_eq!(100", stringify!($SelfT), ".saturating_abs(), 100);
  assert_eq!((-100", stringify!($SelfT), ").saturating_abs(), 100);
 -assert_eq!(", stringify!($SelfT), "::min_value().saturating_abs(), ", stringify!($SelfT),
 -"::max_value());
 -assert_eq!((", stringify!($SelfT), "::min_value() + 1).saturating_abs(), ", stringify!($SelfT),
 -"::max_value());",
 +assert_eq!(", stringify!($SelfT), "::MIN.saturating_abs(), ", stringify!($SelfT),
 +"::MAX);
 +assert_eq!((", stringify!($SelfT), "::MIN + 1).saturating_abs(), ", stringify!($SelfT),
 +"::MAX);",
  $EndFeature, "
  ```"),
  
@@@ -1120,7 -1149,8 +1120,7 @@@ numeric bounds instead of overflowing
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(10", stringify!($SelfT), ".saturating_mul(12), 120);
  assert_eq!(", stringify!($SelfT), "::MAX.saturating_mul(10), ", stringify!($SelfT), "::MAX);
  assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($SelfT), "::MIN);",
@@@ -1152,7 -1182,8 +1152,7 @@@ saturating at the numeric bounds instea
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);
  assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);
  assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);",
@@@ -1182,8 -1213,8 +1182,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_add(27), 127);
 -assert_eq!(", stringify!($SelfT), "::max_value().wrapping_add(2), ", stringify!($SelfT),
 -"::min_value() + 1);",
 +assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add(2), ", stringify!($SelfT),
 +"::MIN + 1);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -1206,8 -1237,8 +1206,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(0", stringify!($SelfT), ".wrapping_sub(127), -127);
 -assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::max_value()), ",
 -stringify!($SelfT), "::max_value());",
 +assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::MAX), ",
 +stringify!($SelfT), "::MAX);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -1378,8 -1409,8 +1378,8 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_neg(), -100);
 -assert_eq!(", stringify!($SelfT), "::min_value().wrapping_neg(), ", stringify!($SelfT),
 -"::min_value());",
 +assert_eq!(", stringify!($SelfT), "::MIN.wrapping_neg(), ", stringify!($SelfT),
 +"::MIN);",
  $EndFeature, "
  ```"),
              #[stable(feature = "num_wrapping", since = "1.2.0")]
@@@ -1469,8 -1500,8 +1469,8 @@@ Basic usage
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_abs(), 100);
  assert_eq!((-100", stringify!($SelfT), ").wrapping_abs(), 100);
 -assert_eq!(", stringify!($SelfT), "::min_value().wrapping_abs(), ", stringify!($SelfT),
 -"::min_value());
 +assert_eq!(", stringify!($SelfT), "::MIN.wrapping_abs(), ", stringify!($SelfT),
 +"::MIN);
  assert_eq!((-128i8).wrapping_abs() as u8, 128);",
  $EndFeature, "
  ```"),
@@@ -1541,7 -1572,8 +1541,7 @@@ occur. If an overflow would have occurr
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));
  assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (", stringify!($SelfT),
  "::MIN, true));", $EndFeature, "
@@@ -1568,7 -1600,8 +1568,7 @@@ would occur. If an overflow would have 
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_sub(1), (", stringify!($SelfT),
  "::MAX, true));", $EndFeature, "
@@@ -1625,7 -1658,8 +1625,7 @@@ This function will panic if `rhs` is 0
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div(-1), (", stringify!($SelfT),
  "::MIN, true));",
@@@ -1660,6 -1694,8 +1660,6 @@@ This function will panic if `rhs` is 0
  Basic usage:
  
  ```
 -use std::", stringify!($SelfT), ";
 -
  assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringify!($SelfT),
  "::MIN, true));
@@@ -1693,7 -1729,8 +1693,7 @@@ This function will panic if `rhs` is 0
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem(-1), (0, true));",
  $EndFeature, "
@@@ -1728,6 -1765,8 +1728,6 @@@ This function will panic if `rhs` is 0
  Basic usage:
  
  ```
 -use std::", stringify!($SelfT), ";
 -
  assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));
  ```"),
@@@ -1758,6 -1797,8 +1758,6 @@@ minimum value will be returned again an
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
  assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2, false));
  assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($SelfT),
  "::MIN, true));", $EndFeature, "
@@@ -1843,8 -1884,8 +1843,8 @@@ Basic usage
  ```
  ", $Feature, "assert_eq!(10", stringify!($SelfT), ".overflowing_abs(), (10, false));
  assert_eq!((-10", stringify!($SelfT), ").overflowing_abs(), (10, false));
 -assert_eq!((", stringify!($SelfT), "::min_value()).overflowing_abs(), (", stringify!($SelfT),
 -"::min_value(), true));",
 +assert_eq!((", stringify!($SelfT), "::MIN).overflowing_abs(), (", stringify!($SelfT),
 +"::MIN, true));",
  $EndFeature, "
  ```"),
              #[stable(feature = "no_panic_abs", since = "1.13.0")]
@@@ -2042,10 -2083,10 +2042,10 @@@ assert_eq!((-a).rem_euclid(-b), 1)
  
  # Overflow behavior
  
 -The absolute value of `", stringify!($SelfT), "::min_value()` cannot be represented as an
 +The absolute value of `", stringify!($SelfT), "::MIN` cannot be represented as an
  `", stringify!($SelfT), "`, and attempting to calculate it will cause an overflow. This means that
  code in debug mode will trigger a panic on this case and optimized code will return `",
 -stringify!($SelfT), "::min_value()` without a panic.
 +stringify!($SelfT), "::MIN` without a panic.
  
  # Examples
  
@@@ -2154,7 -2195,7 +2154,7 @@@ let bytes = ", $swap_op, stringify!($Se
  assert_eq!(bytes, ", $be_bytes, ");
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
                  self.to_be().to_ne_bytes()
@@@ -2174,7 -2215,7 +2174,7 @@@ let bytes = ", $swap_op, stringify!($Se
  assert_eq!(bytes, ", $le_bytes, ");
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
                  self.to_le().to_ne_bytes()
@@@ -2209,12 -2250,20 +2209,20 @@@ assert_eq!
  );
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+             // SAFETY: const sound because integers are plain old datatypes so we can always
+             // transmute them to arrays of bytes
+             #[allow_internal_unstable(const_fn_union)]
              #[inline]
              pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
+                 #[repr(C)]
+                 union Bytes {
+                     val: $SelfT,
+                     bytes: [u8; mem::size_of::<$SelfT>()],
+                 }
                  // SAFETY: integers are plain old datatypes so we can always transmute them to
                  // arrays of bytes
-                 unsafe { mem::transmute(self) }
+                 unsafe { Bytes { val: self }.bytes }
              }
          }
  
@@@ -2243,7 -2292,7 +2251,7 @@@ fn read_be_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
                  Self::from_be(Self::from_ne_bytes(bytes))
@@@ -2276,7 -2325,7 +2284,7 @@@ fn read_le_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
                  Self::from_le(Self::from_ne_bytes(bytes))
@@@ -2319,45 -2368,21 +2327,53 @@@ fn read_ne_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+             // SAFETY: const sound because integers are plain old datatypes so we can always
+             // transmute to them
+             #[allow_internal_unstable(const_fn_union)]
              #[inline]
              pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+                 #[repr(C)]
+                 union Bytes {
+                     val: $SelfT,
+                     bytes: [u8; mem::size_of::<$SelfT>()],
+                 }
                  // SAFETY: integers are plain old datatypes so we can always transmute to them
-                 unsafe { mem::transmute(bytes) }
+                 unsafe { Bytes { bytes }.val }
              }
          }
 +
 +        doc_comment! {
 +            concat!("**This method is soft-deprecated.**
 +
 +Although using it won’t cause compilation warning,
 +new code should use [`", stringify!($SelfT), "::MIN", "`](#associatedconstant.MIN) instead.
 +
 +Returns the smallest value that can be represented by this integer type."),
 +            #[stable(feature = "rust1", since = "1.0.0")]
 +            #[inline(always)]
 +            #[rustc_promotable]
 +            #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
 +            pub const fn min_value() -> Self {
 +                Self::MIN
 +            }
 +        }
 +
 +        doc_comment! {
 +            concat!("**This method is soft-deprecated.**
 +
 +Although using it won’t cause compilation warning,
 +new code should use [`", stringify!($SelfT), "::MAX", "`](#associatedconstant.MAX) instead.
 +
 +Returns the largest value that can be represented by this integer type."),
 +            #[stable(feature = "rust1", since = "1.0.0")]
 +            #[inline(always)]
 +            #[rustc_promotable]
 +            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 +            pub const fn max_value() -> Self {
 +                Self::MAX
 +            }
 +        }
      }
  }
  
@@@ -2440,9 -2465,10 +2456,9 @@@ macro_rules! uint_impl 
  Basic usage:
  
  ```
 -#![feature(assoc_int_consts)]
  ", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, 0);", $EndFeature, "
  ```"),
 -            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
 +            #[stable(feature = "assoc_int_consts", since = "1.43.0")]
              pub const MIN: Self = 0;
          }
  
  Basic usage:
  
  ```
 -#![feature(assoc_int_consts)]
  ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");",
  $EndFeature, "
  ```"),
 -            #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
 +            #[stable(feature = "assoc_int_consts", since = "1.43.0")]
              pub const MAX: Self = !0;
          }
  
 -        doc_comment! {
 -            "Returns the smallest value that can be represented by this integer type.",
 -            #[stable(feature = "rust1", since = "1.0.0")]
 -            #[rustc_promotable]
 -            #[inline(always)]
 -            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 -            pub const fn min_value() -> Self { Self::MIN }
 -        }
 -
 -        doc_comment! {
 -            "Returns the largest value that can be represented by this integer type.",
 -            #[stable(feature = "rust1", since = "1.0.0")]
 -            #[rustc_promotable]
 -            #[inline(always)]
 -            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 -            pub const fn max_value() -> Self { Self::MAX }
 -        }
 -
          doc_comment! {
              concat!("Converts a string slice in a given base to an integer.
  
@@@ -2519,7 -2564,7 +2535,7 @@@ assert_eq!(n.count_ones(), 3);", $EndFe
  Basic usage:
  
  ```
 -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, "
 +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 0);", $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
              #[rustc_const_stable(feature = "const_math", since = "1.32.0")]
  Basic usage:
  
  ```
 -", $Feature, "let n = ", stringify!($SelfT), "::max_value() >> 2;
 +", $Feature, "let n = ", stringify!($SelfT), "::MAX >> 2;
  
  assert_eq!(n.leading_zeros(), 2);", $EndFeature, "
  ```"),
@@@ -2579,7 -2624,7 +2595,7 @@@ Basic usage
  
  ```
  ", $Feature, "#![feature(leading_trailing_ones)]
 -let n = !(", stringify!($SelfT), "::max_value() >> 2);
 +let n = !(", stringify!($SelfT), "::MAX >> 2);
  
  assert_eq!(n.leading_ones(), 2);", $EndFeature, "
  ```"),
@@@ -2853,9 -2898,9 +2869,9 @@@ if overflow occurred
  Basic usage:
  
  ```
 -", $Feature, "assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(1), ",
 -"Some(", stringify!($SelfT), "::max_value() - 1));
 -assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);", $EndFeature, "
 +", $Feature, "assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(1), ",
 +"Some(", stringify!($SelfT), "::MAX - 1));
 +assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
              #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")]
@@@ -2901,7 -2946,7 +2917,7 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(5", stringify!($SelfT), ".checked_mul(1), Some(5));
 -assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);", $EndFeature, "
 +assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
              #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")]
@@@ -3101,7 -3146,7 +3117,7 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32));
 -assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);", $EndFeature, "
 +assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);", $EndFeature, "
  ```"),
              #[stable(feature = "no_panic_pow", since = "1.34.0")]
              #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")]
@@@ -3185,7 -3230,8 +3201,7 @@@ saturating at the numeric bounds instea
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(2", stringify!($SelfT), ".saturating_mul(10), 20);
  assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($SelfT),
  "::MAX);", $EndFeature, "
@@@ -3212,7 -3258,8 +3228,7 @@@ saturating at the numeric bounds instea
  Basic usage:
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(4", stringify!($SelfT), ".saturating_pow(3), 64);
  assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);",
  $EndFeature, "
@@@ -3240,7 -3287,7 +3256,7 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(200", stringify!($SelfT), ".wrapping_add(55), 255);
 -assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::max_value()), 199);",
 +assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::MAX), 199);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -3263,7 -3310,7 +3279,7 @@@ Basic usage
  
  ```
  ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_sub(100), 0);
 -assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::max_value()), 101);",
 +assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::MAX), 101);",
  $EndFeature, "
  ```"),
              #[stable(feature = "rust1", since = "1.0.0")]
@@@ -3551,7 -3598,8 +3567,7 @@@ have occurred then the wrapped value i
  Basic usage
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));
  assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));", $EndFeature, "
  ```"),
@@@ -3578,7 -3626,8 +3594,7 @@@ have occurred then the wrapped value i
  Basic usage
  
  ```
 -", $Feature, "use std::", stringify!($SelfT), ";
 -
 +", $Feature, "
  assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));
  assert_eq!(0", stringify!($SelfT), ".overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));",
  $EndFeature, "
@@@ -4050,7 -4099,7 +4066,7 @@@ Basic usage
  ", $Feature, "assert_eq!(2", stringify!($SelfT),
  ".checked_next_power_of_two(), Some(2));
  assert_eq!(3", stringify!($SelfT), ".checked_next_power_of_two(), Some(4));
 -assert_eq!(", stringify!($SelfT), "::max_value().checked_next_power_of_two(), None);",
 +assert_eq!(", stringify!($SelfT), "::MAX.checked_next_power_of_two(), None);",
  $EndFeature, "
  ```"),
              #[inline]
@@@ -4075,7 -4124,7 +4091,7 @@@ Basic usage
  ", $Feature, "
  assert_eq!(2", stringify!($SelfT), ".wrapping_next_power_of_two(), 2);
  assert_eq!(3", stringify!($SelfT), ".wrapping_next_power_of_two(), 4);
 -assert_eq!(", stringify!($SelfT), "::max_value().wrapping_next_power_of_two(), 0);",
 +assert_eq!(", stringify!($SelfT), "::MAX.wrapping_next_power_of_two(), 0);",
  $EndFeature, "
  ```"),
              #[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
@@@ -4099,7 -4148,7 +4115,7 @@@ let bytes = ", $swap_op, stringify!($Se
  assert_eq!(bytes, ", $be_bytes, ");
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
                  self.to_be().to_ne_bytes()
@@@ -4119,7 -4168,7 +4135,7 @@@ let bytes = ", $swap_op, stringify!($Se
  assert_eq!(bytes, ", $le_bytes, ");
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
                  self.to_le().to_ne_bytes()
@@@ -4154,12 -4203,20 +4170,20 @@@ assert_eq!
  );
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+             // SAFETY: const sound because integers are plain old datatypes so we can always
+             // transmute them to arrays of bytes
+             #[allow_internal_unstable(const_fn_union)]
              #[inline]
              pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
+                 #[repr(C)]
+                 union Bytes {
+                     val: $SelfT,
+                     bytes: [u8; mem::size_of::<$SelfT>()],
+                 }
                  // SAFETY: integers are plain old datatypes so we can always transmute them to
                  // arrays of bytes
-                 unsafe { mem::transmute(self) }
+                 unsafe { Bytes { val: self }.bytes }
              }
          }
  
@@@ -4188,7 -4245,7 +4212,7 @@@ fn read_be_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
                  Self::from_be(Self::from_ne_bytes(bytes))
@@@ -4221,7 -4278,7 +4245,7 @@@ fn read_le_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
              #[inline]
              pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
                  Self::from_le(Self::from_ne_bytes(bytes))
@@@ -4264,41 -4321,21 +4288,49 @@@ fn read_ne_", stringify!($SelfT), "(inp
  }
  ```"),
              #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
-             #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+             #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+             // SAFETY: const sound because integers are plain old datatypes so we can always
+             // transmute to them
+             #[allow_internal_unstable(const_fn_union)]
              #[inline]
              pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+                 #[repr(C)]
+                 union Bytes {
+                     val: $SelfT,
+                     bytes: [u8; mem::size_of::<$SelfT>()],
+                 }
                  // SAFETY: integers are plain old datatypes so we can always transmute to them
-                 unsafe { mem::transmute(bytes) }
+                 unsafe { Bytes { bytes }.val }
              }
          }
 +
 +        doc_comment! {
 +            concat!("**This method is soft-deprecated.**
 +
 +Although using it won’t cause compilation warning,
 +new code should use [`", stringify!($SelfT), "::MIN", "`](#associatedconstant.MIN) instead.
 +
 +Returns the smallest value that can be represented by this integer type."),
 +            #[stable(feature = "rust1", since = "1.0.0")]
 +            #[rustc_promotable]
 +            #[inline(always)]
 +            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 +            pub const fn min_value() -> Self { Self::MIN }
 +        }
 +
 +        doc_comment! {
 +            concat!("**This method is soft-deprecated.**
 +
 +Although using it won’t cause compilation warning,
 +new code should use [`", stringify!($SelfT), "::MAX", "`](#associatedconstant.MAX) instead.
 +
 +Returns the largest value that can be represented by this integer type."),
 +            #[stable(feature = "rust1", since = "1.0.0")]
 +            #[rustc_promotable]
 +            #[inline(always)]
 +            #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
 +            pub const fn max_value() -> Self { Self::MAX }
 +        }
      }
  }
  
@@@ -4319,9 -4356,8 +4351,9 @@@ impl u8 
      /// assert!(!non_ascii.is_ascii());
      /// ```
      #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
 +    #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.43.0")]
      #[inline]
 -    pub fn is_ascii(&self) -> bool {
 +    pub const fn is_ascii(&self) -> bool {
          *self & 128 == 0
      }
  
@@@ -4871,6 -4907,7 +4903,6 @@@ impl usize 
  ///
  /// ```
  /// use std::num::FpCategory;
 -/// use std::f32;
  ///
  /// let num = 12.4_f32;
  /// let inf = f32::INFINITY;