}
+ #[stable(feature = "from_nonzero", since = "1.31.0")]
+ impl From<$Ty> for $Int {
+ fn from(nonzero: $Ty) -> Self {
+ nonzero.0 .0
+ }
+ }
+
impl_nonzero_fmt! {
(Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
}
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn rotate_left(self, n: u32) -> Self {
- (self as $UnsignedT).rotate_left(n) as Self
- }
-
doc_comment! {
concat!("Shifts the bits to the left by a specified amount, `n`,
wrapping the truncated bits to the end of the resulting integer.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_rotate")]
#[inline]
- #[cfg(not(stage0))]
pub const fn rotate_left(self, n: u32) -> Self {
(self as $UnsignedT).rotate_left(n) as Self
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn rotate_right(self, n: u32) -> Self {
- (self as $UnsignedT).rotate_right(n) as Self
- }
-
doc_comment! {
concat!("Shifts the bits to the right by a specified amount, `n`,
wrapping the truncated bits to the beginning of the resulting
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_rotate")]
#[inline]
- #[cfg(not(stage0))]
pub const fn rotate_right(self, n: u32) -> Self {
(self as $UnsignedT).rotate_right(n) as Self
}
}
}
- /// no docs here
- #[unstable(feature = "reverse_bits", issue = "48763")]
- #[inline]
- #[cfg(stage0)]
- pub fn reverse_bits(self) -> Self {
- (self as $UnsignedT).reverse_bits() as Self
- }
-
doc_comment! {
concat!("Reverses the bit pattern of the integer.
#[unstable(feature = "reverse_bits", issue = "48763")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn reverse_bits(self) -> Self {
(self as $UnsignedT).reverse_bits() as Self
}
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_add(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_add(self, rhs)
- }
- }
-
doc_comment! {
concat!("Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the
boundary of the type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_add(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_add(self, rhs)
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_sub(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_sub(self, rhs)
- }
- }
-
doc_comment! {
concat!("Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the
boundary of the type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_sub(self, rhs)
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_mul(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_mul(self, rhs)
- }
- }
-
doc_comment! {
concat!("Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at
the boundary of the type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_mul(self, rhs)
}
}
- /// no docs here
- #[stable(feature = "num_wrapping", since = "1.2.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_shl(self, rhs: u32) -> Self {
- unsafe {
- intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
- }
- }
-
doc_comment! {
concat!("Panic-free bitwise shift-left; yields `self << mask(rhs)`, where `mask` removes
any high-order bits of `rhs` that would cause the shift to exceed the bitwidth of the type.
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
}
}
- /// no docs here
- #[stable(feature = "num_wrapping", since = "1.2.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_shr(self, rhs: u32) -> Self {
- unsafe {
- intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
- }
- }
-
doc_comment! {
concat!("Panic-free bitwise shift-right; yields `self >> mask(rhs)`, where `mask`
removes any high-order bits of `rhs` that would cause the shift to exceed the bitwidth of the type.
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_add(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::add_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
doc_comment! {
concat!("Calculates `self` + `rhs`
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::add_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::sub_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
doc_comment! {
concat!("Calculates `self` - `rhs`
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::sub_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::mul_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
doc_comment! {
concat!("Calculates the multiplication of `self` and `rhs`.
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::mul_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
- (self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
- }
-
doc_comment! {
concat!("Shifts self left by `rhs` bits.
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
- (self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
- }
-
doc_comment! {
concat!("Shifts self right by `rhs` bits.
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
}
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn is_positive(self) -> bool { self > 0 }
-
doc_comment! {
concat!("Returns `true` if `self` is positive and `false` if the number is zero or
negative.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_sign")]
#[inline]
- #[cfg(not(stage0))]
pub const fn is_positive(self) -> bool { self > 0 }
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn is_negative(self) -> bool { self < 0 }
-
doc_comment! {
concat!("Returns `true` if `self` is negative and `false` if the number is zero or
positive.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_sign")]
#[inline]
- #[cfg(not(stage0))]
pub const fn is_negative(self) -> bool { self < 0 }
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
- self.to_be().to_ne_bytes()
- }
-
doc_comment! {
concat!("Return the memory representation of this integer as a byte array in
big-endian (network) byte order.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
- self.to_le().to_ne_bytes()
- }
-
doc_comment! {
concat!("Return the memory representation of this integer as a byte array in
little-endian byte order.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
- unsafe { mem::transmute(self) }
- }
-
doc_comment! {
concat!("
Return the memory representation of this integer as a byte array in
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
unsafe { mem::transmute(self) }
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- Self::from_be(Self::from_ne_bytes(bytes))
- }
-
doc_comment! {
concat!("Create an integer value from its representation as a byte array in
big endian.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- Self::from_le(Self::from_ne_bytes(bytes))
- }
-
doc_comment! {
concat!("
Create an integer value from its representation as a byte array in
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- unsafe { mem::transmute(bytes) }
- }
-
doc_comment! {
concat!("Create an integer value from its memory representation as a byte
array in native endianness.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn rotate_left(self, n: u32) -> Self {
- // Protect against undefined behaviour for over-long bit shifts
- let n = n % $BITS;
- (self << n) | (self >> (($BITS - n) % $BITS))
- }
-
doc_comment! {
concat!("Shifts the bits to the left by a specified amount, `n`,
wrapping the truncated bits to the end of the resulting integer.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_rotate")]
#[inline]
- #[cfg(not(stage0))]
pub const fn rotate_left(self, n: u32) -> Self {
(self << (n % $BITS)) | (self >> (($BITS - (n % $BITS)) % $BITS))
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn rotate_right(self, n: u32) -> Self {
- // Protect against undefined behaviour for over-long bit shifts
- let n = n % $BITS;
- (self >> n) | (self << (($BITS - n) % $BITS))
- }
-
doc_comment! {
concat!("Shifts the bits to the right by a specified amount, `n`,
wrapping the truncated bits to the beginning of the resulting
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_rotate")]
#[inline]
- #[cfg(not(stage0))]
pub const fn rotate_right(self, n: u32) -> Self {
(self >> (n % $BITS)) | (self << (($BITS - (n % $BITS)) % $BITS))
}
}
}
- /// no docs here
- #[unstable(feature = "reverse_bits", issue = "48763")]
- #[inline]
- #[cfg(stage0)]
- pub fn reverse_bits(self) -> Self {
- unsafe { intrinsics::bitreverse(self as $ActualT) as Self }
- }
-
doc_comment! {
concat!("Reverses the bit pattern of the integer.
#[unstable(feature = "reverse_bits", issue = "48763")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn reverse_bits(self) -> Self {
unsafe { intrinsics::bitreverse(self as $ActualT) as Self }
}
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_add(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_add(self, rhs)
- }
- }
-
doc_comment! {
concat!("Wrapping (modular) addition. Computes `self + rhs`,
wrapping around at the boundary of the type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_add(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_add(self, rhs)
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_sub(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_sub(self, rhs)
- }
- }
-
doc_comment! {
concat!("Wrapping (modular) subtraction. Computes `self - rhs`,
wrapping around at the boundary of the type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_sub(self, rhs)
}
}
- /// no docs here
- #[stable(feature = "rust1", since = "1.0.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_mul(self, rhs: Self) -> Self {
- unsafe {
- intrinsics::overflowing_mul(self, rhs)
- }
- }
-
/// Wrapping (modular) multiplication. Computes `self *
/// rhs`, wrapping around at the boundary of the type.
///
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
unsafe {
intrinsics::overflowing_mul(self, rhs)
self.overflowing_neg().0
}
- /// no docs here
- #[stable(feature = "num_wrapping", since = "1.2.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_shl(self, rhs: u32) -> Self {
- unsafe {
- intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
- }
- }
-
doc_comment! {
concat!("Panic-free bitwise shift-left; yields `self << mask(rhs)`,
where `mask` removes any high-order bits of `rhs` that
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
}
}
- /// no docs here
- #[stable(feature = "num_wrapping", since = "1.2.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn wrapping_shr(self, rhs: u32) -> Self {
- unsafe {
- intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
- }
- }
-
doc_comment! {
concat!("Panic-free bitwise shift-right; yields `self >> mask(rhs)`,
where `mask` removes any high-order bits of `rhs` that
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[inline]
- #[cfg(not(stage0))]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_add(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::add_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
doc_comment! {
concat!("Calculates `self` + `rhs`
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::add_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::sub_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
doc_comment! {
concat!("Calculates `self` - `rhs`
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::sub_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
- let (a, b) = unsafe {
- intrinsics::mul_with_overflow(self as $ActualT,
- rhs as $ActualT)
- };
- (a as Self, b)
- }
-
/// Calculates the multiplication of `self` and `rhs`.
///
/// Returns a tuple of the multiplication along with a boolean
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
let (a, b) = unsafe {
intrinsics::mul_with_overflow(self as $ActualT,
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
- (self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
- }
-
doc_comment! {
concat!("Shifts self left by `rhs` bits.
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
}
}
- /// no docs here
- #[stable(feature = "wrapping", since = "1.7.0")]
- #[inline]
- #[cfg(stage0)]
- pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
- (self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
- }
-
doc_comment! {
concat!("Shifts self right by `rhs` bits.
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_unstable(feature = "const_int_overflowing")]
#[inline]
- #[cfg(not(stage0))]
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
}
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
- self.to_be().to_ne_bytes()
- }
-
- doc_comment! {
+ doc_comment! {
concat!("Return the memory representation of this integer as a byte array in
big-endian (network) byte order.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
- self.to_le().to_ne_bytes()
- }
-
doc_comment! {
concat!("Return the memory representation of this integer as a byte array in
little-endian byte order.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
- unsafe { mem::transmute(self) }
- }
-
doc_comment! {
concat!("
Return the memory representation of this integer as a byte array in
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
unsafe { mem::transmute(self) }
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- Self::from_be(Self::from_ne_bytes(bytes))
- }
-
doc_comment! {
concat!("Create an integer value from its representation as a byte array in
big endian.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- Self::from_le(Self::from_ne_bytes(bytes))
- }
-
doc_comment! {
concat!("
Create an integer value from its representation as a byte array in
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
}
- /// no docs here
- #[unstable(feature = "int_to_from_bytes", issue = "52963")]
- #[inline]
- #[cfg(stage0)]
- pub fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- unsafe { mem::transmute(bytes) }
- }
-
doc_comment! {
concat!("Create an integer value from its memory representation as a byte
array in native endianness.
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
- #[cfg(not(stage0))]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]
#![feature(exhaustive_patterns)]
- #![cfg_attr(not(stage0), feature(nll))]
+ #![feature(nll)]
#![feature(quote)]
#![feature(refcell_replace_swap)]
#![feature(rustc_diagnostic_macros)]
span: Span) {
if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
let mut err = struct_span_err!(tcx.sess, span, E0045,
- "variadic function must have C or cdecl calling convention");
+ "variadic function must have C or cdecl calling convention");
err.span_label(span, "variadics require C or cdecl calling convention").emit();
}
}
let main_t = tcx.type_of(main_def_id);
match main_t.sty {
ty::FnDef(..) => {
- match tcx.hir.find(main_id) {
- Some(Node::Item(it)) => {
- match it.node {
- hir::ItemKind::Fn(.., ref generics, _) => {
- let mut error = false;
- if !generics.params.is_empty() {
- let msg = "`main` function is not allowed to have generic \
- parameters".to_string();
- let label = "`main` cannot have generic parameters".to_string();
- struct_span_err!(tcx.sess, generics.span, E0131, "{}", msg)
- .span_label(generics.span, label)
- .emit();
- error = true;
- }
- if let Some(sp) = generics.where_clause.span() {
- struct_span_err!(tcx.sess, sp, E0646,
- "`main` function is not allowed to have a `where` clause")
- .span_label(sp, "`main` cannot have a `where` clause")
- .emit();
- error = true;
- }
- if error {
- return;
- }
- }
- _ => ()
+ if let Some(Node::Item(it)) = tcx.hir.find(main_id) {
+ if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
+ let mut error = false;
+ if !generics.params.is_empty() {
+ let msg = "`main` function is not allowed to have generic \
+ parameters".to_owned();
+ let label = "`main` cannot have generic parameters".to_string();
+ struct_span_err!(tcx.sess, generics.span, E0131, "{}", msg)
+ .span_label(generics.span, label)
+ .emit();
+ error = true;
+ }
+ if let Some(sp) = generics.where_clause.span() {
+ struct_span_err!(tcx.sess, sp, E0646,
+ "`main` function is not allowed to have a `where` clause")
+ .span_label(sp, "`main` cannot have a `where` clause")
+ .emit();
+ error = true;
+ }
+ if error {
+ return;
}
}
- _ => ()
}
let actual = tcx.fn_sig(main_def_id);
let start_t = tcx.type_of(start_def_id);
match start_t.sty {
ty::FnDef(..) => {
- match tcx.hir.find(start_id) {
- Some(Node::Item(it)) => {
- match it.node {
- hir::ItemKind::Fn(.., ref generics, _) => {
- let mut error = false;
- if !generics.params.is_empty() {
- struct_span_err!(tcx.sess, generics.span, E0132,
- "start function is not allowed to have type parameters")
- .span_label(generics.span,
- "start function cannot have type parameters")
- .emit();
- error = true;
- }
- if let Some(sp) = generics.where_clause.span() {
- struct_span_err!(tcx.sess, sp, E0647,
- "start function is not allowed to have a `where` clause")
- .span_label(sp, "start function cannot have a `where` clause")
- .emit();
- error = true;
- }
- if error {
- return;
- }
- }
- _ => ()
+ if let Some(Node::Item(it)) = tcx.hir.find(start_id) {
+ if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
+ let mut error = false;
+ if !generics.params.is_empty() {
+ struct_span_err!(tcx.sess, generics.span, E0132,
+ "start function is not allowed to have type parameters")
+ .span_label(generics.span,
+ "start function cannot have type parameters")
+ .emit();
+ error = true;
+ }
+ if let Some(sp) = generics.where_clause.span() {
+ struct_span_err!(tcx.sess, sp, E0647,
+ "start function is not allowed to have a `where` clause")
+ .span_label(sp, "start function cannot have a `where` clause")
+ .emit();
+ error = true;
+ }
+ if error {
+ return;
}
}
- _ => ()
}
let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(
let env_node_id = tcx.hir.get_parent(hir_ty.id);
let env_def_id = tcx.hir.local_def_id(env_node_id);
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id);
+
astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty)
}
pub fn hir_trait_to_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_trait: &hir::TraitRef)
- -> (ty::PolyTraitRef<'tcx>, Vec<ty::PolyProjectionPredicate<'tcx>>) {
+ -> (ty::PolyTraitRef<'tcx>, Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>) {
// In case there are any projections etc, find the "environment"
// def-id that will be used to determine the traits/predicates in
// scope. This is derived from the enclosing item-like thing.
let principal = astconv::AstConv::instantiate_poly_trait_ref_inner(
&item_cx, hir_trait, tcx.types.err, &mut projections, true
);
+
(principal, projections)
}