From 1b9ab8939efc1a38a7a5398a069517466fd88d38 Mon Sep 17 00:00:00 2001 From: Linus Färnstrand Date: Tue, 29 May 2018 11:42:13 +0200 Subject: Make most integer operations const fns --- src/libcore/num/mod.rs | 154 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 40 deletions(-) (limited to 'src/libcore/num') diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index ea652ad811e..60fdd4a3642 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -267,8 +267,9 @@ $EndFeature, " ``` "), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } + pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } } doc_comment! { @@ -282,8 +283,9 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn count_zeros(self) -> u32 { + pub const fn count_zeros(self) -> u32 { (!self).count_ones() } } @@ -302,8 +304,9 @@ assert_eq!(n.leading_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { (self as $UnsignedT).leading_zeros() } } @@ -322,8 +325,9 @@ assert_eq!(n.trailing_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn trailing_zeros(self) -> u32 { + pub const fn trailing_zeros(self) -> u32 { (self as $UnsignedT).trailing_zeros() } } @@ -396,8 +400,9 @@ $EndFeature, " /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn swap_bytes(self) -> Self { + pub const fn swap_bytes(self) -> Self { (self as $UnsignedT).swap_bytes() as Self } @@ -447,9 +452,17 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn from_be(x: Self) -> Self { - if cfg!(target_endian = "big") { x } else { x.swap_bytes() } + pub const fn from_be(x: Self) -> Self { + #[cfg(target_endian = "big")] + { + x + } + #[cfg(not(target_endian = "big"))] + { + x.swap_bytes() + } } } @@ -473,9 +486,17 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn from_le(x: Self) -> Self { - if cfg!(target_endian = "little") { x } else { x.swap_bytes() } + pub const fn from_le(x: Self) -> Self { + #[cfg(target_endian = "little")] + { + x + } + #[cfg(not(target_endian = "little"))] + { + x.swap_bytes() + } } } @@ -499,9 +520,17 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn to_be(self) -> Self { // or not to be? - if cfg!(target_endian = "big") { self } else { self.swap_bytes() } + pub const fn to_be(self) -> Self { // or not to be? + #[cfg(target_endian = "big")] + { + self + } + #[cfg(not(target_endian = "big"))] + { + self.swap_bytes() + } } } @@ -525,9 +554,17 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn to_le(self) -> Self { - if cfg!(target_endian = "little") { self } else { self.swap_bytes() } + pub const fn to_le(self) -> Self { + #[cfg(target_endian = "little")] + { + self + } + #[cfg(not(target_endian = "little"))] + { + self.swap_bytes() + } } } @@ -1943,6 +1980,19 @@ impl isize { int_impl! { isize, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "" } } +// Emits the correct `cttz` call, depending on the size of the type. +macro_rules! uint_cttz_call { + // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic + // emits two conditional moves on x86_64. By promoting the value to + // u16 and setting bit 8, we get better code without any conditional + // operations. + // FIXME: There's a LLVM patch (http://reviews.llvm.org/D9284) + // pending, remove this workaround once LLVM generates better code + // for cttz8. + ($value:expr, 8) => { intrinsics::cttz($value as u16 | 0x100) }; + ($value:expr, $_BITS:expr) => { intrinsics::cttz($value) } +} + // `Int` + `UnsignedInt` implemented for unsigned integers macro_rules! uint_impl { ($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr) => { @@ -2020,8 +2070,9 @@ Basic usage: assert_eq!(n.count_ones(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn count_ones(self) -> u32 { + pub const fn count_ones(self) -> u32 { unsafe { intrinsics::ctpop(self as $ActualT) as u32 } } } @@ -2037,8 +2088,9 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn count_zeros(self) -> u32 { + pub const fn count_zeros(self) -> u32 { (!self).count_ones() } } @@ -2056,8 +2108,9 @@ Basic usage: assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn leading_zeros(self) -> u32 { + pub const fn leading_zeros(self) -> u32 { unsafe { intrinsics::ctlz(self as $ActualT) as u32 } } } @@ -2076,22 +2129,10 @@ Basic usage: assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn trailing_zeros(self) -> u32 { - // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic - // emits two conditional moves on x86_64. By promoting the value to - // u16 and setting bit 8, we get better code without any conditional - // operations. - // FIXME: There's a LLVM patch (http://reviews.llvm.org/D9284) - // pending, remove this workaround once LLVM generates better code - // for cttz8. - unsafe { - if $BITS == 8 { - intrinsics::cttz(self as u16 | 0x100) as u32 - } else { - intrinsics::cttz(self) as u32 - } - } + pub const fn trailing_zeros(self) -> u32 { + unsafe { uint_cttz_call!(self, $BITS) as u32 } } } @@ -2167,8 +2208,9 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn swap_bytes(self) -> Self { + pub const fn swap_bytes(self) -> Self { unsafe { intrinsics::bswap(self as $ActualT) as Self } } @@ -2218,9 +2260,17 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn from_be(x: Self) -> Self { - if cfg!(target_endian = "big") { x } else { x.swap_bytes() } + pub const fn from_be(x: Self) -> Self { + #[cfg(target_endian = "big")] + { + x + } + #[cfg(not(target_endian = "big"))] + { + x.swap_bytes() + } } } @@ -2244,9 +2294,17 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn from_le(x: Self) -> Self { - if cfg!(target_endian = "little") { x } else { x.swap_bytes() } + pub const fn from_le(x: Self) -> Self { + #[cfg(target_endian = "little")] + { + x + } + #[cfg(not(target_endian = "little"))] + { + x.swap_bytes() + } } } @@ -2270,9 +2328,17 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn to_be(self) -> Self { // or not to be? - if cfg!(target_endian = "big") { self } else { self.swap_bytes() } + pub const fn to_be(self) -> Self { // or not to be? + #[cfg(target_endian = "big")] + { + self + } + #[cfg(not(target_endian = "big"))] + { + self.swap_bytes() + } } } @@ -2296,9 +2362,17 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] #[inline] - pub fn to_le(self) -> Self { - if cfg!(target_endian = "little") { self } else { self.swap_bytes() } + pub const fn to_le(self) -> Self { + #[cfg(target_endian = "little")] + { + self + } + #[cfg(not(target_endian = "little"))] + { + self.swap_bytes() + } } } -- cgit 1.4.1-3-g733a5 From 8a27c19c92b293051bd5fa8c3bd18082d8d7dd51 Mon Sep 17 00:00:00 2001 From: Linus Färnstrand Date: Sat, 2 Jun 2018 11:24:32 +0200 Subject: Make integer methods non-const in stage0 --- src/libcore/num/mod.rs | 192 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) (limited to 'src/libcore/num') diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 60fdd4a3642..26dd08b10b9 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -267,11 +267,20 @@ $EndFeature, " ``` "), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } + } + doc_comment! { concat!("Returns the number of zeros in the binary representation of `self`. @@ -283,6 +292,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn count_zeros(self) -> u32 { @@ -290,6 +300,16 @@ Basic usage: } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentatio"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn count_zeros(self) -> u32 { + (!self).count_ones() + } + } + doc_comment! { concat!("Returns the number of leading zeros in the binary representation of `self`. @@ -304,6 +324,7 @@ assert_eq!(n.leading_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn leading_zeros(self) -> u32 { @@ -311,6 +332,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn leading_zeros(self) -> u32 { + (self as $UnsignedT).leading_zeros() + } + } + doc_comment! { concat!("Returns the number of trailing zeros in the binary representation of `self`. @@ -325,6 +356,7 @@ assert_eq!(n.trailing_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn trailing_zeros(self) -> u32 { @@ -332,6 +364,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn trailing_zeros(self) -> u32 { + (self as $UnsignedT).trailing_zeros() + } + } + /// Shifts the bits to the left by a specified amount, `n`, /// wrapping the truncated bits to the end of the resulting integer. /// @@ -400,12 +442,21 @@ $EndFeature, " /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn swap_bytes(self) -> Self { (self as $UnsignedT).swap_bytes() as Self } + /// Dummy docs. See !stage0 documentation. + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn swap_bytes(self) -> Self { + (self as $UnsignedT).swap_bytes() as Self + } + /// Reverses the bit pattern of the integer. /// /// # Examples @@ -452,6 +503,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn from_be(x: Self) -> Self { @@ -466,6 +518,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn from_be(x: Self) -> Self { + if cfg!(target_endian = "big") { x } else { x.swap_bytes() } + } + } + doc_comment! { concat!("Converts an integer from little endian to the target's endianness. @@ -486,6 +548,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn from_le(x: Self) -> Self { @@ -500,6 +563,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn from_le(x: Self) -> Self { + if cfg!(target_endian = "little") { x } else { x.swap_bytes() } + } + } + doc_comment! { concat!("Converts `self` to big endian from the target's endianness. @@ -520,6 +593,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn to_be(self) -> Self { // or not to be? @@ -534,6 +608,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn to_be(self) -> Self { // or not to be? + if cfg!(target_endian = "big") { self } else { self.swap_bytes() } + } + } + doc_comment! { concat!("Converts `self` to little endian from the target's endianness. @@ -554,6 +638,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn to_le(self) -> Self { @@ -568,6 +653,16 @@ $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn to_le(self) -> Self { + if cfg!(target_endian = "little") { self } else { self.swap_bytes() } + } + } + doc_comment! { concat!("Checked integer addition. Computes `self + rhs`, returning `None` if overflow occurred. @@ -2070,6 +2165,7 @@ Basic usage: assert_eq!(n.count_ones(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn count_ones(self) -> u32 { @@ -2077,6 +2173,16 @@ assert_eq!(n.count_ones(), 3);", $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn count_ones(self) -> u32 { + unsafe { intrinsics::ctpop(self as $ActualT) as u32 } + } + } + doc_comment! { concat!("Returns the number of zeros in the binary representation of `self`. @@ -2088,6 +2194,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn count_zeros(self) -> u32 { @@ -2095,6 +2202,16 @@ Basic usage: } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn count_zeros(self) -> u32 { + (!self).count_ones() + } + } + doc_comment! { concat!("Returns the number of leading zeros in the binary representation of `self`. @@ -2108,6 +2225,7 @@ Basic usage: assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn leading_zeros(self) -> u32 { @@ -2115,6 +2233,16 @@ assert_eq!(n.leading_zeros(), 2);", $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn leading_zeros(self) -> u32 { + unsafe { intrinsics::ctlz(self as $ActualT) as u32 } + } + } + doc_comment! { concat!("Returns the number of trailing zeros in the binary representation of `self`. @@ -2129,6 +2257,7 @@ Basic usage: assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn trailing_zeros(self) -> u32 { @@ -2136,6 +2265,16 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn trailing_zeros(self) -> u32 { + unsafe { uint_cttz_call!(self, $BITS) as u32 } + } + } + /// Shifts the bits to the left by a specified amount, `n`, /// wrapping the truncated bits to the end of the resulting integer. /// @@ -2208,12 +2347,21 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn swap_bytes(self) -> Self { unsafe { intrinsics::bswap(self as $ActualT) as Self } } + /// Dummy docs. See !stage0 documentation. + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn swap_bytes(self) -> Self { + unsafe { intrinsics::bswap(self as $ActualT) as Self } + } + /// Reverses the bit pattern of the integer. /// /// # Examples @@ -2260,6 +2408,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn from_be(x: Self) -> Self { @@ -2274,6 +2423,16 @@ if cfg!(target_endian = \"big\") { } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn from_be(x: Self) -> Self { + if cfg!(target_endian = "big") { x } else { x.swap_bytes() } + } + } + doc_comment! { concat!("Converts an integer from little endian to the target's endianness. @@ -2294,6 +2453,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn from_le(x: Self) -> Self { @@ -2308,6 +2468,16 @@ if cfg!(target_endian = \"little\") { } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn from_le(x: Self) -> Self { + if cfg!(target_endian = "little") { x } else { x.swap_bytes() } + } + } + doc_comment! { concat!("Converts `self` to big endian from the target's endianness. @@ -2328,6 +2498,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn to_be(self) -> Self { // or not to be? @@ -2342,6 +2513,16 @@ if cfg!(target_endian = \"big\") { } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn to_be(self) -> Self { // or not to be? + if cfg!(target_endian = "big") { self } else { self.swap_bytes() } + } + } + doc_comment! { concat!("Converts `self` to little endian from the target's endianness. @@ -2362,6 +2543,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_ops")] #[inline] pub const fn to_le(self) -> Self { @@ -2376,6 +2558,16 @@ if cfg!(target_endian = \"little\") { } } + doc_comment! { + concat!("Dummy docs. See !stage0 documentation"), + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] + #[inline] + pub fn to_le(self) -> Self { + if cfg!(target_endian = "little") { self } else { self.swap_bytes() } + } + } + doc_comment! { concat!("Checked integer addition. Computes `self + rhs`, returning `None` if overflow occurred. -- cgit 1.4.1-3-g733a5