Remove all doc_comment!{} hacks by using #[doc = expr] where needed.

This commit is contained in:
Mara Bos 2020-11-17 23:57:29 +01:00
parent e226704685
commit 27b81bf97a
8 changed files with 4555 additions and 5052 deletions

View File

@ -113,6 +113,7 @@
#![feature(doc_spotlight)]
#![feature(duration_consts_2)]
#![feature(duration_saturating_ops)]
#![feature(extended_key_value_attributes)]
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intrinsics)]

File diff suppressed because it is too large Load Diff

View File

@ -23,13 +23,6 @@ macro_rules! unlikely {
};
}
macro_rules! doc_comment {
($x:expr, $($tt:tt)*) => {
#[doc = $x]
$($tt)*
};
}
// All these modules are technically private and only exposed for coretests:
pub mod bignum;
pub mod dec2flt;
@ -95,26 +88,26 @@ depending on the target pointer size.
#[lang = "i8"]
impl i8 {
int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
int_impl! { i8, i8, u8, 8, -128, 127, 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
"[0x12]", "[0x12]", "", "" }
}
#[lang = "i16"]
impl i16 {
int_impl! { i16, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
int_impl! { i16, i16, u16, 16, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
"0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" }
}
#[lang = "i32"]
impl i32 {
int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301",
int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]", "", "" }
}
#[lang = "i64"]
impl i64 {
int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", 12,
int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, 12,
"0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", "", "" }
@ -123,7 +116,7 @@ impl i64 {
#[lang = "i128"]
impl i128 {
int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728,
170141183460469231731687303715884105727, "", "", 16,
170141183460469231731687303715884105727, 16,
"0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012",
"0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48",
"[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
@ -135,7 +128,7 @@ impl i128 {
#[cfg(target_pointer_width = "16")]
#[lang = "isize"]
impl isize {
int_impl! { isize, i16, usize, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234",
int_impl! { isize, i16, usize, 16, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234",
"0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
}
@ -143,7 +136,7 @@ impl isize {
#[cfg(target_pointer_width = "32")]
#[lang = "isize"]
impl isize {
int_impl! { isize, i32, usize, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301",
int_impl! { isize, i32, usize, 32, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
@ -152,7 +145,7 @@ impl isize {
#[cfg(target_pointer_width = "64")]
#[lang = "isize"]
impl isize {
int_impl! { isize, i64, usize, 64, -9223372036854775808, 9223372036854775807, "", "",
int_impl! { isize, i64, usize, 64, -9223372036854775808, 9223372036854775807,
12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
@ -161,7 +154,7 @@ impl isize {
#[lang = "u8"]
impl u8 {
uint_impl! { u8, u8, 8, 255, "", "", 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
uint_impl! { u8, u8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
"[0x12]", "", "" }
/// Checks if the value is within the ASCII range.
@ -660,19 +653,19 @@ impl u8 {
#[lang = "u16"]
impl u16 {
uint_impl! { u16, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
uint_impl! { u16, u16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]", "", "" }
}
#[lang = "u32"]
impl u32 {
uint_impl! { u32, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678",
uint_impl! { u32, u32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" }
}
#[lang = "u64"]
impl u64 {
uint_impl! { u64, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa",
uint_impl! { u64, u64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
@ -681,7 +674,7 @@ impl u64 {
#[lang = "u128"]
impl u128 {
uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, "", "", 16,
uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, 16,
"0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012",
"0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48",
"[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
@ -694,14 +687,14 @@ impl u128 {
#[cfg(target_pointer_width = "16")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
uint_impl! { usize, u16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
}
#[cfg(target_pointer_width = "32")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678",
uint_impl! { usize, u32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
}
@ -709,7 +702,7 @@ impl usize {
#[cfg(target_pointer_width = "64")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa",
uint_impl! { usize, u64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",

View File

@ -8,13 +8,6 @@ use super::from_str_radix;
use super::{IntErrorKind, ParseIntError};
use crate::intrinsics;
macro_rules! doc_comment {
($x:expr, $($tt:tt)*) => {
#[doc = $x]
$($tt)*
};
}
macro_rules! impl_nonzero_fmt {
( #[$stability: meta] ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
$(
@ -32,24 +25,21 @@ macro_rules! impl_nonzero_fmt {
macro_rules! nonzero_integers {
( $( #[$stability: meta] $Ty: ident($Int: ty); )+ ) => {
$(
doc_comment! {
concat!("An integer that is known not to equal zero.
This enables some memory layout optimization.
For example, `Option<", stringify!($Ty), ">` is the same size as `", stringify!($Int), "`:
```rust
use std::mem::size_of;
assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", stringify!($Int),
">());
```"),
#[$stability]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
pub struct $Ty($Int);
}
/// An integer that is known not to equal zero.
///
/// This enables some memory layout optimization.
#[doc = concat!("For example, `Option<", stringify!($Ty), ">` is the same size as `", stringify!($Int), "`:")]
///
/// ```rust
/// use std::mem::size_of;
#[doc = concat!("assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", stringify!($Int), ">());")]
/// ```
#[$stability]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
pub struct $Ty($Int);
impl $Ty {
/// Creates a non-zero without checking the value.
@ -90,13 +80,10 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
#[stable(feature = "from_nonzero", since = "1.31.0")]
impl From<$Ty> for $Int {
doc_comment! {
concat!(
"Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`"),
#[inline]
fn from(nonzero: $Ty) -> Self {
nonzero.0
}
#[doc = concat!("Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`")]
#[inline]
fn from(nonzero: $Ty) -> Self {
nonzero.0
}
}

View File

@ -1,49 +1,44 @@
#![doc(hidden)]
macro_rules! doc_comment {
($x:expr, $($tt:tt)*) => {
#[doc = $x]
$($tt)*
};
}
macro_rules! int_module {
($T:ident) => (int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
($T:ident, #[$attr:meta]) => (
doc_comment! {
concat!("The smallest value that can be represented by this integer type.
Use [`", stringify!($T), "::MIN", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MIN) instead.
#[doc = concat!(
"The smallest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MIN", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MIN)",
"intead.",
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let min = std::", stringify!($T), "::MIN;")]
///
/// // intended way
#[doc = concat!("let min = ", stringify!($T), "::MIN;")]
/// ```
///
#[$attr]
pub const MIN: $T = $T::MIN;
# Examples
```rust
// deprecated way
let min = std::", stringify!($T), "::MIN;
// intended way
let min = ", stringify!($T), "::MIN;
```
"),
#[$attr]
pub const MIN: $T = $T::MIN;
}
doc_comment! {
concat!("The largest value that can be represented by this integer type.
Use [`", stringify!($T), "::MAX", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MAX) instead.
# Examples
```rust
// deprecated way
let max = std::", stringify!($T), "::MAX;
// intended way
let max = ", stringify!($T), "::MAX;
```
"),
#[$attr]
pub const MAX: $T = $T::MAX;
}
#[doc = concat!(
"The largest value that can be represented by this integer type. Use ",
"[`", stringify!($T), "::MAX", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MAX)",
"instead.",
)]
///
/// # Examples
///
/// ```rust
/// // deprecated way
#[doc = concat!("let max = std::", stringify!($T), "::MAX;")]
///
/// // intended way
#[doc = concat!("let max = ", stringify!($T), "::MAX;")]
/// ```
///
#[$attr]
pub const MAX: $T = $T::MAX;
)
}

File diff suppressed because it is too large Load Diff

View File

@ -403,105 +403,94 @@ wrapping_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
macro_rules! wrapping_int_impl {
($($t:ty)*) => ($(
impl Wrapping<$t> {
doc_comment! {
concat!("Returns the smallest value that can be represented by this integer type.
/// Returns the smallest value that can be represented by this integer type.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(<Wrapping<", stringify!($t), ">>::MIN, Wrapping(", stringify!($t), "::MIN));")]
/// ```
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const MIN: Self = Self(<$t>::MIN);
# Examples
/// Returns the largest value that can be represented by this integer type.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(<Wrapping<", stringify!($t), ">>::MAX, Wrapping(", stringify!($t), "::MAX));")]
/// ```
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const MAX: Self = Self(<$t>::MAX);
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<", stringify!($t), ">>::MIN, Wrapping(", stringify!($t), "::MIN));
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const MIN: Self = Self(<$t>::MIN);
/// Returns the number of ones in the binary representation of `self`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0b01001100", stringify!($t), ");")]
///
/// assert_eq!(n.count_ones(), 3);
/// ```
#[inline]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_ones(self) -> u32 {
self.0.count_ones()
}
doc_comment! {
concat!("Returns the largest value that can be represented by this integer type.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<", stringify!($t), ">>::MAX, Wrapping(", stringify!($t), "::MAX));
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const MAX: Self = Self(<$t>::MAX);
/// Returns the number of zeros in the binary representation of `self`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(Wrapping(!0", stringify!($t), ").count_zeros(), 0);")]
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_zeros(self) -> u32 {
self.0.count_zeros()
}
doc_comment! {
concat!("Returns the number of ones in the binary representation of `self`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0b01001100", stringify!($t), ");
assert_eq!(n.count_ones(), 3);
```"),
#[inline]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_ones(self) -> u32 {
self.0.count_ones()
}
}
doc_comment! {
concat!("Returns the number of zeros in the binary representation of `self`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(!0", stringify!($t), ").count_zeros(), 0);
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_zeros(self) -> u32 {
self.0.count_zeros()
}
}
doc_comment! {
concat!("Returns the number of trailing zeros in the binary representation
of `self`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0b0101000", stringify!($t), ");
assert_eq!(n.trailing_zeros(), 3);
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn trailing_zeros(self) -> u32 {
self.0.trailing_zeros()
}
/// Returns the number of trailing zeros in the binary representation of `self`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0b0101000", stringify!($t), ");")]
///
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn trailing_zeros(self) -> u32 {
self.0.trailing_zeros()
}
/// Shifts the bits to the left by a specified amount, `n`,
@ -608,150 +597,140 @@ assert_eq!(n.trailing_zeros(), 3);
Wrapping(self.0.reverse_bits())
}
doc_comment! {
concat!("Converts an integer from big endian to the target's endianness.
On big endian this is a no-op. On little endian the bytes are
swapped.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1A", stringify!($t), ");
if cfg!(target_endian = \"big\") {
assert_eq!(<Wrapping<", stringify!($t), ">>::from_be(n), n)
} else {
assert_eq!(<Wrapping<", stringify!($t), ">>::from_be(n), n.swap_bytes())
}
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn from_be(x: Self) -> Self {
Wrapping(<$t>::from_be(x.0))
}
/// Converts an integer from big endian to the target's endianness.
///
/// On big endian this is a no-op. On little endian the bytes are
/// swapped.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0x1A", stringify!($t), ");")]
///
/// if cfg!(target_endian = "big") {
#[doc = concat!(" assert_eq!(<Wrapping<", stringify!($t), ">>::from_be(n), n)")]
/// } else {
#[doc = concat!(" assert_eq!(<Wrapping<", stringify!($t), ">>::from_be(n), n.swap_bytes())")]
/// }
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn from_be(x: Self) -> Self {
Wrapping(<$t>::from_be(x.0))
}
doc_comment! {
concat!("Converts an integer from little endian to the target's endianness.
On little endian this is a no-op. On big endian the bytes are
swapped.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1A", stringify!($t), ");
if cfg!(target_endian = \"little\") {
assert_eq!(<Wrapping<", stringify!($t), ">>::from_le(n), n)
} else {
assert_eq!(<Wrapping<", stringify!($t), ">>::from_le(n), n.swap_bytes())
}
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn from_le(x: Self) -> Self {
Wrapping(<$t>::from_le(x.0))
}
/// Converts an integer from little endian to the target's endianness.
///
/// On little endian this is a no-op. On big endian the bytes are
/// swapped.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0x1A", stringify!($t), ");")]
///
/// if cfg!(target_endian = "little") {
#[doc = concat!(" assert_eq!(<Wrapping<", stringify!($t), ">>::from_le(n), n)")]
/// } else {
#[doc = concat!(" assert_eq!(<Wrapping<", stringify!($t), ">>::from_le(n), n.swap_bytes())")]
/// }
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn from_le(x: Self) -> Self {
Wrapping(<$t>::from_le(x.0))
}
doc_comment! {
concat!("Converts `self` to big endian from the target's endianness.
On big endian this is a no-op. On little endian the bytes are
swapped.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1A", stringify!($t), ");
if cfg!(target_endian = \"big\") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_be(self) -> Self {
Wrapping(self.0.to_be())
}
/// Converts `self` to big endian from the target's endianness.
///
/// On big endian this is a no-op. On little endian the bytes are
/// swapped.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0x1A", stringify!($t), ");")]
///
/// if cfg!(target_endian = "big") {
/// assert_eq!(n.to_be(), n)
/// } else {
/// assert_eq!(n.to_be(), n.swap_bytes())
/// }
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_be(self) -> Self {
Wrapping(self.0.to_be())
}
doc_comment! {
concat!("Converts `self` to little endian from the target's endianness.
On little endian this is a no-op. On big endian the bytes are
swapped.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1A", stringify!($t), ");
if cfg!(target_endian = \"little\") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_le(self) -> Self {
Wrapping(self.0.to_le())
}
/// Converts `self` to little endian from the target's endianness.
///
/// On little endian this is a no-op. On big endian the bytes are
/// swapped.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(0x1A", stringify!($t), ");")]
///
/// if cfg!(target_endian = "little") {
/// assert_eq!(n.to_le(), n)
/// } else {
/// assert_eq!(n.to_le(), n.swap_bytes())
/// }
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_le(self) -> Self {
Wrapping(self.0.to_le())
}
doc_comment! {
concat!("Raises self to the power of `exp`, using exponentiation by squaring.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3", stringify!($t), ").pow(4), Wrapping(81));
```
Results that are too large are wrapped:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn pow(self, exp: u32) -> Self {
Wrapping(self.0.wrapping_pow(exp))
}
/// Raises self to the power of `exp`, using exponentiation by squaring.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(Wrapping(3", stringify!($t), ").pow(4), Wrapping(81));")]
/// ```
///
/// Results that are too large are wrapped:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
/// assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
/// assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn pow(self, exp: u32) -> Self {
Wrapping(self.0.wrapping_pow(exp))
}
}
)*)
@ -762,124 +741,114 @@ wrapping_int_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
macro_rules! wrapping_int_impl_signed {
($($t:ty)*) => ($(
impl Wrapping<$t> {
doc_comment! {
concat!("Returns the number of leading zeros in the binary representation of `self`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(", stringify!($t), "::MAX) >> 2;
assert_eq!(n.leading_zeros(), 3);
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
/// Returns the number of leading zeros in the binary representation of `self`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(", stringify!($t), "::MAX) >> 2;")]
///
/// assert_eq!(n.leading_zeros(), 3);
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
doc_comment! {
concat!("Computes the absolute value of `self`, wrapping around at
the boundary of the type.
The only case where such wrapping can occur is when one takes the absolute value of the negative
minimal value for the type this is a positive value that is too large to represent in the type. In
such a case, this function returns `MIN` itself.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(100", stringify!($t), ").abs(), Wrapping(100));
assert_eq!(Wrapping(-100", stringify!($t), ").abs(), Wrapping(100));
assert_eq!(Wrapping(", stringify!($t), "::MIN).abs(), Wrapping(", stringify!($t), "::MIN));
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn abs(self) -> Wrapping<$t> {
Wrapping(self.0.wrapping_abs())
}
/// Computes the absolute value of `self`, wrapping around at
/// the boundary of the type.
///
/// The only case where such wrapping can occur is when one takes the absolute value of the negative
/// minimal value for the type this is a positive value that is too large to represent in the type. In
/// such a case, this function returns `MIN` itself.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(Wrapping(100", stringify!($t), ").abs(), Wrapping(100));")]
#[doc = concat!("assert_eq!(Wrapping(-100", stringify!($t), ").abs(), Wrapping(100));")]
#[doc = concat!("assert_eq!(Wrapping(", stringify!($t), "::MIN).abs(), Wrapping(", stringify!($t), "::MIN));")]
/// assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn abs(self) -> Wrapping<$t> {
Wrapping(self.0.wrapping_abs())
}
doc_comment! {
concat!("Returns a number representing sign of `self`.
- `0` if the number is zero
- `1` if the number is positive
- `-1` if the number is negative
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(10", stringify!($t), ").signum(), Wrapping(1));
assert_eq!(Wrapping(0", stringify!($t), ").signum(), Wrapping(0));
assert_eq!(Wrapping(-10", stringify!($t), ").signum(), Wrapping(-1));
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn signum(self) -> Wrapping<$t> {
Wrapping(self.0.signum())
}
/// Returns a number representing sign of `self`.
///
/// - `0` if the number is zero
/// - `1` if the number is positive
/// - `-1` if the number is negative
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(Wrapping(10", stringify!($t), ").signum(), Wrapping(1));")]
#[doc = concat!("assert_eq!(Wrapping(0", stringify!($t), ").signum(), Wrapping(0));")]
#[doc = concat!("assert_eq!(Wrapping(-10", stringify!($t), ").signum(), Wrapping(-1));")]
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn signum(self) -> Wrapping<$t> {
Wrapping(self.0.signum())
}
doc_comment! {
concat!("Returns `true` if `self` is positive and `false` if the number is zero or
negative.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert!(Wrapping(10", stringify!($t), ").is_positive());
assert!(!Wrapping(-10", stringify!($t), ").is_positive());
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn is_positive(self) -> bool {
self.0.is_positive()
}
/// Returns `true` if `self` is positive and `false` if the number is zero or
/// negative.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert!(Wrapping(10", stringify!($t), ").is_positive());")]
#[doc = concat!("assert!(!Wrapping(-10", stringify!($t), ").is_positive());")]
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn is_positive(self) -> bool {
self.0.is_positive()
}
doc_comment! {
concat!("Returns `true` if `self` is negative and `false` if the number is zero or
positive.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert!(Wrapping(-10", stringify!($t), ").is_negative());
assert!(!Wrapping(10", stringify!($t), ").is_negative());
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn is_negative(self) -> bool {
self.0.is_negative()
}
/// Returns `true` if `self` is negative and `false` if the number is zero or
/// positive.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert!(Wrapping(-10", stringify!($t), ").is_negative());")]
#[doc = concat!("assert!(!Wrapping(10", stringify!($t), ").is_negative());")]
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn is_negative(self) -> bool {
self.0.is_negative()
}
}
)*)
@ -890,73 +859,67 @@ wrapping_int_impl_signed! { isize i8 i16 i32 i64 i128 }
macro_rules! wrapping_int_impl_unsigned {
($($t:ty)*) => ($(
impl Wrapping<$t> {
doc_comment! {
concat!("Returns the number of leading zeros in the binary representation of `self`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(", stringify!($t), "::MAX) >> 2;
assert_eq!(n.leading_zeros(), 2);
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
/// Returns the number of leading zeros in the binary representation of `self`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("let n = Wrapping(", stringify!($t), "::MAX) >> 2;")]
///
/// assert_eq!(n.leading_zeros(), 2);
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
doc_comment! {
concat!("Returns `true` if and only if `self == 2^k` for some `k`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert!(Wrapping(16", stringify!($t), ").is_power_of_two());
assert!(!Wrapping(10", stringify!($t), ").is_power_of_two());
```"),
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn is_power_of_two(self) -> bool {
self.0.is_power_of_two()
}
/// Returns `true` if and only if `self == 2^k` for some `k`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert!(Wrapping(16", stringify!($t), ").is_power_of_two());")]
#[doc = concat!("assert!(!Wrapping(10", stringify!($t), ").is_power_of_two());")]
/// ```
#[inline]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn is_power_of_two(self) -> bool {
self.0.is_power_of_two()
}
doc_comment! {
concat!("Returns the smallest power of two greater than or equal to `self`.
When return value overflows (i.e., `self > (1 << (N-1))` for type
`uN`), overflows to `2^N = 0`.
# Examples
Basic usage:
```
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2", stringify!($t), ").next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3", stringify!($t), ").next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
```"),
#[inline]
#[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
reason = "needs decision on wrapping behaviour")]
pub fn next_power_of_two(self) -> Self {
Wrapping(self.0.wrapping_next_power_of_two())
}
/// Returns the smallest power of two greater than or equal to `self`.
///
/// When return value overflows (i.e., `self > (1 << (N-1))` for type
/// `uN`), overflows to `2^N = 0`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_next_power_of_two)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(Wrapping(2", stringify!($t), ").next_power_of_two(), Wrapping(2));")]
#[doc = concat!("assert_eq!(Wrapping(3", stringify!($t), ").next_power_of_two(), Wrapping(4));")]
#[doc = concat!("assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));")]
/// ```
#[inline]
#[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
reason = "needs decision on wrapping behaviour")]
pub fn next_power_of_two(self) -> Self {
Wrapping(self.0.wrapping_next_power_of_two())
}
}
)*)

File diff suppressed because it is too large Load Diff