Migrate to numeric associated consts
This commit is contained in:
parent
283522400b
commit
fff822fead
101 changed files with 485 additions and 518 deletions
|
@ -2034,7 +2034,7 @@ trait RcBoxPtr<T: ?Sized> {
|
|||
// The reference count will never be zero when this is called;
|
||||
// nevertheless, we insert an abort here to hint LLVM at
|
||||
// an otherwise missed optimization.
|
||||
if strong == 0 || strong == usize::max_value() {
|
||||
if strong == 0 || strong == usize::MAX {
|
||||
abort();
|
||||
}
|
||||
self.inner().strong.set(strong + 1);
|
||||
|
@ -2058,7 +2058,7 @@ trait RcBoxPtr<T: ?Sized> {
|
|||
// The reference count will never be zero when this is called;
|
||||
// nevertheless, we insert an abort here to hint LLVM at
|
||||
// an otherwise missed optimization.
|
||||
if weak == 0 || weak == usize::max_value() {
|
||||
if weak == 0 || weak == usize::MAX {
|
||||
abort();
|
||||
}
|
||||
self.inner().weak.set(weak + 1);
|
||||
|
|
|
@ -407,14 +407,14 @@ fn test_from_vec() {
|
|||
fn test_downcast() {
|
||||
use std::any::Any;
|
||||
|
||||
let r1: Rc<dyn Any> = Rc::new(i32::max_value());
|
||||
let r1: Rc<dyn Any> = Rc::new(i32::MAX);
|
||||
let r2: Rc<dyn Any> = Rc::new("abc");
|
||||
|
||||
assert!(r1.clone().downcast::<u32>().is_err());
|
||||
|
||||
let r1i32 = r1.downcast::<i32>();
|
||||
assert!(r1i32.is_ok());
|
||||
assert_eq!(r1i32.unwrap(), Rc::new(i32::max_value()));
|
||||
assert_eq!(r1i32.unwrap(), Rc::new(i32::MAX));
|
||||
|
||||
assert!(r2.clone().downcast::<i32>().is_err());
|
||||
|
||||
|
|
|
@ -465,14 +465,14 @@ fn test_from_vec() {
|
|||
fn test_downcast() {
|
||||
use std::any::Any;
|
||||
|
||||
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
|
||||
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::MAX);
|
||||
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");
|
||||
|
||||
assert!(r1.clone().downcast::<u32>().is_err());
|
||||
|
||||
let r1i32 = r1.downcast::<i32>();
|
||||
assert!(r1i32.is_ok());
|
||||
assert_eq!(r1i32.unwrap(), Arc::new(i32::max_value()));
|
||||
assert_eq!(r1i32.unwrap(), Arc::new(i32::MAX));
|
||||
|
||||
assert!(r2.clone().downcast::<i32>().is_err());
|
||||
|
||||
|
|
|
@ -566,13 +566,13 @@ mod slice_index {
|
|||
data: "hello";
|
||||
// note: using 0 specifically ensures that the result of overflowing is 0..0,
|
||||
// so that `get` doesn't simply return None for the wrong reason.
|
||||
bad: data[0..=usize::max_value()];
|
||||
bad: data[0..=usize::MAX];
|
||||
message: "maximum usize";
|
||||
}
|
||||
|
||||
in mod rangetoinclusive {
|
||||
data: "hello";
|
||||
bad: data[..=usize::max_value()];
|
||||
bad: data[..=usize::MAX];
|
||||
message: "maximum usize";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ fn test_reserve() {
|
|||
|
||||
#[test]
|
||||
fn test_zst_capacity() {
|
||||
assert_eq!(Vec::<()>::new().capacity(), usize::max_value());
|
||||
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -563,19 +563,19 @@ fn test_drain_inclusive_range() {
|
|||
|
||||
#[test]
|
||||
fn test_drain_max_vec_size() {
|
||||
let mut v = Vec::<()>::with_capacity(usize::max_value());
|
||||
let mut v = Vec::<()>::with_capacity(usize::MAX);
|
||||
unsafe {
|
||||
v.set_len(usize::max_value());
|
||||
v.set_len(usize::MAX);
|
||||
}
|
||||
for _ in v.drain(usize::max_value() - 1..) {}
|
||||
assert_eq!(v.len(), usize::max_value() - 1);
|
||||
for _ in v.drain(usize::MAX - 1..) {}
|
||||
assert_eq!(v.len(), usize::MAX - 1);
|
||||
|
||||
let mut v = Vec::<()>::with_capacity(usize::max_value());
|
||||
let mut v = Vec::<()>::with_capacity(usize::MAX);
|
||||
unsafe {
|
||||
v.set_len(usize::max_value());
|
||||
v.set_len(usize::MAX);
|
||||
}
|
||||
for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {}
|
||||
assert_eq!(v.len(), usize::max_value() - 1);
|
||||
for _ in v.drain(usize::MAX - 1..=usize::MAX - 1) {}
|
||||
assert_eq!(v.len(), usize::MAX - 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1163,8 +1163,8 @@ impl<'b> BorrowRef<'b> {
|
|||
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
|
||||
// 1. It was < 0, i.e. there are writing borrows, so we can't allow a read borrow
|
||||
// due to Rust's reference aliasing rules
|
||||
// 2. It was isize::max_value() (the max amount of reading borrows) and it overflowed
|
||||
// into isize::min_value() (the max amount of writing borrows) so we can't allow
|
||||
// 2. It was isize::MAX (the max amount of reading borrows) and it overflowed
|
||||
// into isize::MIN (the max amount of writing borrows) so we can't allow
|
||||
// an additional read borrow because isize can't represent so many read borrows
|
||||
// (this can only happen if you mem::forget more than a small constant amount of
|
||||
// `Ref`s, which is not good practice)
|
||||
|
@ -1172,7 +1172,7 @@ impl<'b> BorrowRef<'b> {
|
|||
} else {
|
||||
// Incrementing borrow can result in a reading value (> 0) in these cases:
|
||||
// 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read borrow
|
||||
// 2. It was > 0 and < isize::max_value(), i.e. there were read borrows, and isize
|
||||
// 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize
|
||||
// is large enough to represent having one more read borrow
|
||||
borrow.set(b);
|
||||
Some(BorrowRef { borrow })
|
||||
|
@ -1198,7 +1198,7 @@ impl Clone for BorrowRef<'_> {
|
|||
debug_assert!(is_reading(borrow));
|
||||
// Prevent the borrow counter from overflowing into
|
||||
// a writing borrow.
|
||||
assert!(borrow != isize::max_value());
|
||||
assert!(borrow != isize::MAX);
|
||||
self.borrow.set(borrow + 1);
|
||||
BorrowRef { borrow: self.borrow }
|
||||
}
|
||||
|
@ -1489,7 +1489,7 @@ impl<'b> BorrowRefMut<'b> {
|
|||
let borrow = self.borrow.get();
|
||||
debug_assert!(is_writing(borrow));
|
||||
// Prevent the borrow counter from underflowing.
|
||||
assert!(borrow != isize::min_value());
|
||||
assert!(borrow != isize::MIN);
|
||||
self.borrow.set(borrow - 1);
|
||||
BorrowRefMut { borrow: self.borrow }
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ macro_rules! try_from_upper_bounded {
|
|||
/// is outside of the range of the target type.
|
||||
#[inline]
|
||||
fn try_from(u: $source) -> Result<Self, Self::Error> {
|
||||
if u > (Self::max_value() as $source) {
|
||||
if u > (Self::MAX as $source) {
|
||||
Err(TryFromIntError(()))
|
||||
} else {
|
||||
Ok(u as Self)
|
||||
|
@ -239,8 +239,8 @@ macro_rules! try_from_both_bounded {
|
|||
/// is outside of the range of the target type.
|
||||
#[inline]
|
||||
fn try_from(u: $source) -> Result<Self, Self::Error> {
|
||||
let min = Self::min_value() as $source;
|
||||
let max = Self::max_value() as $source;
|
||||
let min = Self::MIN as $source;
|
||||
let max = Self::MAX as $source;
|
||||
if u < min || u > max {
|
||||
Err(TryFromIntError(()))
|
||||
} else {
|
||||
|
|
|
@ -750,9 +750,9 @@ $EndFeature, "
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow
|
||||
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -792,9 +792,9 @@ $EndFeature, "
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow
|
||||
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -834,9 +834,9 @@ $EndFeature, "
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow
|
||||
concat!("Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -871,7 +871,7 @@ $EndFeature, "
|
|||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
|
||||
if rhs == 0 || (self == Self::MIN && rhs == -1) {
|
||||
None
|
||||
} else {
|
||||
// SAFETY: div by zero and by INT_MIN have been checked above
|
||||
|
@ -900,7 +900,7 @@ assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);
|
|||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
|
||||
if rhs == 0 || (self == Self::MIN && rhs == -1) {
|
||||
None
|
||||
} else {
|
||||
Some(self.div_euclid(rhs))
|
||||
|
@ -929,7 +929,7 @@ $EndFeature, "
|
|||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
|
||||
if rhs == 0 || (self == Self::MIN && rhs == -1) {
|
||||
None
|
||||
} else {
|
||||
// SAFETY: div by zero and by INT_MIN have been checked above
|
||||
|
@ -957,7 +957,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);
|
|||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 || (self == Self::min_value() && rhs == -1) {
|
||||
if rhs == 0 || (self == Self::MIN && rhs == -1) {
|
||||
None
|
||||
} else {
|
||||
Some(self.rem_euclid(rhs))
|
||||
|
@ -1236,9 +1236,9 @@ $EndFeature, "
|
|||
match self.checked_mul(rhs) {
|
||||
Some(x) => x,
|
||||
None => if (self < 0) == (rhs < 0) {
|
||||
Self::max_value()
|
||||
Self::MAX
|
||||
} else {
|
||||
Self::min_value()
|
||||
Self::MIN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1267,8 +1267,8 @@ $EndFeature, "
|
|||
pub const fn saturating_pow(self, exp: u32) -> Self {
|
||||
match self.checked_pow(exp) {
|
||||
Some(x) => x,
|
||||
None if self < 0 && exp % 2 == 1 => Self::min_value(),
|
||||
None => Self::max_value(),
|
||||
None if self < 0 && exp % 2 == 1 => Self::MIN,
|
||||
None => Self::MAX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1738,7 +1738,7 @@ $EndFeature, "
|
|||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
|
||||
if self == Self::min_value() && rhs == -1 {
|
||||
if self == Self::MIN && rhs == -1 {
|
||||
(self, true)
|
||||
} else {
|
||||
(self / rhs, false)
|
||||
|
@ -1771,7 +1771,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringi
|
|||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
|
||||
if self == Self::min_value() && rhs == -1 {
|
||||
if self == Self::MIN && rhs == -1 {
|
||||
(self, true)
|
||||
} else {
|
||||
(self.div_euclid(rhs), false)
|
||||
|
@ -1805,7 +1805,7 @@ $EndFeature, "
|
|||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
|
||||
if self == Self::min_value() && rhs == -1 {
|
||||
if self == Self::MIN && rhs == -1 {
|
||||
(0, true)
|
||||
} else {
|
||||
(self % rhs, false)
|
||||
|
@ -1838,7 +1838,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));
|
|||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
|
||||
if self == Self::min_value() && rhs == -1 {
|
||||
if self == Self::MIN && rhs == -1 {
|
||||
(0, true)
|
||||
} else {
|
||||
(self.rem_euclid(rhs), false)
|
||||
|
@ -1869,8 +1869,8 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self
|
|||
#[allow(unused_attributes)]
|
||||
#[allow_internal_unstable(const_if_match)]
|
||||
pub const fn overflowing_neg(self) -> (Self, bool) {
|
||||
if self == Self::min_value() {
|
||||
(Self::min_value(), true)
|
||||
if self == Self::MIN {
|
||||
(Self::MIN, true)
|
||||
} else {
|
||||
(-self, false)
|
||||
}
|
||||
|
@ -1952,7 +1952,7 @@ $EndFeature, "
|
|||
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
|
||||
#[inline]
|
||||
pub const fn overflowing_abs(self) -> (Self, bool) {
|
||||
(self.wrapping_abs(), self == Self::min_value())
|
||||
(self.wrapping_abs(), self == Self::MIN)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2986,9 +2986,9 @@ assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeat
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow
|
||||
concat!("Unchecked integer addition. Computes `self + rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -3026,9 +3026,9 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, "
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow
|
||||
concat!("Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -3066,9 +3066,9 @@ assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, "
|
|||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow
|
||||
concat!("Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
|
||||
cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT),
|
||||
"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."),
|
||||
"::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`."),
|
||||
#[unstable(
|
||||
feature = "unchecked_math",
|
||||
reason = "niche optimization path",
|
||||
|
@ -3366,7 +3366,7 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se
|
|||
pub const fn saturating_mul(self, rhs: Self) -> Self {
|
||||
match self.checked_mul(rhs) {
|
||||
Some(x) => x,
|
||||
None => Self::max_value(),
|
||||
None => Self::MAX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3393,7 +3393,7 @@ $EndFeature, "
|
|||
pub const fn saturating_pow(self, exp: u32) -> Self {
|
||||
match self.checked_pow(exp) {
|
||||
Some(x) => x,
|
||||
None => Self::max_value(),
|
||||
None => Self::MAX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4080,7 +4080,7 @@ Basic usage:
|
|||
}
|
||||
}
|
||||
|
||||
doc_comment! {
|
||||
doc_comment! {
|
||||
concat!("Performs Euclidean division.
|
||||
|
||||
Since, for the positive integers, all common
|
||||
|
@ -4178,7 +4178,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
|
|||
// (such as intel pre-haswell) have more efficient ctlz
|
||||
// intrinsics when the argument is non-zero.
|
||||
let z = unsafe { intrinsics::ctlz_nonzero(p) };
|
||||
<$SelfT>::max_value() >> z
|
||||
<$SelfT>::MAX >> z
|
||||
}
|
||||
|
||||
doc_comment! {
|
||||
|
@ -5160,9 +5160,9 @@ trait FromStrRadixHelper: PartialOrd + Copy {
|
|||
macro_rules! doit {
|
||||
($($t:ty)*) => ($(impl FromStrRadixHelper for $t {
|
||||
#[inline]
|
||||
fn min_value() -> Self { Self::min_value() }
|
||||
fn min_value() -> Self { Self::MIN }
|
||||
#[inline]
|
||||
fn max_value() -> Self { Self::max_value() }
|
||||
fn max_value() -> Self { Self::MAX }
|
||||
#[inline]
|
||||
fn from_u32(u: u32) -> Self { u as Self }
|
||||
#[inline]
|
||||
|
|
|
@ -694,7 +694,7 @@ Basic usage:
|
|||
#![feature(wrapping_int_impl)]
|
||||
use std::num::Wrapping;
|
||||
|
||||
let n = Wrapping(", stringify!($t), "::max_value()) >> 2;
|
||||
let n = Wrapping(", stringify!($t), "::MAX) >> 2;
|
||||
|
||||
assert_eq!(n.leading_zeros(), 3);
|
||||
```"),
|
||||
|
@ -723,8 +723,7 @@ 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_value()).abs(), Wrapping(", stringify!($t),
|
||||
"::min_value()));
|
||||
assert_eq!(Wrapping(", stringify!($t), "::MIN).abs(), Wrapping(", stringify!($t), "::MIN));
|
||||
assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
|
||||
```"),
|
||||
#[inline]
|
||||
|
@ -823,7 +822,7 @@ Basic usage:
|
|||
#![feature(wrapping_int_impl)]
|
||||
use std::num::Wrapping;
|
||||
|
||||
let n = Wrapping(", stringify!($t), "::max_value()) >> 2;
|
||||
let n = Wrapping(", stringify!($t), "::MAX) >> 2;
|
||||
|
||||
assert_eq!(n.leading_zeros(), 2);
|
||||
```"),
|
||||
|
|
|
@ -291,7 +291,7 @@ impl<T: ?Sized> *const T {
|
|||
T: Sized,
|
||||
{
|
||||
let pointee_size = mem::size_of::<T>();
|
||||
assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize);
|
||||
assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
|
||||
intrinsics::ptr_offset_from(self, origin)
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ impl<T: ?Sized> *const T {
|
|||
T: Sized,
|
||||
{
|
||||
let pointee_size = mem::size_of::<T>();
|
||||
assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize);
|
||||
assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
|
||||
|
||||
let d = isize::wrapping_sub(self as _, origin as _);
|
||||
d.wrapping_div(pointee_size as _)
|
||||
|
|
|
@ -1128,7 +1128,7 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
|
|||
//
|
||||
// Note, that we use wrapping operations here intentionally – the original formula
|
||||
// uses e.g., subtraction `mod n`. It is entirely fine to do them `mod
|
||||
// usize::max_value()` instead, because we take the result `mod n` at the end
|
||||
// usize::MAX` instead, because we take the result `mod n` at the end
|
||||
// anyway.
|
||||
inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse)));
|
||||
if going_mod >= m {
|
||||
|
@ -1193,7 +1193,7 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
|
|||
}
|
||||
|
||||
// Cannot be aligned at all.
|
||||
usize::max_value()
|
||||
usize::MAX
|
||||
}
|
||||
|
||||
/// Compares raw pointers for equality.
|
||||
|
|
|
@ -3043,16 +3043,12 @@ impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
|||
|
||||
#[inline]
|
||||
fn get(self, slice: &[T]) -> Option<&[T]> {
|
||||
if *self.end() == usize::max_value() {
|
||||
None
|
||||
} else {
|
||||
(*self.start()..self.end() + 1).get(slice)
|
||||
}
|
||||
if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get(slice) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
None
|
||||
} else {
|
||||
(*self.start()..self.end() + 1).get_mut(slice)
|
||||
|
@ -3071,7 +3067,7 @@ impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
|||
|
||||
#[inline]
|
||||
fn index(self, slice: &[T]) -> &[T] {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
slice_index_overflow_fail();
|
||||
}
|
||||
(*self.start()..self.end() + 1).index(slice)
|
||||
|
@ -3079,7 +3075,7 @@ impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
|
|||
|
||||
#[inline]
|
||||
fn index_mut(self, slice: &mut [T]) -> &mut [T] {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
slice_index_overflow_fail();
|
||||
}
|
||||
(*self.start()..self.end() + 1).index_mut(slice)
|
||||
|
|
|
@ -1651,7 +1651,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
|
|||
// Ascii case, try to skip forward quickly.
|
||||
// When the pointer is aligned, read 2 words of data per iteration
|
||||
// until we find a word containing a non-ascii byte.
|
||||
if align != usize::max_value() && align.wrapping_sub(index) % usize_bytes == 0 {
|
||||
if align != usize::MAX && align.wrapping_sub(index) % usize_bytes == 0 {
|
||||
let ptr = v.as_ptr();
|
||||
while index < blocks_end {
|
||||
// SAFETY: since `align - index` and `ascii_block_size` are
|
||||
|
@ -2083,7 +2083,7 @@ mod traits {
|
|||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
None
|
||||
} else {
|
||||
(*self.start()..self.end() + 1).get(slice)
|
||||
|
@ -2091,7 +2091,7 @@ mod traits {
|
|||
}
|
||||
#[inline]
|
||||
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
None
|
||||
} else {
|
||||
(*self.start()..self.end() + 1).get_mut(slice)
|
||||
|
@ -2107,14 +2107,14 @@ mod traits {
|
|||
}
|
||||
#[inline]
|
||||
fn index(self, slice: &str) -> &Self::Output {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
str_index_overflow_fail();
|
||||
}
|
||||
(*self.start()..self.end() + 1).index(slice)
|
||||
}
|
||||
#[inline]
|
||||
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
||||
if *self.end() == usize::max_value() {
|
||||
if *self.end() == usize::MAX {
|
||||
str_index_overflow_fail();
|
||||
}
|
||||
(*self.start()..self.end() + 1).index_mut(slice)
|
||||
|
@ -2140,11 +2140,11 @@ mod traits {
|
|||
type Output = str;
|
||||
#[inline]
|
||||
fn get(self, slice: &str) -> Option<&Self::Output> {
|
||||
if self.end == usize::max_value() { None } else { (..self.end + 1).get(slice) }
|
||||
if self.end == usize::MAX { None } else { (..self.end + 1).get(slice) }
|
||||
}
|
||||
#[inline]
|
||||
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
|
||||
if self.end == usize::max_value() { None } else { (..self.end + 1).get_mut(slice) }
|
||||
if self.end == usize::MAX { None } else { (..self.end + 1).get_mut(slice) }
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn get_unchecked(self, slice: &str) -> &Self::Output {
|
||||
|
@ -2156,14 +2156,14 @@ mod traits {
|
|||
}
|
||||
#[inline]
|
||||
fn index(self, slice: &str) -> &Self::Output {
|
||||
if self.end == usize::max_value() {
|
||||
if self.end == usize::MAX {
|
||||
str_index_overflow_fail();
|
||||
}
|
||||
(..self.end + 1).index(slice)
|
||||
}
|
||||
#[inline]
|
||||
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
||||
if self.end == usize::max_value() {
|
||||
if self.end == usize::MAX {
|
||||
str_index_overflow_fail();
|
||||
}
|
||||
(..self.end + 1).index_mut(slice)
|
||||
|
|
|
@ -140,8 +140,8 @@ macro_rules! test_impl_from {
|
|||
($fn_name: ident, $Small: ty, $Large: ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let small_max = <$Small>::max_value();
|
||||
let small_min = <$Small>::min_value();
|
||||
let small_max = <$Small>::MAX;
|
||||
let small_min = <$Small>::MIN;
|
||||
let large_max: $Large = small_max.into();
|
||||
let large_min: $Large = small_min.into();
|
||||
assert_eq!(large_max as $Small, small_max);
|
||||
|
@ -248,8 +248,8 @@ macro_rules! test_impl_try_from_always_ok {
|
|||
($fn_name:ident, $source:ty, $target: ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let max = <$source>::max_value();
|
||||
let min = <$source>::min_value();
|
||||
let max = <$source>::MAX;
|
||||
let min = <$source>::MIN;
|
||||
let zero: $source = 0;
|
||||
assert_eq!(<$target as TryFrom<$source>>::try_from(max).unwrap(), max as $target);
|
||||
assert_eq!(<$target as TryFrom<$source>>::try_from(min).unwrap(), min as $target);
|
||||
|
@ -361,8 +361,8 @@ macro_rules! test_impl_try_from_signed_to_unsigned_upper_ok {
|
|||
($fn_name:ident, $source:ty, $target:ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let max = <$source>::max_value();
|
||||
let min = <$source>::min_value();
|
||||
let max = <$source>::MAX;
|
||||
let min = <$source>::MIN;
|
||||
let zero: $source = 0;
|
||||
let neg_one: $source = -1;
|
||||
assert_eq!(<$target as TryFrom<$source>>::try_from(max).unwrap(), max as $target);
|
||||
|
@ -426,8 +426,8 @@ macro_rules! test_impl_try_from_unsigned_to_signed_upper_err {
|
|||
($fn_name:ident, $source:ty, $target:ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let max = <$source>::max_value();
|
||||
let min = <$source>::min_value();
|
||||
let max = <$source>::MAX;
|
||||
let min = <$source>::MIN;
|
||||
let zero: $source = 0;
|
||||
assert!(<$target as TryFrom<$source>>::try_from(max).is_err());
|
||||
assert_eq!(<$target as TryFrom<$source>>::try_from(min).unwrap(), min as $target);
|
||||
|
@ -487,11 +487,11 @@ macro_rules! test_impl_try_from_same_sign_err {
|
|||
($fn_name:ident, $source:ty, $target:ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let max = <$source>::max_value();
|
||||
let min = <$source>::min_value();
|
||||
let max = <$source>::MAX;
|
||||
let min = <$source>::MIN;
|
||||
let zero: $source = 0;
|
||||
let t_max = <$target>::max_value();
|
||||
let t_min = <$target>::min_value();
|
||||
let t_max = <$target>::MAX;
|
||||
let t_min = <$target>::MIN;
|
||||
assert!(<$target as TryFrom<$source>>::try_from(max).is_err());
|
||||
if min != 0 {
|
||||
assert!(<$target as TryFrom<$source>>::try_from(min).is_err());
|
||||
|
@ -576,11 +576,11 @@ macro_rules! test_impl_try_from_signed_to_unsigned_err {
|
|||
($fn_name:ident, $source:ty, $target:ty) => {
|
||||
#[test]
|
||||
fn $fn_name() {
|
||||
let max = <$source>::max_value();
|
||||
let min = <$source>::min_value();
|
||||
let max = <$source>::MAX;
|
||||
let min = <$source>::MIN;
|
||||
let zero: $source = 0;
|
||||
let t_max = <$target>::max_value();
|
||||
let t_min = <$target>::min_value();
|
||||
let t_max = <$target>::MAX;
|
||||
let t_min = <$target>::MIN;
|
||||
assert!(<$target as TryFrom<$source>>::try_from(max).is_err());
|
||||
assert!(<$target as TryFrom<$source>>::try_from(min).is_err());
|
||||
assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target);
|
||||
|
|
|
@ -357,7 +357,7 @@ fn align_offset_weird_strides() {
|
|||
|
||||
unsafe fn test_weird_stride<T>(ptr: *const T, align: usize) -> bool {
|
||||
let numptr = ptr as usize;
|
||||
let mut expected = usize::max_value();
|
||||
let mut expected = usize::MAX;
|
||||
// Naive but definitely correct way to find the *first* aligned element of stride::<T>.
|
||||
for el in 0..align {
|
||||
if (numptr + el * ::std::mem::size_of::<T>()) % align == 0 {
|
||||
|
|
|
@ -1691,8 +1691,8 @@ fn test_copy_within_panics_src_inverted() {
|
|||
#[should_panic(expected = "attempted to index slice up to maximum usize")]
|
||||
fn test_copy_within_panics_src_out_of_bounds() {
|
||||
let mut bytes = *b"Hello, World!";
|
||||
// an inclusive range ending at usize::max_value() would make src_end overflow
|
||||
bytes.copy_within(usize::max_value()..=usize::max_value(), 0);
|
||||
// an inclusive range ending at usize::MAX would make src_end overflow
|
||||
bytes.copy_within(usize::MAX..=usize::MAX, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -133,9 +133,9 @@ impl Neg for Round {
|
|||
pub type ExpInt = i16;
|
||||
|
||||
// \c ilogb error results.
|
||||
pub const IEK_INF: ExpInt = ExpInt::max_value();
|
||||
pub const IEK_NAN: ExpInt = ExpInt::min_value();
|
||||
pub const IEK_ZERO: ExpInt = ExpInt::min_value() + 1;
|
||||
pub const IEK_INF: ExpInt = ExpInt::MAX;
|
||||
pub const IEK_NAN: ExpInt = ExpInt::MIN;
|
||||
pub const IEK_ZERO: ExpInt = ExpInt::MIN + 1;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ParseError(pub &'static str);
|
||||
|
|
|
@ -2997,8 +2997,8 @@ fn scalbn() {
|
|||
assert!(smallest_f64.scalbn(2099).is_infinite());
|
||||
|
||||
// Test for integer overflows when adding to exponent.
|
||||
assert!(smallest_f64.scalbn(-ExpInt::max_value()).is_pos_zero());
|
||||
assert!(largest_f64.scalbn(ExpInt::max_value()).is_infinite());
|
||||
assert!(smallest_f64.scalbn(-ExpInt::MAX).is_pos_zero());
|
||||
assert!(largest_f64.scalbn(ExpInt::MAX).is_infinite());
|
||||
|
||||
assert!(largest_denormal_f64.bitwise_eq(largest_denormal_f64.scalbn(0),));
|
||||
assert!(neg_largest_denormal_f64.bitwise_eq(neg_largest_denormal_f64.scalbn(0),));
|
||||
|
|
|
@ -12,8 +12,8 @@ fn test_encode() {
|
|||
test(35, base);
|
||||
test(36, base);
|
||||
test(37, base);
|
||||
test(u64::max_value() as u128, base);
|
||||
test(u128::max_value(), base);
|
||||
test(u64::MAX as u128, base);
|
||||
test(u128::MAX, base);
|
||||
|
||||
for i in 0..1_000 {
|
||||
test(i * 983, base);
|
||||
|
|
|
@ -582,10 +582,10 @@ impl server::Literal for Rustc<'_> {
|
|||
};
|
||||
|
||||
// Bounds check the values, preventing addition overflow and OOB spans.
|
||||
if start > u32::max_value() as usize
|
||||
|| end > u32::max_value() as usize
|
||||
|| (u32::max_value() - start as u32) < span.lo().to_u32()
|
||||
|| (u32::max_value() - end as u32) < span.lo().to_u32()
|
||||
if start > u32::MAX as usize
|
||||
|| end > u32::MAX as usize
|
||||
|| (u32::MAX - start as u32) < span.lo().to_u32()
|
||||
|| (u32::MAX - end as u32) < span.lo().to_u32()
|
||||
|| start >= end
|
||||
|| end > length
|
||||
{
|
||||
|
|
|
@ -335,7 +335,7 @@ where
|
|||
|
||||
fn byte_from_char(c: char) -> u8 {
|
||||
let res = c as u32;
|
||||
assert!(res <= u8::max_value() as u32, "guaranteed because of Mode::ByteStr");
|
||||
assert!(res <= u8::MAX as u32, "guaranteed because of Mode::ByteStr");
|
||||
res as u8
|
||||
}
|
||||
|
||||
|
|
|
@ -108,23 +108,23 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
|
|||
// warnings are consistent between 32- and 64-bit platforms.
|
||||
fn int_ty_range(int_ty: ast::IntTy) -> (i128, i128) {
|
||||
match int_ty {
|
||||
ast::IntTy::Isize => (i64::min_value() as i128, i64::max_value() as i128),
|
||||
ast::IntTy::I8 => (i8::min_value() as i64 as i128, i8::max_value() as i128),
|
||||
ast::IntTy::I16 => (i16::min_value() as i64 as i128, i16::max_value() as i128),
|
||||
ast::IntTy::I32 => (i32::min_value() as i64 as i128, i32::max_value() as i128),
|
||||
ast::IntTy::I64 => (i64::min_value() as i128, i64::max_value() as i128),
|
||||
ast::IntTy::I128 => (i128::min_value() as i128, i128::max_value()),
|
||||
ast::IntTy::Isize => (i64::MIN as i128, i64::MAX as i128),
|
||||
ast::IntTy::I8 => (i8::MIN as i64 as i128, i8::MAX as i128),
|
||||
ast::IntTy::I16 => (i16::MIN as i64 as i128, i16::MAX as i128),
|
||||
ast::IntTy::I32 => (i32::MIN as i64 as i128, i32::MAX as i128),
|
||||
ast::IntTy::I64 => (i64::MIN as i128, i64::MAX as i128),
|
||||
ast::IntTy::I128 => (i128::MIN as i128, i128::MAX),
|
||||
}
|
||||
}
|
||||
|
||||
fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) {
|
||||
match uint_ty {
|
||||
ast::UintTy::Usize => (u64::min_value() as u128, u64::max_value() as u128),
|
||||
ast::UintTy::U8 => (u8::min_value() as u128, u8::max_value() as u128),
|
||||
ast::UintTy::U16 => (u16::min_value() as u128, u16::max_value() as u128),
|
||||
ast::UintTy::U32 => (u32::min_value() as u128, u32::max_value() as u128),
|
||||
ast::UintTy::U64 => (u64::min_value() as u128, u64::max_value() as u128),
|
||||
ast::UintTy::U128 => (u128::min_value(), u128::max_value()),
|
||||
ast::UintTy::Usize => (u64::MIN as u128, u64::MAX as u128),
|
||||
ast::UintTy::U8 => (u8::MIN as u128, u8::MAX as u128),
|
||||
ast::UintTy::U16 => (u16::MIN as u128, u16::MAX as u128),
|
||||
ast::UintTy::U32 => (u32::MIN as u128, u32::MAX as u128),
|
||||
ast::UintTy::U64 => (u64::MIN as u128, u64::MAX as u128),
|
||||
ast::UintTy::U128 => (u128::MIN, u128::MAX),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -934,7 +934,7 @@ impl<'a> CrateLoader<'a> {
|
|||
src: ExternCrateSource::Path,
|
||||
span,
|
||||
// to have the least priority in `update_extern_crate`
|
||||
path_len: usize::max_value(),
|
||||
path_len: usize::MAX,
|
||||
dependency_of: LOCAL_CRATE,
|
||||
},
|
||||
);
|
||||
|
|
|
@ -160,13 +160,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
ty::Int(ity) => {
|
||||
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||
let max = truncate(u128::max_value(), size);
|
||||
let max = truncate(u128::MAX, size);
|
||||
let bias = 1u128 << (size.bits() - 1);
|
||||
(Some((0, max, size)), bias)
|
||||
}
|
||||
ty::Uint(uty) => {
|
||||
let size = Integer::from_attr(&tcx, UnsignedInt(uty)).size();
|
||||
let max = truncate(u128::max_value(), size);
|
||||
let max = truncate(u128::MAX, size);
|
||||
(Some((0, max, size)), 0)
|
||||
}
|
||||
_ => (None, 0),
|
||||
|
|
|
@ -1519,7 +1519,7 @@ fn all_constructors<'a, 'tcx>(
|
|||
}
|
||||
ty::Uint(uty) => {
|
||||
let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size();
|
||||
let max = truncate(u128::max_value(), size);
|
||||
let max = truncate(u128::MAX, size);
|
||||
vec![make_range(0, max)]
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -1088,7 +1088,7 @@ fn id_from_hir_id(id: hir::HirId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
|
|||
}
|
||||
|
||||
fn null_id() -> rls_data::Id {
|
||||
rls_data::Id { krate: u32::max_value(), index: u32::max_value() }
|
||||
rls_data::Id { krate: u32::MAX, index: u32::MAX }
|
||||
}
|
||||
|
||||
fn lower_attributes(
|
||||
|
|
|
@ -1031,7 +1031,7 @@ pub fn get_cmd_lint_options(
|
|||
// HACK: forbid is always specified last, so it can't be overridden.
|
||||
// FIXME: remove this once <https://github.com/rust-lang/rust/issues/70819> is
|
||||
// fixed and `forbid` works as expected.
|
||||
usize::max_value()
|
||||
usize::MAX
|
||||
} else {
|
||||
passed_arg_pos
|
||||
};
|
||||
|
|
|
@ -1250,7 +1250,7 @@ impl SourceFile {
|
|||
hasher.finish::<u128>()
|
||||
};
|
||||
let end_pos = start_pos.to_usize() + src.len();
|
||||
assert!(end_pos <= u32::max_value() as usize);
|
||||
assert!(end_pos <= u32::MAX as usize);
|
||||
|
||||
let (lines, multibyte_chars, non_narrow_chars) =
|
||||
analyze_source_file::analyze_source_file(&src[..], start_pos);
|
||||
|
|
|
@ -819,9 +819,7 @@ impl SourceMap {
|
|||
|
||||
// Disregard indexes that are at the start or end of their spans, they can't fit bigger
|
||||
// characters.
|
||||
if (!forwards && end_index == usize::min_value())
|
||||
|| (forwards && start_index == usize::max_value())
|
||||
{
|
||||
if (!forwards && end_index == usize::MIN) || (forwards && start_index == usize::MAX) {
|
||||
debug!("find_width_of_character_at_span: start or end of span, cannot be multibyte");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -916,8 +916,7 @@ impl f32 {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::f32;
|
||||
use crate::f32::*;
|
||||
use crate::f32::consts;
|
||||
use crate::num::FpCategory as Fp;
|
||||
use crate::num::*;
|
||||
|
||||
|
@ -928,14 +927,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_min_nan() {
|
||||
assert_eq!(NAN.min(2.0), 2.0);
|
||||
assert_eq!(2.0f32.min(NAN), 2.0);
|
||||
assert_eq!(f32::NAN.min(2.0), 2.0);
|
||||
assert_eq!(2.0f32.min(f32::NAN), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_nan() {
|
||||
assert_eq!(NAN.max(2.0), 2.0);
|
||||
assert_eq!(2.0f32.max(NAN), 2.0);
|
||||
assert_eq!(f32::NAN.max(2.0), 2.0);
|
||||
assert_eq!(2.0f32.max(f32::NAN), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1158,52 +1157,52 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
assert_eq!(INFINITY.abs(), INFINITY);
|
||||
assert_eq!(f32::INFINITY.abs(), f32::INFINITY);
|
||||
assert_eq!(1f32.abs(), 1f32);
|
||||
assert_eq!(0f32.abs(), 0f32);
|
||||
assert_eq!((-0f32).abs(), 0f32);
|
||||
assert_eq!((-1f32).abs(), 1f32);
|
||||
assert_eq!(NEG_INFINITY.abs(), INFINITY);
|
||||
assert_eq!((1f32 / NEG_INFINITY).abs(), 0f32);
|
||||
assert!(NAN.abs().is_nan());
|
||||
assert_eq!(f32::NEG_INFINITY.abs(), f32::INFINITY);
|
||||
assert_eq!((1f32 / f32::NEG_INFINITY).abs(), 0f32);
|
||||
assert!(f32::NAN.abs().is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_signum() {
|
||||
assert_eq!(INFINITY.signum(), 1f32);
|
||||
assert_eq!(f32::INFINITY.signum(), 1f32);
|
||||
assert_eq!(1f32.signum(), 1f32);
|
||||
assert_eq!(0f32.signum(), 1f32);
|
||||
assert_eq!((-0f32).signum(), -1f32);
|
||||
assert_eq!((-1f32).signum(), -1f32);
|
||||
assert_eq!(NEG_INFINITY.signum(), -1f32);
|
||||
assert_eq!((1f32 / NEG_INFINITY).signum(), -1f32);
|
||||
assert!(NAN.signum().is_nan());
|
||||
assert_eq!(f32::NEG_INFINITY.signum(), -1f32);
|
||||
assert_eq!((1f32 / f32::NEG_INFINITY).signum(), -1f32);
|
||||
assert!(f32::NAN.signum().is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_sign_positive() {
|
||||
assert!(INFINITY.is_sign_positive());
|
||||
assert!(f32::INFINITY.is_sign_positive());
|
||||
assert!(1f32.is_sign_positive());
|
||||
assert!(0f32.is_sign_positive());
|
||||
assert!(!(-0f32).is_sign_positive());
|
||||
assert!(!(-1f32).is_sign_positive());
|
||||
assert!(!NEG_INFINITY.is_sign_positive());
|
||||
assert!(!(1f32 / NEG_INFINITY).is_sign_positive());
|
||||
assert!(NAN.is_sign_positive());
|
||||
assert!(!(-NAN).is_sign_positive());
|
||||
assert!(!f32::NEG_INFINITY.is_sign_positive());
|
||||
assert!(!(1f32 / f32::NEG_INFINITY).is_sign_positive());
|
||||
assert!(f32::NAN.is_sign_positive());
|
||||
assert!(!(-f32::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_sign_negative() {
|
||||
assert!(!INFINITY.is_sign_negative());
|
||||
assert!(!f32::INFINITY.is_sign_negative());
|
||||
assert!(!1f32.is_sign_negative());
|
||||
assert!(!0f32.is_sign_negative());
|
||||
assert!((-0f32).is_sign_negative());
|
||||
assert!((-1f32).is_sign_negative());
|
||||
assert!(NEG_INFINITY.is_sign_negative());
|
||||
assert!((1f32 / NEG_INFINITY).is_sign_negative());
|
||||
assert!(!NAN.is_sign_negative());
|
||||
assert!((-NAN).is_sign_negative());
|
||||
assert!(f32::NEG_INFINITY.is_sign_negative());
|
||||
assert!((1f32 / f32::NEG_INFINITY).is_sign_negative());
|
||||
assert!(!f32::NAN.is_sign_negative());
|
||||
assert!((-f32::NAN).is_sign_negative());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1268,13 +1267,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_sqrt_domain() {
|
||||
assert!(NAN.sqrt().is_nan());
|
||||
assert!(NEG_INFINITY.sqrt().is_nan());
|
||||
assert!(f32::NAN.sqrt().is_nan());
|
||||
assert!(f32::NEG_INFINITY.sqrt().is_nan());
|
||||
assert!((-1.0f32).sqrt().is_nan());
|
||||
assert_eq!((-0.0f32).sqrt(), -0.0);
|
||||
assert_eq!(0.0f32.sqrt(), 0.0);
|
||||
assert_eq!(1.0f32.sqrt(), 1.0);
|
||||
assert_eq!(INFINITY.sqrt(), INFINITY);
|
||||
assert_eq!(f32::INFINITY.sqrt(), f32::INFINITY);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1523,13 +1522,13 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
let _ = 1.0f32.clamp(NAN, 1.0);
|
||||
let _ = 1.0f32.clamp(f32::NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
let _ = 1.0f32.clamp(3.0, NAN);
|
||||
let _ = 1.0f32.clamp(3.0, f32::NAN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -943,8 +943,7 @@ impl f64 {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::f64;
|
||||
use crate::f64::*;
|
||||
use crate::f64::consts;
|
||||
use crate::num::FpCategory as Fp;
|
||||
use crate::num::*;
|
||||
|
||||
|
@ -955,19 +954,19 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_min_nan() {
|
||||
assert_eq!(NAN.min(2.0), 2.0);
|
||||
assert_eq!(2.0f64.min(NAN), 2.0);
|
||||
assert_eq!(f64::NAN.min(2.0), 2.0);
|
||||
assert_eq!(2.0f64.min(f64::NAN), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_nan() {
|
||||
assert_eq!(NAN.max(2.0), 2.0);
|
||||
assert_eq!(2.0f64.max(NAN), 2.0);
|
||||
assert_eq!(f64::NAN.max(2.0), 2.0);
|
||||
assert_eq!(2.0f64.max(f64::NAN), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nan() {
|
||||
let nan: f64 = NAN;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert!(nan.is_nan());
|
||||
assert!(!nan.is_infinite());
|
||||
assert!(!nan.is_finite());
|
||||
|
@ -979,7 +978,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_infinity() {
|
||||
let inf: f64 = INFINITY;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
assert!(inf.is_infinite());
|
||||
assert!(!inf.is_finite());
|
||||
assert!(inf.is_sign_positive());
|
||||
|
@ -991,7 +990,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_neg_infinity() {
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert!(neg_inf.is_infinite());
|
||||
assert!(!neg_inf.is_finite());
|
||||
assert!(!neg_inf.is_sign_positive());
|
||||
|
@ -1043,9 +1042,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_is_nan() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert!(nan.is_nan());
|
||||
assert!(!0.0f64.is_nan());
|
||||
assert!(!5.3f64.is_nan());
|
||||
|
@ -1056,9 +1055,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_is_infinite() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert!(!nan.is_infinite());
|
||||
assert!(inf.is_infinite());
|
||||
assert!(neg_inf.is_infinite());
|
||||
|
@ -1069,9 +1068,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_is_finite() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert!(!nan.is_finite());
|
||||
assert!(!inf.is_finite());
|
||||
assert!(!neg_inf.is_finite());
|
||||
|
@ -1083,9 +1082,9 @@ mod tests {
|
|||
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
|
||||
#[test]
|
||||
fn test_is_normal() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let zero: f64 = 0.0f64;
|
||||
let neg_zero: f64 = -0.0;
|
||||
assert!(!nan.is_normal());
|
||||
|
@ -1101,9 +1100,9 @@ mod tests {
|
|||
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
|
||||
#[test]
|
||||
fn test_classify() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let zero: f64 = 0.0f64;
|
||||
let neg_zero: f64 = -0.0;
|
||||
assert_eq!(nan.classify(), Fp::Nan);
|
||||
|
@ -1187,59 +1186,59 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
assert_eq!(INFINITY.abs(), INFINITY);
|
||||
assert_eq!(f64::INFINITY.abs(), f64::INFINITY);
|
||||
assert_eq!(1f64.abs(), 1f64);
|
||||
assert_eq!(0f64.abs(), 0f64);
|
||||
assert_eq!((-0f64).abs(), 0f64);
|
||||
assert_eq!((-1f64).abs(), 1f64);
|
||||
assert_eq!(NEG_INFINITY.abs(), INFINITY);
|
||||
assert_eq!((1f64 / NEG_INFINITY).abs(), 0f64);
|
||||
assert!(NAN.abs().is_nan());
|
||||
assert_eq!(f64::NEG_INFINITY.abs(), f64::INFINITY);
|
||||
assert_eq!((1f64 / f64::NEG_INFINITY).abs(), 0f64);
|
||||
assert!(f64::NAN.abs().is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_signum() {
|
||||
assert_eq!(INFINITY.signum(), 1f64);
|
||||
assert_eq!(f64::INFINITY.signum(), 1f64);
|
||||
assert_eq!(1f64.signum(), 1f64);
|
||||
assert_eq!(0f64.signum(), 1f64);
|
||||
assert_eq!((-0f64).signum(), -1f64);
|
||||
assert_eq!((-1f64).signum(), -1f64);
|
||||
assert_eq!(NEG_INFINITY.signum(), -1f64);
|
||||
assert_eq!((1f64 / NEG_INFINITY).signum(), -1f64);
|
||||
assert!(NAN.signum().is_nan());
|
||||
assert_eq!(f64::NEG_INFINITY.signum(), -1f64);
|
||||
assert_eq!((1f64 / f64::NEG_INFINITY).signum(), -1f64);
|
||||
assert!(f64::NAN.signum().is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_sign_positive() {
|
||||
assert!(INFINITY.is_sign_positive());
|
||||
assert!(f64::INFINITY.is_sign_positive());
|
||||
assert!(1f64.is_sign_positive());
|
||||
assert!(0f64.is_sign_positive());
|
||||
assert!(!(-0f64).is_sign_positive());
|
||||
assert!(!(-1f64).is_sign_positive());
|
||||
assert!(!NEG_INFINITY.is_sign_positive());
|
||||
assert!(!(1f64 / NEG_INFINITY).is_sign_positive());
|
||||
assert!(NAN.is_sign_positive());
|
||||
assert!(!(-NAN).is_sign_positive());
|
||||
assert!(!f64::NEG_INFINITY.is_sign_positive());
|
||||
assert!(!(1f64 / f64::NEG_INFINITY).is_sign_positive());
|
||||
assert!(f64::NAN.is_sign_positive());
|
||||
assert!(!(-f64::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_sign_negative() {
|
||||
assert!(!INFINITY.is_sign_negative());
|
||||
assert!(!f64::INFINITY.is_sign_negative());
|
||||
assert!(!1f64.is_sign_negative());
|
||||
assert!(!0f64.is_sign_negative());
|
||||
assert!((-0f64).is_sign_negative());
|
||||
assert!((-1f64).is_sign_negative());
|
||||
assert!(NEG_INFINITY.is_sign_negative());
|
||||
assert!((1f64 / NEG_INFINITY).is_sign_negative());
|
||||
assert!(!NAN.is_sign_negative());
|
||||
assert!((-NAN).is_sign_negative());
|
||||
assert!(f64::NEG_INFINITY.is_sign_negative());
|
||||
assert!((1f64 / f64::NEG_INFINITY).is_sign_negative());
|
||||
assert!(!f64::NAN.is_sign_negative());
|
||||
assert!((-f64::NAN).is_sign_negative());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mul_add() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_approx_eq!(12.3f64.mul_add(4.5, 6.7), 62.05);
|
||||
assert_approx_eq!((-12.3f64).mul_add(-4.5, -6.7), 48.65);
|
||||
assert_approx_eq!(0.0f64.mul_add(8.9, 1.2), 1.2);
|
||||
|
@ -1253,9 +1252,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_recip() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(1.0f64.recip(), 1.0);
|
||||
assert_eq!(2.0f64.recip(), 0.5);
|
||||
assert_eq!((-0.4f64).recip(), -2.5);
|
||||
|
@ -1267,9 +1266,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_powi() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(1.0f64.powi(1), 1.0);
|
||||
assert_approx_eq!((-3.1f64).powi(2), 9.61);
|
||||
assert_approx_eq!(5.9f64.powi(-2), 0.028727);
|
||||
|
@ -1281,9 +1280,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_powf() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(1.0f64.powf(1.0), 1.0);
|
||||
assert_approx_eq!(3.4f64.powf(4.5), 246.408183);
|
||||
assert_approx_eq!(2.7f64.powf(-3.2), 0.041652);
|
||||
|
@ -1297,13 +1296,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_sqrt_domain() {
|
||||
assert!(NAN.sqrt().is_nan());
|
||||
assert!(NEG_INFINITY.sqrt().is_nan());
|
||||
assert!(f64::NAN.sqrt().is_nan());
|
||||
assert!(f64::NEG_INFINITY.sqrt().is_nan());
|
||||
assert!((-1.0f64).sqrt().is_nan());
|
||||
assert_eq!((-0.0f64).sqrt(), -0.0);
|
||||
assert_eq!(0.0f64.sqrt(), 0.0);
|
||||
assert_eq!(1.0f64.sqrt(), 1.0);
|
||||
assert_eq!(INFINITY.sqrt(), INFINITY);
|
||||
assert_eq!(f64::INFINITY.sqrt(), f64::INFINITY);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1312,9 +1311,9 @@ mod tests {
|
|||
assert_approx_eq!(2.718282, 1.0f64.exp());
|
||||
assert_approx_eq!(148.413159, 5.0f64.exp());
|
||||
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert_eq!(inf, inf.exp());
|
||||
assert_eq!(0.0, neg_inf.exp());
|
||||
assert!(nan.exp().is_nan());
|
||||
|
@ -1325,9 +1324,9 @@ mod tests {
|
|||
assert_eq!(32.0, 5.0f64.exp2());
|
||||
assert_eq!(1.0, 0.0f64.exp2());
|
||||
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert_eq!(inf, inf.exp2());
|
||||
assert_eq!(0.0, neg_inf.exp2());
|
||||
assert!(nan.exp2().is_nan());
|
||||
|
@ -1335,9 +1334,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ln() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_approx_eq!(1.0f64.exp().ln(), 1.0);
|
||||
assert!(nan.ln().is_nan());
|
||||
assert_eq!(inf.ln(), inf);
|
||||
|
@ -1350,9 +1349,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_log() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(10.0f64.log(10.0), 1.0);
|
||||
assert_approx_eq!(2.3f64.log(3.5), 0.664858);
|
||||
assert_eq!(1.0f64.exp().log(1.0f64.exp()), 1.0);
|
||||
|
@ -1368,9 +1367,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_log2() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_approx_eq!(10.0f64.log2(), 3.321928);
|
||||
assert_approx_eq!(2.3f64.log2(), 1.201634);
|
||||
assert_approx_eq!(1.0f64.exp().log2(), 1.442695);
|
||||
|
@ -1384,9 +1383,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_log10() {
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(10.0f64.log10(), 1.0);
|
||||
assert_approx_eq!(2.3f64.log10(), 0.361728);
|
||||
assert_approx_eq!(1.0f64.exp().log10(), 0.434294);
|
||||
|
@ -1402,9 +1401,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_degrees() {
|
||||
let pi: f64 = consts::PI;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(0.0f64.to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8f64).to_degrees(), -332.315521);
|
||||
assert_eq!(pi.to_degrees(), 180.0);
|
||||
|
@ -1416,9 +1415,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_radians() {
|
||||
let pi: f64 = consts::PI;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_eq!(0.0f64.to_radians(), 0.0);
|
||||
assert_approx_eq!(154.6f64.to_radians(), 2.698279);
|
||||
assert_approx_eq!((-332.31f64).to_radians(), -5.799903);
|
||||
|
@ -1433,9 +1432,9 @@ mod tests {
|
|||
assert_eq!(0.0f64.asinh(), 0.0f64);
|
||||
assert_eq!((-0.0f64).asinh(), -0.0f64);
|
||||
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert_eq!(inf.asinh(), inf);
|
||||
assert_eq!(neg_inf.asinh(), neg_inf);
|
||||
assert!(nan.asinh().is_nan());
|
||||
|
@ -1450,9 +1449,9 @@ mod tests {
|
|||
assert_eq!(1.0f64.acosh(), 0.0f64);
|
||||
assert!(0.999f64.acosh().is_nan());
|
||||
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert_eq!(inf.acosh(), inf);
|
||||
assert!(neg_inf.acosh().is_nan());
|
||||
assert!(nan.acosh().is_nan());
|
||||
|
@ -1465,9 +1464,9 @@ mod tests {
|
|||
assert_eq!(0.0f64.atanh(), 0.0f64);
|
||||
assert_eq!((-0.0f64).atanh(), -0.0f64);
|
||||
|
||||
let inf: f64 = INFINITY;
|
||||
let neg_inf: f64 = NEG_INFINITY;
|
||||
let nan: f64 = NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let nan: f64 = f64::NAN;
|
||||
assert_eq!(1.0f64.atanh(), inf);
|
||||
assert_eq!((-1.0f64).atanh(), neg_inf);
|
||||
assert!(2f64.atanh().atanh().is_nan());
|
||||
|
@ -1546,13 +1545,13 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
let _ = 1.0f64.clamp(NAN, 1.0);
|
||||
let _ = 1.0f64.clamp(f64::NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
let _ = 1.0f64.clamp(3.0, NAN);
|
||||
let _ = 1.0f64.clamp(3.0, f64::NAN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -366,7 +366,7 @@ impl<R: Seek> Seek for BufReader<R> {
|
|||
// it should be safe to assume that remainder fits within an i64 as the alternative
|
||||
// means we managed to allocate 8 exbibytes and that's absurd.
|
||||
// But it's not out of the realm of possibility for some weird underlying reader to
|
||||
// support seeking by i64::min_value() so we need to handle underflow when subtracting
|
||||
// support seeking by i64::MIN so we need to handle underflow when subtracting
|
||||
// remainder.
|
||||
if let Some(offset) = n.checked_sub(remainder) {
|
||||
result = self.inner.seek(SeekFrom::Current(offset))?;
|
||||
|
@ -1268,7 +1268,7 @@ mod tests {
|
|||
self.pos = self.pos.wrapping_add(n as u64);
|
||||
}
|
||||
SeekFrom::End(n) => {
|
||||
self.pos = u64::max_value().wrapping_add(n as u64);
|
||||
self.pos = u64::MAX.wrapping_add(n as u64);
|
||||
}
|
||||
}
|
||||
Ok(self.pos)
|
||||
|
@ -1277,11 +1277,11 @@ mod tests {
|
|||
|
||||
let mut reader = BufReader::with_capacity(5, PositionReader { pos: 0 });
|
||||
assert_eq!(reader.fill_buf().ok(), Some(&[0, 1, 2, 3, 4][..]));
|
||||
assert_eq!(reader.seek(SeekFrom::End(-5)).ok(), Some(u64::max_value() - 5));
|
||||
assert_eq!(reader.seek(SeekFrom::End(-5)).ok(), Some(u64::MAX - 5));
|
||||
assert_eq!(reader.fill_buf().ok().map(|s| s.len()), Some(5));
|
||||
// the following seek will require two underlying seeks
|
||||
let expected = 9223372036854775802;
|
||||
assert_eq!(reader.seek(SeekFrom::Current(i64::min_value())).ok(), Some(expected));
|
||||
assert_eq!(reader.seek(SeekFrom::Current(i64::MIN)).ok(), Some(expected));
|
||||
assert_eq!(reader.fill_buf().ok().map(|s| s.len()), Some(5));
|
||||
// seeking to 0 should empty the buffer.
|
||||
assert_eq!(reader.seek(SeekFrom::Current(0)).ok(), Some(expected));
|
||||
|
@ -1319,7 +1319,7 @@ mod tests {
|
|||
// The following seek will require two underlying seeks. The first will
|
||||
// succeed but the second will fail. This should still invalidate the
|
||||
// buffer.
|
||||
assert!(reader.seek(SeekFrom::Current(i64::min_value())).is_err());
|
||||
assert!(reader.seek(SeekFrom::Current(i64::MIN)).is_err());
|
||||
assert_eq!(reader.buffer().len(), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -963,7 +963,7 @@ mod tests {
|
|||
#[cfg(target_pointer_width = "32")]
|
||||
fn vec_seek_and_write_past_usize_max() {
|
||||
let mut c = Cursor::new(Vec::new());
|
||||
c.set_position(<usize>::max_value() as u64 + 1);
|
||||
c.set_position(usize::MAX as u64 + 1);
|
||||
assert!(c.write_all(&[1, 2, 3]).is_err());
|
||||
}
|
||||
|
||||
|
|
|
@ -52,52 +52,43 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ops::Mul;
|
||||
use crate::u16;
|
||||
use crate::u32;
|
||||
use crate::u64;
|
||||
use crate::u8;
|
||||
use crate::usize;
|
||||
|
||||
#[test]
|
||||
fn test_saturating_add_uint() {
|
||||
use crate::usize::MAX;
|
||||
assert_eq!(3_usize.saturating_add(5_usize), 8_usize);
|
||||
assert_eq!(3_usize.saturating_add(MAX - 1), MAX);
|
||||
assert_eq!(MAX.saturating_add(MAX), MAX);
|
||||
assert_eq!((MAX - 2).saturating_add(1), MAX - 1);
|
||||
assert_eq!(3_usize.saturating_add(usize::MAX - 1), usize::MAX);
|
||||
assert_eq!(usize::MAX.saturating_add(usize::MAX), usize::MAX);
|
||||
assert_eq!((usize::MAX - 2).saturating_add(1), usize::MAX - 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saturating_sub_uint() {
|
||||
use crate::usize::MAX;
|
||||
assert_eq!(5_usize.saturating_sub(3_usize), 2_usize);
|
||||
assert_eq!(3_usize.saturating_sub(5_usize), 0_usize);
|
||||
assert_eq!(0_usize.saturating_sub(1_usize), 0_usize);
|
||||
assert_eq!((MAX - 1).saturating_sub(MAX), 0);
|
||||
assert_eq!((usize::MAX - 1).saturating_sub(usize::MAX), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saturating_add_int() {
|
||||
use crate::isize::{MAX, MIN};
|
||||
assert_eq!(3i32.saturating_add(5), 8);
|
||||
assert_eq!(3isize.saturating_add(MAX - 1), MAX);
|
||||
assert_eq!(MAX.saturating_add(MAX), MAX);
|
||||
assert_eq!((MAX - 2).saturating_add(1), MAX - 1);
|
||||
assert_eq!(3isize.saturating_add(isize::MAX - 1), isize::MAX);
|
||||
assert_eq!(isize::MAX.saturating_add(isize::MAX), isize::MAX);
|
||||
assert_eq!((isize::MAX - 2).saturating_add(1), isize::MAX - 1);
|
||||
assert_eq!(3i32.saturating_add(-5), -2);
|
||||
assert_eq!(MIN.saturating_add(-1), MIN);
|
||||
assert_eq!((-2isize).saturating_add(-MAX), MIN);
|
||||
assert_eq!(isize::MIN.saturating_add(-1), isize::MIN);
|
||||
assert_eq!((-2isize).saturating_add(-isize::MAX), isize::MIN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saturating_sub_int() {
|
||||
use crate::isize::{MAX, MIN};
|
||||
assert_eq!(3i32.saturating_sub(5), -2);
|
||||
assert_eq!(MIN.saturating_sub(1), MIN);
|
||||
assert_eq!((-2isize).saturating_sub(MAX), MIN);
|
||||
assert_eq!(isize::MIN.saturating_sub(1), isize::MIN);
|
||||
assert_eq!((-2isize).saturating_sub(isize::MAX), isize::MIN);
|
||||
assert_eq!(3i32.saturating_sub(-5), 8);
|
||||
assert_eq!(3isize.saturating_sub(-(MAX - 1)), MAX);
|
||||
assert_eq!(MAX.saturating_sub(-MAX), MAX);
|
||||
assert_eq!((MAX - 2).saturating_sub(-1), MAX - 1);
|
||||
assert_eq!(3isize.saturating_sub(-(isize::MAX - 1)), isize::MAX);
|
||||
assert_eq!(isize::MAX.saturating_sub(-isize::MAX), isize::MAX);
|
||||
assert_eq!((isize::MAX - 2).saturating_sub(-1), isize::MAX - 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -609,7 +609,6 @@ mod tests {
|
|||
use crate::sync::{Arc, Condvar, Mutex};
|
||||
use crate::thread;
|
||||
use crate::time::Duration;
|
||||
use crate::u64;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
|
|
|
@ -2176,8 +2176,7 @@ mod tests {
|
|||
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
|
||||
fn very_long_recv_timeout_wont_panic() {
|
||||
let (tx, rx) = channel::<()>();
|
||||
let join_handle =
|
||||
thread::spawn(move || rx.recv_timeout(Duration::from_secs(u64::max_value())));
|
||||
let join_handle = thread::spawn(move || rx.recv_timeout(Duration::from_secs(u64::MAX)));
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
assert!(tx.send(()).is_ok());
|
||||
assert_eq!(join_handle.join().unwrap(), Ok(()));
|
||||
|
|
|
@ -42,7 +42,7 @@ impl Condvar {
|
|||
let ret = abi::condvar_signal(
|
||||
condvar as *mut abi::condvar,
|
||||
abi::scope::PRIVATE,
|
||||
abi::nthreads::max_value(),
|
||||
abi::nthreads::MAX,
|
||||
);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to broadcast on condition variable");
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Condvar {
|
|||
|
||||
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
|
||||
let nanos = dur.as_nanos();
|
||||
let nanos = cmp::min(i64::max_value() as u128, nanos);
|
||||
let nanos = cmp::min(i64::MAX as u128, nanos);
|
||||
|
||||
// add current task to the wait queue
|
||||
let _ = abi::add_queue(self.id(), nanos as i64);
|
||||
|
|
|
@ -95,7 +95,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
|
|||
match ftruncate64.get() {
|
||||
Some(f) => cvt_r(|| f(fd, size as i64)).map(drop),
|
||||
None => {
|
||||
if size > i32::max_value() as u64 {
|
||||
if size > i32::MAX as u64 {
|
||||
Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB"))
|
||||
} else {
|
||||
cvt_r(|| ftruncate(fd, size as i32)).map(drop)
|
||||
|
|
|
@ -10,14 +10,10 @@ unsafe impl Send for Condvar {}
|
|||
unsafe impl Sync for Condvar {}
|
||||
|
||||
const TIMESPEC_MAX: libc::timespec =
|
||||
libc::timespec { tv_sec: <libc::time_t>::max_value(), tv_nsec: 1_000_000_000 - 1 };
|
||||
libc::timespec { tv_sec: <libc::time_t>::MAX, tv_nsec: 1_000_000_000 - 1 };
|
||||
|
||||
fn saturating_cast_to_time_t(value: u64) -> libc::time_t {
|
||||
if value > <libc::time_t>::max_value() as u64 {
|
||||
<libc::time_t>::max_value()
|
||||
} else {
|
||||
value as libc::time_t
|
||||
}
|
||||
if value > <libc::time_t>::MAX as u64 { <libc::time_t>::MAX } else { value as libc::time_t }
|
||||
}
|
||||
|
||||
impl Condvar {
|
||||
|
|
|
@ -1090,7 +1090,7 @@ impl<'a> Iterator for Incoming<'a> {
|
|||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(usize::max_value(), None)
|
||||
(usize::MAX, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,7 @@ fn max_len() -> usize {
|
|||
// intentionally showing odd behavior by rejecting any read with a size
|
||||
// larger than or equal to INT_MAX. To handle both of these the read
|
||||
// size is capped on both platforms.
|
||||
if cfg!(target_os = "macos") {
|
||||
<c_int>::max_value() as usize - 1
|
||||
} else {
|
||||
<ssize_t>::max_value() as usize
|
||||
}
|
||||
if cfg!(target_os = "macos") { <c_int>::MAX as usize - 1 } else { <ssize_t>::MAX as usize }
|
||||
}
|
||||
|
||||
impl FileDesc {
|
||||
|
@ -58,7 +54,7 @@ impl FileDesc {
|
|||
libc::readv(
|
||||
self.fd,
|
||||
bufs.as_ptr() as *const libc::iovec,
|
||||
cmp::min(bufs.len(), c_int::max_value() as usize) as c_int,
|
||||
cmp::min(bufs.len(), c_int::MAX as usize) as c_int,
|
||||
)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
|
@ -115,7 +111,7 @@ impl FileDesc {
|
|||
libc::writev(
|
||||
self.fd,
|
||||
bufs.as_ptr() as *const libc::iovec,
|
||||
cmp::min(bufs.len(), c_int::max_value() as usize) as c_int,
|
||||
cmp::min(bufs.len(), c_int::MAX as usize) as c_int,
|
||||
)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
|
|
|
@ -1196,7 +1196,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
|||
let mut written = 0u64;
|
||||
while written < len {
|
||||
let copy_result = if has_copy_file_range {
|
||||
let bytes_to_copy = cmp::min(len - written, usize::max_value() as u64) as usize;
|
||||
let bytes_to_copy = cmp::min(len - written, usize::MAX as u64) as usize;
|
||||
let copy_result = unsafe {
|
||||
// We actually don't have to adjust the offsets,
|
||||
// because copy_file_range adjusts the file offset automatically
|
||||
|
|
|
@ -148,7 +148,7 @@ impl Socket {
|
|||
timeout = 1;
|
||||
}
|
||||
|
||||
let timeout = cmp::min(timeout, c_int::max_value() as u64) as c_int;
|
||||
let timeout = cmp::min(timeout, c_int::MAX as u64) as c_int;
|
||||
|
||||
match unsafe { libc::poll(&mut pollfd, 1, timeout) } {
|
||||
-1 => {
|
||||
|
@ -283,8 +283,8 @@ impl Socket {
|
|||
));
|
||||
}
|
||||
|
||||
let secs = if dur.as_secs() > libc::time_t::max_value() as u64 {
|
||||
libc::time_t::max_value()
|
||||
let secs = if dur.as_secs() > libc::time_t::MAX as u64 {
|
||||
libc::time_t::MAX
|
||||
} else {
|
||||
dur.as_secs() as libc::time_t
|
||||
};
|
||||
|
|
|
@ -171,7 +171,7 @@ impl Thread {
|
|||
unsafe {
|
||||
while secs > 0 || nsecs > 0 {
|
||||
let mut ts = libc::timespec {
|
||||
tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t,
|
||||
tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t,
|
||||
tv_nsec: nsecs,
|
||||
};
|
||||
secs -= ts.tv_sec as u64;
|
||||
|
|
|
@ -10,14 +10,10 @@ unsafe impl Send for Condvar {}
|
|||
unsafe impl Sync for Condvar {}
|
||||
|
||||
const TIMESPEC_MAX: libc::timespec =
|
||||
libc::timespec { tv_sec: <libc::time_t>::max_value(), tv_nsec: 1_000_000_000 - 1 };
|
||||
libc::timespec { tv_sec: <libc::time_t>::MAX, tv_nsec: 1_000_000_000 - 1 };
|
||||
|
||||
fn saturating_cast_to_time_t(value: u64) -> libc::time_t {
|
||||
if value > <libc::time_t>::max_value() as u64 {
|
||||
<libc::time_t>::max_value()
|
||||
} else {
|
||||
value as libc::time_t
|
||||
}
|
||||
if value > <libc::time_t>::MAX as u64 { <libc::time_t>::MAX } else { value as libc::time_t }
|
||||
}
|
||||
|
||||
impl Condvar {
|
||||
|
|
|
@ -17,7 +17,7 @@ fn max_len() -> usize {
|
|||
// The maximum read limit on most posix-like systems is `SSIZE_MAX`,
|
||||
// with the man page quoting that if the count of bytes to read is
|
||||
// greater than `SSIZE_MAX` the result is "unspecified".
|
||||
<ssize_t>::max_value() as usize
|
||||
<ssize_t>::MAX as usize
|
||||
}
|
||||
|
||||
impl FileDesc {
|
||||
|
@ -48,7 +48,7 @@ impl FileDesc {
|
|||
libc::readv(
|
||||
self.fd,
|
||||
bufs.as_ptr() as *const libc::iovec,
|
||||
cmp::min(bufs.len(), c_int::max_value() as usize) as c_int,
|
||||
cmp::min(bufs.len(), c_int::MAX as usize) as c_int,
|
||||
)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
|
@ -98,7 +98,7 @@ impl FileDesc {
|
|||
libc::writev(
|
||||
self.fd,
|
||||
bufs.as_ptr() as *const libc::iovec,
|
||||
cmp::min(bufs.len(), c_int::max_value() as usize) as c_int,
|
||||
cmp::min(bufs.len(), c_int::MAX as usize) as c_int,
|
||||
)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
|
|
|
@ -107,7 +107,7 @@ impl Socket {
|
|||
timeout = 1;
|
||||
}
|
||||
|
||||
let timeout = cmp::min(timeout, c_int::max_value() as u64) as c_int;
|
||||
let timeout = cmp::min(timeout, c_int::MAX as u64) as c_int;
|
||||
|
||||
match unsafe { libc::poll(&mut pollfd, 1, timeout) } {
|
||||
-1 => {
|
||||
|
@ -220,8 +220,8 @@ impl Socket {
|
|||
));
|
||||
}
|
||||
|
||||
let secs = if dur.as_secs() > libc::time_t::max_value() as u64 {
|
||||
libc::time_t::max_value()
|
||||
let secs = if dur.as_secs() > libc::time_t::MAX as u64 {
|
||||
libc::time_t::MAX
|
||||
} else {
|
||||
dur.as_secs() as libc::time_t
|
||||
};
|
||||
|
|
|
@ -96,7 +96,7 @@ impl Thread {
|
|||
unsafe {
|
||||
while secs > 0 || nsecs > 0 {
|
||||
let mut ts = libc::timespec {
|
||||
tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t,
|
||||
tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t,
|
||||
tv_nsec: nsecs,
|
||||
};
|
||||
secs -= ts.tv_sec as u64;
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn unsupported_err() -> std_io::Error {
|
|||
|
||||
pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
|
||||
use std_io::ErrorKind::*;
|
||||
if errno > u16::max_value() as i32 || errno < 0 {
|
||||
if errno > u16::MAX as i32 || errno < 0 {
|
||||
return Other;
|
||||
}
|
||||
match errno as u16 {
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Thread {
|
|||
|
||||
pub fn sleep(dur: Duration) {
|
||||
let nanos = dur.as_nanos();
|
||||
assert!(nanos <= u64::max_value() as u128);
|
||||
assert!(nanos <= u64::MAX as u128);
|
||||
|
||||
const USERDATA: wasi::Userdata = 0x0123_45678;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Condvar {
|
|||
#[inline]
|
||||
pub unsafe fn notify_all(&self) {
|
||||
self.cnt.fetch_add(1, SeqCst);
|
||||
wasm32::atomic_notify(self.ptr(), u32::max_value()); // -1 == "wake everyone"
|
||||
wasm32::atomic_notify(self.ptr(), u32::MAX); // -1 == "wake everyone"
|
||||
}
|
||||
|
||||
pub unsafe fn wait(&self, mutex: &Mutex) {
|
||||
|
@ -72,7 +72,7 @@ impl Condvar {
|
|||
let ticket = self.cnt.load(SeqCst) as i32;
|
||||
mutex.unlock();
|
||||
let nanos = dur.as_nanos();
|
||||
let nanos = cmp::min(i64::max_value() as u128, nanos);
|
||||
let nanos = cmp::min(i64::MAX as u128, nanos);
|
||||
|
||||
// If the return value is 2 then a timeout happened, so we return
|
||||
// `false` as we weren't actually notified.
|
||||
|
|
|
@ -38,7 +38,7 @@ impl Thread {
|
|||
// 2).
|
||||
let mut nanos = dur.as_nanos();
|
||||
while nanos > 0 {
|
||||
let amt = cmp::min(i64::max_value() as u128, nanos);
|
||||
let amt = cmp::min(i64::MAX as u128, nanos);
|
||||
let mut x = 0;
|
||||
let val = unsafe { wasm32::i32_atomic_wait(&mut x, 0, amt as i64) };
|
||||
debug_assert_eq!(val, 2);
|
||||
|
|
|
@ -70,7 +70,7 @@ impl RawHandle {
|
|||
|
||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
let mut read = 0;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
|
||||
let res = cvt(unsafe {
|
||||
c::ReadFile(self.0, buf.as_mut_ptr() as c::LPVOID, len, &mut read, ptr::null_mut())
|
||||
});
|
||||
|
@ -99,7 +99,7 @@ impl RawHandle {
|
|||
|
||||
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
|
||||
let mut read = 0;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
|
||||
let res = unsafe {
|
||||
let mut overlapped: c::OVERLAPPED = mem::zeroed();
|
||||
overlapped.Offset = offset as u32;
|
||||
|
@ -118,7 +118,7 @@ impl RawHandle {
|
|||
buf: &mut [u8],
|
||||
overlapped: *mut c::OVERLAPPED,
|
||||
) -> io::Result<Option<usize>> {
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
|
||||
let mut amt = 0;
|
||||
let res = cvt(c::ReadFile(self.0, buf.as_ptr() as c::LPVOID, len, &mut amt, overlapped));
|
||||
match res {
|
||||
|
@ -165,7 +165,7 @@ impl RawHandle {
|
|||
|
||||
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
let mut amt = 0;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
|
||||
cvt(unsafe {
|
||||
c::WriteFile(self.0, buf.as_ptr() as c::LPVOID, len, &mut amt, ptr::null_mut())
|
||||
})?;
|
||||
|
@ -183,7 +183,7 @@ impl RawHandle {
|
|||
|
||||
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
|
||||
let mut written = 0;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
|
||||
unsafe {
|
||||
let mut overlapped: c::OVERLAPPED = mem::zeroed();
|
||||
overlapped.Offset = offset as u32;
|
||||
|
|
|
@ -12,7 +12,7 @@ pub struct IoSlice<'a> {
|
|||
impl<'a> IoSlice<'a> {
|
||||
#[inline]
|
||||
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
|
||||
assert!(buf.len() <= c::ULONG::max_value() as usize);
|
||||
assert!(buf.len() <= c::ULONG::MAX as usize);
|
||||
IoSlice {
|
||||
vec: c::WSABUF {
|
||||
len: buf.len() as c::ULONG,
|
||||
|
@ -49,7 +49,7 @@ pub struct IoSliceMut<'a> {
|
|||
impl<'a> IoSliceMut<'a> {
|
||||
#[inline]
|
||||
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
|
||||
assert!(buf.len() <= c::ULONG::max_value() as usize);
|
||||
assert!(buf.len() <= c::ULONG::MAX as usize);
|
||||
IoSliceMut {
|
||||
vec: c::WSABUF { len: buf.len() as c::ULONG, buf: buf.as_mut_ptr() as *mut c::CHAR },
|
||||
_p: PhantomData,
|
||||
|
|
|
@ -295,7 +295,7 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD {
|
|||
.checked_mul(1000)
|
||||
.and_then(|ms| ms.checked_add((dur.subsec_nanos() as u64) / 1_000_000))
|
||||
.and_then(|ms| ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 { 1 } else { 0 }))
|
||||
.map(|ms| if ms > <c::DWORD>::max_value() as u64 { c::INFINITE } else { ms as c::DWORD })
|
||||
.map(|ms| if ms > <c::DWORD>::MAX as u64 { c::INFINITE } else { ms as c::DWORD })
|
||||
.unwrap_or(c::INFINITE)
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ impl Socket {
|
|||
fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> {
|
||||
// On unix when a socket is shut down all further reads return 0, so we
|
||||
// do the same on windows to map a shut down socket to returning EOF.
|
||||
let len = cmp::min(buf.len(), i32::max_value() as usize) as i32;
|
||||
let len = cmp::min(buf.len(), i32::MAX as usize) as i32;
|
||||
unsafe {
|
||||
match c::recv(self.0, buf.as_mut_ptr() as *mut c_void, len, flags) {
|
||||
-1 if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0),
|
||||
|
@ -245,7 +245,7 @@ impl Socket {
|
|||
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
// On unix when a socket is shut down all further reads return 0, so we
|
||||
// do the same on windows to map a shut down socket to returning EOF.
|
||||
let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(bufs.len(), c::DWORD::MAX as usize) as c::DWORD;
|
||||
let mut nread = 0;
|
||||
let mut flags = 0;
|
||||
unsafe {
|
||||
|
@ -282,7 +282,7 @@ impl Socket {
|
|||
) -> io::Result<(usize, SocketAddr)> {
|
||||
let mut storage: c::SOCKADDR_STORAGE_LH = unsafe { mem::zeroed() };
|
||||
let mut addrlen = mem::size_of_val(&storage) as c::socklen_t;
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
|
||||
|
||||
// On unix when a socket is shut down all further reads return 0, so we
|
||||
// do the same on windows to map a shut down socket to returning EOF.
|
||||
|
@ -313,7 +313,7 @@ impl Socket {
|
|||
}
|
||||
|
||||
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
|
||||
let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD;
|
||||
let len = cmp::min(bufs.len(), c::DWORD::MAX as usize) as c::DWORD;
|
||||
let mut nwritten = 0;
|
||||
unsafe {
|
||||
cvt(c::WSASend(
|
||||
|
|
|
@ -271,7 +271,7 @@ impl TcpStream {
|
|||
}
|
||||
|
||||
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
|
||||
let ret = cvt(unsafe {
|
||||
c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, MSG_NOSIGNAL)
|
||||
})?;
|
||||
|
@ -502,7 +502,7 @@ impl UdpSocket {
|
|||
}
|
||||
|
||||
pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result<usize> {
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
|
||||
let (dstp, dstlen) = dst.into_inner();
|
||||
let ret = cvt(unsafe {
|
||||
c::sendto(
|
||||
|
@ -641,7 +641,7 @@ impl UdpSocket {
|
|||
}
|
||||
|
||||
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
|
||||
let len = cmp::min(buf.len(), <wrlen_t>::MAX as usize) as wrlen_t;
|
||||
let ret = cvt(unsafe {
|
||||
c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, MSG_NOSIGNAL)
|
||||
})?;
|
||||
|
|
|
@ -1530,7 +1530,6 @@ mod tests {
|
|||
use crate::sync::mpsc::{channel, Sender};
|
||||
use crate::thread::{self, ThreadId};
|
||||
use crate::time::Duration;
|
||||
use crate::u32;
|
||||
|
||||
// !!! These tests are dangerous. If something is buggy, they will hang, !!!
|
||||
// !!! instead of exiting cleanly. This might wedge the buildbots. !!!
|
||||
|
|
|
@ -686,7 +686,7 @@ mod tests {
|
|||
|
||||
// checked_add_duration will not panic on overflow
|
||||
let mut maybe_t = Some(Instant::now());
|
||||
let max_duration = Duration::from_secs(u64::max_value());
|
||||
let max_duration = Duration::from_secs(u64::MAX);
|
||||
// in case `Instant` can store `>= now + max_duration`.
|
||||
for _ in 0..2 {
|
||||
maybe_t = maybe_t.and_then(|t| t.checked_add(max_duration));
|
||||
|
@ -766,7 +766,7 @@ mod tests {
|
|||
|
||||
// checked_add_duration will not panic on overflow
|
||||
let mut maybe_t = Some(SystemTime::UNIX_EPOCH);
|
||||
let max_duration = Duration::from_secs(u64::max_value());
|
||||
let max_duration = Duration::from_secs(u64::MAX);
|
||||
// in case `SystemTime` can store `>= UNIX_EPOCH + max_duration`.
|
||||
for _ in 0..2 {
|
||||
maybe_t = maybe_t.and_then(|t| t.checked_add(max_duration));
|
||||
|
|
|
@ -28,8 +28,8 @@ pub const CONST_CALC_I32: i32 = 42 + 1;
|
|||
// @!has show_const_contents/constant.CONST_REF_I32.html '; //'
|
||||
pub const CONST_REF_I32: &'static i32 = &42;
|
||||
|
||||
// @has show_const_contents/constant.CONST_I32_MAX.html '= i32::max_value(); // 2_147_483_647i32'
|
||||
pub const CONST_I32_MAX: i32 = i32::max_value();
|
||||
// @has show_const_contents/constant.CONST_I32_MAX.html '= i32::MAX; // 2_147_483_647i32'
|
||||
pub const CONST_I32_MAX: i32 = i32::MAX;
|
||||
|
||||
// @!has show_const_contents/constant.UNIT.html '= ();'
|
||||
// @!has show_const_contents/constant.UNIT.html '; //'
|
||||
|
@ -56,11 +56,11 @@ pub use std::i32::MAX;
|
|||
|
||||
macro_rules! int_module {
|
||||
($T:ident) => (
|
||||
pub const MIN: $T = $T::min_value();
|
||||
pub const MIN: $T = $T::MIN;
|
||||
)
|
||||
}
|
||||
|
||||
// @has show_const_contents/constant.MIN.html '= i16::min_value(); // -32_768i16'
|
||||
// @has show_const_contents/constant.MIN.html '= i16::MIN; // -32_768i16'
|
||||
int_module!(i16);
|
||||
|
||||
// @has show_const_contents/constant.ESCAPE.html //pre '= r#"<script>alert("ESCAPE");</script>"#;'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
enum Foo {
|
||||
// test that we detect overflows for non-u32 discriminants
|
||||
X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080
|
||||
X = 1 << ((u32::MAX as u64) + 1), //~ ERROR E0080
|
||||
Y = 42,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/shift_overflow.rs:3:9
|
||||
|
|
||||
LL | X = 1 << ((u32::max_value() as u64) + 1),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow
|
||||
LL | X = 1 << ((u32::MAX as u64) + 1),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ suite!(
|
|||
C6: 5i8.checked_mul(122), None;
|
||||
C7: (-127i8).checked_mul(-99), None;
|
||||
|
||||
C8: (i8::min_value() + 1).checked_div(-1), Some(127);
|
||||
C9: i8::min_value().checked_div(-1), None;
|
||||
C8: (i8::MIN + 1).checked_div(-1), Some(127);
|
||||
C9: i8::MIN.checked_div(-1), None;
|
||||
C10: 1i8.checked_div(0), None;
|
||||
|
||||
C11: 5i8.checked_rem(2), Some(1);
|
||||
|
@ -56,8 +56,8 @@ suite!(
|
|||
C21: i8::MIN.checked_abs(), None;
|
||||
|
||||
// `const_euclidean_int_methods`
|
||||
C22: (i8::min_value() + 1).checked_div_euclid(-1), Some(127);
|
||||
C23: i8::min_value().checked_div_euclid(-1), None;
|
||||
C22: (i8::MIN + 1).checked_div_euclid(-1), Some(127);
|
||||
C23: i8::MIN.checked_div_euclid(-1), None;
|
||||
C24: (1i8).checked_div_euclid(0), None;
|
||||
|
||||
C25: 5i8.checked_rem_euclid(2), Some(1);
|
||||
|
@ -72,12 +72,12 @@ suite!(
|
|||
saturating_and_wrapping -> i8 {
|
||||
// `const_saturating_int_methods`
|
||||
C28: 100i8.saturating_add(1), 101;
|
||||
C29: i8::max_value().saturating_add(100), i8::max_value();
|
||||
C30: i8::min_value().saturating_add(-1), i8::min_value();
|
||||
C29: i8::MAX.saturating_add(100), i8::MAX;
|
||||
C30: i8::MIN.saturating_add(-1), i8::MIN;
|
||||
|
||||
C31: 100i8.saturating_sub(127), -27;
|
||||
C32: i8::min_value().saturating_sub(100), i8::min_value();
|
||||
C33: i8::max_value().saturating_sub(-1), i8::max_value();
|
||||
C32: i8::MIN.saturating_sub(100), i8::MIN;
|
||||
C33: i8::MAX.saturating_sub(-1), i8::MAX;
|
||||
|
||||
C34: 10i8.saturating_mul(12), 120;
|
||||
C35: i8::MAX.saturating_mul(10), i8::MAX;
|
||||
|
@ -85,13 +85,13 @@ suite!(
|
|||
|
||||
C37: 100i8.saturating_neg(), -100;
|
||||
C38: (-100i8).saturating_neg(), 100;
|
||||
C39: i8::min_value().saturating_neg(), i8::max_value();
|
||||
C40: i8::max_value().saturating_neg(), i8::min_value() + 1;
|
||||
C39: i8::MIN.saturating_neg(), i8::MAX;
|
||||
C40: i8::MAX.saturating_neg(), i8::MIN + 1;
|
||||
|
||||
C57: 100i8.saturating_abs(), 100;
|
||||
C58: (-100i8).saturating_abs(), 100;
|
||||
C59: i8::min_value().saturating_abs(), i8::max_value();
|
||||
C60: (i8::min_value() + 1).saturating_abs(), i8::max_value();
|
||||
C59: i8::MIN.saturating_abs(), i8::MAX;
|
||||
C60: (i8::MIN + 1).saturating_abs(), i8::MAX;
|
||||
|
||||
// `const_wrapping_int_methods`
|
||||
C41: 100i8.wrapping_div(10), 10;
|
||||
|
|
|
@ -6,13 +6,13 @@ const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
|
|||
const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
|
||||
const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
|
||||
const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
|
||||
const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
|
||||
const TO_NE_BYTES: [u8; 4] = i32::MIN.to_be().to_ne_bytes();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(REVERSE, 0x1e6a2c48);
|
||||
assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
|
||||
assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
|
||||
assert_eq!(FROM_NE_BYTES, i32::min_value());
|
||||
assert_eq!(FROM_NE_BYTES, i32::MIN);
|
||||
assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
|
||||
assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
|
||||
assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
|
||||
|
|
|
@ -11,6 +11,6 @@ fn main() {
|
|||
//~^ ERROR temporary value dropped while borrowed
|
||||
let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes());
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
|
||||
let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes());
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
}
|
||||
|
|
|
@ -67,8 +67,8 @@ LL | }
|
|||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/const-int-conversion.rs:14:29
|
||||
|
|
||||
LL | let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
LL | let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes());
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
LL |
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// run-pass
|
||||
|
||||
const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
|
||||
const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
|
||||
const ADD_B: (u32, bool) = u32::MAX.overflowing_add(1);
|
||||
|
||||
const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
|
||||
const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
|
||||
|
@ -20,14 +20,14 @@ const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
|
|||
|
||||
const ABS_POS: (i32, bool) = 10i32.overflowing_abs();
|
||||
const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs();
|
||||
const ABS_MIN: (i32, bool) = i32::min_value().overflowing_abs();
|
||||
const ABS_MIN: (i32, bool) = i32::MIN.overflowing_abs();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(ADD_A, (7, false));
|
||||
assert_eq!(ADD_B, (0, true));
|
||||
|
||||
assert_eq!(SUB_A, (3, false));
|
||||
assert_eq!(SUB_B, (u32::max_value(), true));
|
||||
assert_eq!(SUB_B, (u32::MAX, true));
|
||||
|
||||
assert_eq!(MUL_A, (10, false));
|
||||
assert_eq!(MUL_B, (1410065408, true));
|
||||
|
@ -43,5 +43,5 @@ fn main() {
|
|||
|
||||
assert_eq!(ABS_POS, (10, false));
|
||||
assert_eq!(ABS_NEG, (10, false));
|
||||
assert_eq!(ABS_MIN, (i32::min_value(), true));
|
||||
assert_eq!(ABS_MIN, (i32::MIN, true));
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ const NEXT_POWER_OF_TWO: u32 = 3u32.next_power_of_two();
|
|||
|
||||
const CHECKED_NEXT_POWER_OF_TWO_OK: Option<u32> = 3u32.checked_next_power_of_two();
|
||||
const CHECKED_NEXT_POWER_OF_TWO_OVERFLOW: Option<u32> =
|
||||
u32::max_value().checked_next_power_of_two();
|
||||
u32::MAX.checked_next_power_of_two();
|
||||
|
||||
const WRAPPING_NEXT_POWER_OF_TWO: u32 =
|
||||
u32::max_value().wrapping_next_power_of_two();
|
||||
u32::MAX.wrapping_next_power_of_two();
|
||||
|
||||
fn main() {
|
||||
assert!(!IS_POWER_OF_TWO_A);
|
||||
|
@ -37,7 +37,7 @@ fn main() {
|
|||
|
||||
assert_eq!(WRAPPING_POW, 217);
|
||||
assert_eq!(OVERFLOWING_POW, (217, true));
|
||||
assert_eq!(SATURATING_POW, u8::max_value());
|
||||
assert_eq!(SATURATING_POW, u8::MAX);
|
||||
|
||||
assert_eq!(NEXT_POWER_OF_TWO, 4);
|
||||
|
||||
|
|
|
@ -2,33 +2,33 @@
|
|||
#![feature(const_saturating_int_methods)]
|
||||
|
||||
const INT_U32_NO: u32 = (42 as u32).saturating_add(2);
|
||||
const INT_U32: u32 = u32::max_value().saturating_add(1);
|
||||
const INT_U128: u128 = u128::max_value().saturating_add(1);
|
||||
const INT_I128: i128 = i128::max_value().saturating_add(1);
|
||||
const INT_I128_NEG: i128 = i128::min_value().saturating_add(-1);
|
||||
const INT_U32: u32 = u32::MAX.saturating_add(1);
|
||||
const INT_U128: u128 = u128::MAX.saturating_add(1);
|
||||
const INT_I128: i128 = i128::MAX.saturating_add(1);
|
||||
const INT_I128_NEG: i128 = i128::MIN.saturating_add(-1);
|
||||
|
||||
const INT_U32_NO_SUB: u32 = (42 as u32).saturating_sub(2);
|
||||
const INT_U32_SUB: u32 = (1 as u32).saturating_sub(2);
|
||||
const INT_I32_NO_SUB: i32 = (-42 as i32).saturating_sub(2);
|
||||
const INT_I32_NEG_SUB: i32 = i32::min_value().saturating_sub(1);
|
||||
const INT_I32_POS_SUB: i32 = i32::max_value().saturating_sub(-1);
|
||||
const INT_I32_NEG_SUB: i32 = i32::MIN.saturating_sub(1);
|
||||
const INT_I32_POS_SUB: i32 = i32::MAX.saturating_sub(-1);
|
||||
const INT_U128_SUB: u128 = (0 as u128).saturating_sub(1);
|
||||
const INT_I128_NEG_SUB: i128 = i128::min_value().saturating_sub(1);
|
||||
const INT_I128_POS_SUB: i128 = i128::max_value().saturating_sub(-1);
|
||||
const INT_I128_NEG_SUB: i128 = i128::MIN.saturating_sub(1);
|
||||
const INT_I128_POS_SUB: i128 = i128::MAX.saturating_sub(-1);
|
||||
|
||||
fn main() {
|
||||
assert_eq!(INT_U32_NO, 44);
|
||||
assert_eq!(INT_U32, u32::max_value());
|
||||
assert_eq!(INT_U128, u128::max_value());
|
||||
assert_eq!(INT_I128, i128::max_value());
|
||||
assert_eq!(INT_I128_NEG, i128::min_value());
|
||||
assert_eq!(INT_U32, u32::MAX);
|
||||
assert_eq!(INT_U128, u128::MAX);
|
||||
assert_eq!(INT_I128, i128::MAX);
|
||||
assert_eq!(INT_I128_NEG, i128::MIN);
|
||||
|
||||
assert_eq!(INT_U32_NO_SUB, 40);
|
||||
assert_eq!(INT_U32_SUB, 0);
|
||||
assert_eq!(INT_I32_NO_SUB, -44);
|
||||
assert_eq!(INT_I32_NEG_SUB, i32::min_value());
|
||||
assert_eq!(INT_I32_POS_SUB, i32::max_value());
|
||||
assert_eq!(INT_I32_NEG_SUB, i32::MIN);
|
||||
assert_eq!(INT_I32_POS_SUB, i32::MAX);
|
||||
assert_eq!(INT_U128_SUB, 0);
|
||||
assert_eq!(INT_I128_NEG_SUB, i128::min_value());
|
||||
assert_eq!(INT_I128_POS_SUB, i128::max_value());
|
||||
assert_eq!(INT_I128_NEG_SUB, i128::MIN);
|
||||
assert_eq!(INT_I128_POS_SUB, i128::MAX);
|
||||
}
|
||||
|
|
|
@ -131,12 +131,12 @@ const _: u16 = unsafe { std::intrinsics::unchecked_mul(300u16, 250u16) };
|
|||
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
|
||||
const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -355,8 +355,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) };
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/const-int-unchecked.rs:134:25
|
||||
|
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| overflow executing `unchecked_div`
|
||||
|
||||
|
@ -371,8 +371,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) };
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/const-int-unchecked.rs:139:25
|
||||
|
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) };
|
||||
| ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| overflow executing `unchecked_rem`
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// run-pass
|
||||
|
||||
const ADD_A: u32 = 200u32.wrapping_add(55);
|
||||
const ADD_B: u32 = 200u32.wrapping_add(u32::max_value());
|
||||
const ADD_B: u32 = 200u32.wrapping_add(u32::MAX);
|
||||
|
||||
const SUB_A: u32 = 100u32.wrapping_sub(100);
|
||||
const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value());
|
||||
const SUB_B: u32 = 100u32.wrapping_sub(u32::MAX);
|
||||
|
||||
const MUL_A: u8 = 10u8.wrapping_mul(12);
|
||||
const MUL_B: u8 = 25u8.wrapping_mul(12);
|
||||
|
@ -20,7 +20,7 @@ const NEG_B: u32 = 1234567890u32.wrapping_neg();
|
|||
|
||||
const ABS_POS: i32 = 10i32.wrapping_abs();
|
||||
const ABS_NEG: i32 = (-10i32).wrapping_abs();
|
||||
const ABS_MIN: i32 = i32::min_value().wrapping_abs();
|
||||
const ABS_MIN: i32 = i32::MIN.wrapping_abs();
|
||||
|
||||
fn main() {
|
||||
assert_eq!(ADD_A, 255);
|
||||
|
@ -43,5 +43,5 @@ fn main() {
|
|||
|
||||
assert_eq!(ABS_POS, 10);
|
||||
assert_eq!(ABS_NEG, 10);
|
||||
assert_eq!(ABS_MIN, i32::min_value());
|
||||
assert_eq!(ABS_MIN, i32::MIN);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#[repr(i128)]
|
||||
enum Test {
|
||||
A(Box<u64>) = 0,
|
||||
B(usize) = u64::max_value() as i128 + 1,
|
||||
B(usize) = u64::MAX as i128 + 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -8,9 +8,9 @@ use std::marker::DiscriminantKind;
|
|||
enum Signed {
|
||||
Zero = 0,
|
||||
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
|
||||
U64Limit = u64::max_value() as i128 + 1,
|
||||
U64Limit = u64::MAX as i128 + 1,
|
||||
SmallNegative = -1,
|
||||
BigNegative = i128::min_value(),
|
||||
BigNegative = i128::MIN,
|
||||
Next,
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ enum Signed {
|
|||
enum Unsigned {
|
||||
Zero = 0,
|
||||
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
|
||||
U64Limit = u64::max_value() as u128 + 1,
|
||||
U64Limit = u64::MAX as u128 + 1,
|
||||
Next,
|
||||
}
|
||||
|
||||
|
@ -32,13 +32,13 @@ where
|
|||
fn main() {
|
||||
discr(Signed::Zero, 0);
|
||||
discr(Signed::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
|
||||
discr(Signed::U64Limit, u64::max_value() as i128 + 1);
|
||||
discr(Signed::U64Limit, u64::MAX as i128 + 1);
|
||||
discr(Signed::SmallNegative, -1);
|
||||
discr(Signed::BigNegative, i128::min_value());
|
||||
discr(Signed::Next, i128::min_value() + 1);
|
||||
discr(Signed::BigNegative, i128::MIN);
|
||||
discr(Signed::Next, i128::MIN + 1);
|
||||
|
||||
discr(Unsigned::Zero, 0);
|
||||
discr(Unsigned::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
|
||||
discr(Unsigned::U64Limit, u64::max_value() as u128 + 1);
|
||||
discr(Unsigned::Next, u64::max_value() as u128 + 2);
|
||||
discr(Unsigned::U64Limit, u64::MAX as u128 + 1);
|
||||
discr(Unsigned::Next, u64::MAX as u128 + 2);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ use std::time::{Instant, Duration};
|
|||
|
||||
fn main() {
|
||||
let now = Instant::now();
|
||||
let _ = now + Duration::from_secs(u64::max_value());
|
||||
let _ = now + Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime};
|
|||
|
||||
fn main() {
|
||||
let now = SystemTime::now();
|
||||
let _ = now + Duration::from_secs(u64::max_value());
|
||||
let _ = now + Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ use std::time::{Instant, Duration};
|
|||
|
||||
fn main() {
|
||||
let now = Instant::now();
|
||||
let _ = now - Duration::from_secs(u64::max_value());
|
||||
let _ = now - Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime};
|
|||
|
||||
fn main() {
|
||||
let now = SystemTime::now();
|
||||
let _ = now - Duration::from_secs(u64::max_value());
|
||||
let _ = now - Duration::from_secs(u64::MAX);
|
||||
}
|
||||
|
|
|
@ -27,21 +27,21 @@ macro_rules! check {
|
|||
|
||||
fn main() {
|
||||
check![
|
||||
isize::min_value() / -isize::one(),
|
||||
i8::min_value() / -i8::one(),
|
||||
i16::min_value() / -i16::one(),
|
||||
i32::min_value() / -i32::one(),
|
||||
i64::min_value() / -i64::one(),
|
||||
isize::MIN / -isize::one(),
|
||||
i8::MIN / -i8::one(),
|
||||
i16::MIN / -i16::one(),
|
||||
i32::MIN / -i32::one(),
|
||||
i64::MIN / -i64::one(),
|
||||
1isize / isize::zero(),
|
||||
1i8 / i8::zero(),
|
||||
1i16 / i16::zero(),
|
||||
1i32 / i32::zero(),
|
||||
1i64 / i64::zero(),
|
||||
isize::min_value() % -isize::one(),
|
||||
i8::min_value() % -i8::one(),
|
||||
i16::min_value() % -i16::one(),
|
||||
i32::min_value() % -i32::one(),
|
||||
i64::min_value() % -i64::one(),
|
||||
isize::MIN % -isize::one(),
|
||||
i8::MIN % -i8::one(),
|
||||
i16::MIN % -i16::one(),
|
||||
i32::MIN % -i32::one(),
|
||||
i64::MIN % -i64::one(),
|
||||
1isize % isize::zero(),
|
||||
1i8 % i8::zero(),
|
||||
1i16 % i16::zero(),
|
||||
|
|
|
@ -6,14 +6,14 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
let mut it = u8::max_value()..;
|
||||
let mut it = u8::MAX..;
|
||||
it.next().unwrap(); // 255
|
||||
it.next().unwrap();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
let mut it = i8::max_value()..;
|
||||
let mut it = i8::MAX..;
|
||||
it.next().unwrap(); // 127
|
||||
it.next().unwrap();
|
||||
});
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
// compile-flags: -C debug_assertions=no
|
||||
|
||||
fn main() {
|
||||
let mut it = u8::max_value()..;
|
||||
let mut it = u8::MAX..;
|
||||
assert_eq!(it.next().unwrap(), 255);
|
||||
assert_eq!(it.next().unwrap(), u8::min_value());
|
||||
assert_eq!(it.next().unwrap(), u8::MIN);
|
||||
|
||||
let mut it = i8::max_value()..;
|
||||
let mut it = i8::MAX..;
|
||||
assert_eq!(it.next().unwrap(), 127);
|
||||
assert_eq!(it.next().unwrap(), i8::min_value());
|
||||
assert_eq!(it.next().unwrap(), i8::MIN);
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().sum::<i32>();
|
||||
[1, i32::MAX].iter().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().product::<i32>();
|
||||
[2, i32::MAX].iter().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().cloned().sum::<i32>();
|
||||
[1, i32::MAX].iter().cloned().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().cloned().product::<i32>();
|
||||
[2, i32::MAX].iter().cloned().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// compile-flags: -C debug_assertions=no
|
||||
|
||||
fn main() {
|
||||
assert_eq!([1i32, i32::max_value()].iter().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::max_value()));
|
||||
assert_eq!([2i32, i32::max_value()].iter().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::max_value()));
|
||||
assert_eq!([1i32, i32::MAX].iter().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::MAX));
|
||||
assert_eq!([2i32, i32::MAX].iter().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::MAX));
|
||||
|
||||
assert_eq!([1i32, i32::max_value()].iter().cloned().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::max_value()));
|
||||
assert_eq!([2i32, i32::max_value()].iter().cloned().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::max_value()));
|
||||
assert_eq!([1i32, i32::MAX].iter().cloned().sum::<i32>(),
|
||||
1i32.wrapping_add(i32::MAX));
|
||||
assert_eq!([2i32, i32::MAX].iter().cloned().product::<i32>(),
|
||||
2i32.wrapping_mul(i32::MAX));
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@ use std::panic;
|
|||
|
||||
fn main() {
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().sum::<i32>();
|
||||
[1, i32::MAX].iter().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().product::<i32>();
|
||||
[2, i32::MAX].iter().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[1, i32::max_value()].iter().cloned().sum::<i32>();
|
||||
[1, i32::MAX].iter().cloned().sum::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
[2, i32::max_value()].iter().cloned().product::<i32>();
|
||||
[2, i32::MAX].iter().cloned().product::<i32>();
|
||||
});
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
// compile-flags: -C overflow-checks -C opt-level=3
|
||||
|
||||
fn main() {
|
||||
let i = (0..usize::max_value()).chain(0..10).skip(usize::max_value());
|
||||
let i = (0..usize::MAX).chain(0..10).skip(usize::MAX);
|
||||
assert_eq!(i.count(), 10);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ fn main() {
|
|||
assert_eq!((-z).checked_mul(-z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
let l: i128 = b(i128::min_value());
|
||||
let l: i128 = b(i128::MIN);
|
||||
let o: i128 = b(17);
|
||||
assert_eq!(l.checked_sub(b(2)), None);
|
||||
assert_eq!(l.checked_add(l), None);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
assert!(thread::spawn(|| i8::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i16::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i32::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i64::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| isize::min_value().abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i8::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i16::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i32::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| i64::MIN.abs()).join().is_err());
|
||||
assert!(thread::spawn(|| isize::MIN.abs()).join().is_err());
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ fn main() {
|
|||
macro_rules! overflow_test {
|
||||
($t:ident) => (
|
||||
let r = panic::catch_unwind(|| {
|
||||
($t::max_value()).next_power_of_two()
|
||||
($t::MAX).next_power_of_two()
|
||||
});
|
||||
assert!(r.is_err());
|
||||
|
||||
let r = panic::catch_unwind(|| {
|
||||
(($t::max_value() >> 1) + 2).next_power_of_two()
|
||||
(($t::MAX >> 1) + 2).next_power_of_two()
|
||||
});
|
||||
assert!(r.is_err());
|
||||
)
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
fn main() {
|
||||
let x = &(0u32 - 1);
|
||||
assert_eq!(*x, u32::max_value())
|
||||
assert_eq!(*x, u32::MAX)
|
||||
}
|
||||
|
|
|
@ -53,14 +53,14 @@ fn main() {
|
|||
assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000",
|
||||
format!("{:b}", j));
|
||||
assert_eq!("340282366920938463463374607431768211455",
|
||||
format!("{}", u128::max_value()));
|
||||
format!("{}", u128::MAX));
|
||||
assert_eq!("147573952589676412928", format!("{:?}", j));
|
||||
// common traits
|
||||
assert_eq!(x, b(x.clone()));
|
||||
// overflow checks
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
let l: u128 = b(u128::max_value() - 10);
|
||||
let l: u128 = b(u128::MAX - 10);
|
||||
let o: u128 = b(17);
|
||||
assert_eq!(l.checked_add(b(11)), None);
|
||||
assert_eq!(l.checked_sub(l), Some(0));
|
||||
|
|
|
@ -20,7 +20,7 @@ extern "platform-intrinsic" {
|
|||
fn main() {
|
||||
// unsigned
|
||||
{
|
||||
const M: u32 = u32::max_value();
|
||||
const M: u32 = u32::MAX;
|
||||
|
||||
let a = u32x4(1, 2, 3, 4);
|
||||
let b = u32x4(2, 4, 6, 8);
|
||||
|
@ -48,8 +48,8 @@ fn main() {
|
|||
|
||||
// signed
|
||||
{
|
||||
const MIN: i32 = i32::min_value();
|
||||
const MAX: i32 = i32::max_value();
|
||||
const MIN: i32 = i32::MIN;
|
||||
const MAX: i32 = i32::MAX;
|
||||
|
||||
let a = i32x4(1, 2, 3, 4);
|
||||
let b = i32x4(2, 4, 6, 8);
|
||||
|
|
|
@ -39,7 +39,7 @@ fn main() {
|
|||
let e = 0b_1101;
|
||||
|
||||
// Check usize / isize
|
||||
let msize: Tx4<usize> = Tx4(usize::max_value(), 0, usize::max_value(), usize::max_value());
|
||||
let msize: Tx4<usize> = Tx4(usize::MAX, 0, usize::MAX, usize::MAX);
|
||||
|
||||
unsafe {
|
||||
let r: u8 = simd_bitmask(z);
|
||||
|
|
|
@ -100,7 +100,7 @@ fn main() {
|
|||
let r: u32 = simd_reduce_max(x);
|
||||
assert_eq!(r, 4_u32);
|
||||
|
||||
let t = u32::max_value();
|
||||
let t = u32::MAX;
|
||||
let x = u32x4(t, t, t, t);
|
||||
let r: u32 = simd_reduce_and(x);
|
||||
assert_eq!(r, t);
|
||||
|
|
|
@ -254,11 +254,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
if let ["core", "num", int_impl, "max_value"] = *def_path;
|
||||
then {
|
||||
let value = match int_impl {
|
||||
"<impl i8>" => i8::max_value() as u128,
|
||||
"<impl i16>" => i16::max_value() as u128,
|
||||
"<impl i32>" => i32::max_value() as u128,
|
||||
"<impl i64>" => i64::max_value() as u128,
|
||||
"<impl i128>" => i128::max_value() as u128,
|
||||
"<impl i8>" => i8::MAX as u128,
|
||||
"<impl i16>" => i16::MAX as u128,
|
||||
"<impl i32>" => i32::MAX as u128,
|
||||
"<impl i64>" => i64::MAX as u128,
|
||||
"<impl i128>" => i128::MAX as u128,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Constant::Int(value))
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
|
|||
continue;
|
||||
}
|
||||
},
|
||||
ty::Uint(UintTy::Usize) if val > u128::from(u32::max_value()) => {},
|
||||
ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {},
|
||||
_ => continue,
|
||||
}
|
||||
span_lint(
|
||||
|
|
|
@ -1946,18 +1946,18 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_
|
|||
let which = match (&ty.kind, cv) {
|
||||
(&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum,
|
||||
(&ty::Int(ity), Constant::Int(i))
|
||||
if i == unsext(cx.tcx, i128::min_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
|
||||
if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) =>
|
||||
{
|
||||
Minimum
|
||||
},
|
||||
|
||||
(&ty::Bool, Constant::Bool(true)) => Maximum,
|
||||
(&ty::Int(ity), Constant::Int(i))
|
||||
if i == unsext(cx.tcx, i128::max_value() >> (128 - int_bits(cx.tcx, ity)), ity) =>
|
||||
if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) =>
|
||||
{
|
||||
Maximum
|
||||
},
|
||||
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::max_value(), uty) == i => Maximum,
|
||||
(&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum,
|
||||
|
||||
_ => return None,
|
||||
};
|
||||
|
@ -2039,7 +2039,7 @@ impl FullInt {
|
|||
fn cmp_s_u(s: i128, u: u128) -> Ordering {
|
||||
if s < 0 {
|
||||
Ordering::Less
|
||||
} else if u > (i128::max_value() as u128) {
|
||||
} else if u > (i128::MAX as u128) {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
(s as u128).cmp(&u)
|
||||
|
@ -2084,48 +2084,48 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>)
|
|||
match pre_cast_ty.kind {
|
||||
ty::Int(int_ty) => Some(match int_ty {
|
||||
IntTy::I8 => (
|
||||
FullInt::S(i128::from(i8::min_value())),
|
||||
FullInt::S(i128::from(i8::max_value())),
|
||||
FullInt::S(i128::from(i8::MIN)),
|
||||
FullInt::S(i128::from(i8::MAX)),
|
||||
),
|
||||
IntTy::I16 => (
|
||||
FullInt::S(i128::from(i16::min_value())),
|
||||
FullInt::S(i128::from(i16::max_value())),
|
||||
FullInt::S(i128::from(i16::MIN)),
|
||||
FullInt::S(i128::from(i16::MAX)),
|
||||
),
|
||||
IntTy::I32 => (
|
||||
FullInt::S(i128::from(i32::min_value())),
|
||||
FullInt::S(i128::from(i32::max_value())),
|
||||
FullInt::S(i128::from(i32::MIN)),
|
||||
FullInt::S(i128::from(i32::MAX)),
|
||||
),
|
||||
IntTy::I64 => (
|
||||
FullInt::S(i128::from(i64::min_value())),
|
||||
FullInt::S(i128::from(i64::max_value())),
|
||||
FullInt::S(i128::from(i64::MIN)),
|
||||
FullInt::S(i128::from(i64::MAX)),
|
||||
),
|
||||
IntTy::I128 => (FullInt::S(i128::min_value()), FullInt::S(i128::max_value())),
|
||||
IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)),
|
||||
IntTy::Isize => (
|
||||
FullInt::S(isize::min_value() as i128),
|
||||
FullInt::S(isize::max_value() as i128),
|
||||
FullInt::S(isize::MIN as i128),
|
||||
FullInt::S(isize::MAX as i128),
|
||||
),
|
||||
}),
|
||||
ty::Uint(uint_ty) => Some(match uint_ty {
|
||||
UintTy::U8 => (
|
||||
FullInt::U(u128::from(u8::min_value())),
|
||||
FullInt::U(u128::from(u8::max_value())),
|
||||
FullInt::U(u128::from(u8::MIN)),
|
||||
FullInt::U(u128::from(u8::MAX)),
|
||||
),
|
||||
UintTy::U16 => (
|
||||
FullInt::U(u128::from(u16::min_value())),
|
||||
FullInt::U(u128::from(u16::max_value())),
|
||||
FullInt::U(u128::from(u16::MIN)),
|
||||
FullInt::U(u128::from(u16::MAX)),
|
||||
),
|
||||
UintTy::U32 => (
|
||||
FullInt::U(u128::from(u32::min_value())),
|
||||
FullInt::U(u128::from(u32::max_value())),
|
||||
FullInt::U(u128::from(u32::MIN)),
|
||||
FullInt::U(u128::from(u32::MAX)),
|
||||
),
|
||||
UintTy::U64 => (
|
||||
FullInt::U(u128::from(u64::min_value())),
|
||||
FullInt::U(u128::from(u64::max_value())),
|
||||
FullInt::U(u128::from(u64::MIN)),
|
||||
FullInt::U(u128::from(u64::MAX)),
|
||||
),
|
||||
UintTy::U128 => (FullInt::U(u128::min_value()), FullInt::U(u128::max_value())),
|
||||
UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)),
|
||||
UintTy::Usize => (
|
||||
FullInt::U(usize::min_value() as u128),
|
||||
FullInt::U(usize::max_value() as u128),
|
||||
FullInt::U(usize::MIN as u128),
|
||||
FullInt::U(usize::MAX as u128),
|
||||
),
|
||||
}),
|
||||
_ => None,
|
||||
|
|
|
@ -37,11 +37,11 @@ fn main() {
|
|||
1isize as usize;
|
||||
-1isize as usize;
|
||||
0i8 as u8;
|
||||
i8::max_value() as u8;
|
||||
i16::max_value() as u16;
|
||||
i32::max_value() as u32;
|
||||
i64::max_value() as u64;
|
||||
i128::max_value() as u128;
|
||||
i8::MAX as u8;
|
||||
i16::MAX as u16;
|
||||
i32::MAX as u32;
|
||||
i64::MAX as u64;
|
||||
i128::MAX as u128;
|
||||
|
||||
(-1i8).abs() as u8;
|
||||
(-1i16).abs() as u16;
|
||||
|
|
|
@ -110,7 +110,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_8 > i8::min_value() {
|
||||
if i_8 > i8::MIN {
|
||||
i_8 -= 1;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_8 != i8::min_value() {
|
||||
if i_8 != i8::MIN {
|
||||
i_8 -= 1;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_16 > i16::min_value() {
|
||||
if i_16 > i16::MIN {
|
||||
i_16 -= 1;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_16 != i16::min_value() {
|
||||
if i_16 != i16::MIN {
|
||||
i_16 -= 1;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_32 > i32::min_value() {
|
||||
if i_32 > i32::MIN {
|
||||
i_32 -= 1;
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Lint
|
||||
if i_32 != i32::min_value() {
|
||||
if i_32 != i32::MIN {
|
||||
i_32 -= 1;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ fn main() {
|
|||
let mut i_64: i64 = endi_64 - starti_64;
|
||||
|
||||
// Lint
|
||||
if i64::min_value() < i_64 {
|
||||
if i64::MIN < i_64 {
|
||||
i_64 -= 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:113:5
|
||||
|
|
||||
LL | / if i_8 > i8::min_value() {
|
||||
LL | / if i_8 > i8::MIN {
|
||||
LL | | i_8 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
|
||||
|
@ -91,7 +91,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:123:5
|
||||
|
|
||||
LL | / if i_8 != i8::min_value() {
|
||||
LL | / if i_8 != i8::MIN {
|
||||
LL | | i_8 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
|
||||
|
@ -107,7 +107,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:138:5
|
||||
|
|
||||
LL | / if i_16 > i16::min_value() {
|
||||
LL | / if i_16 > i16::MIN {
|
||||
LL | | i_16 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
|
||||
|
@ -123,7 +123,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:148:5
|
||||
|
|
||||
LL | / if i_16 != i16::min_value() {
|
||||
LL | / if i_16 != i16::MIN {
|
||||
LL | | i_16 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
|
||||
|
@ -139,7 +139,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:163:5
|
||||
|
|
||||
LL | / if i_32 > i32::min_value() {
|
||||
LL | / if i_32 > i32::MIN {
|
||||
LL | | i_32 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
|
||||
|
@ -155,7 +155,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:173:5
|
||||
|
|
||||
LL | / if i_32 != i32::min_value() {
|
||||
LL | / if i_32 != i32::MIN {
|
||||
LL | | i_32 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
|
||||
|
@ -163,7 +163,7 @@ LL | | }
|
|||
error: Implicitly performing saturating subtraction
|
||||
--> $DIR/implicit_saturating_sub.rs:183:5
|
||||
|
|
||||
LL | / if i64::min_value() < i_64 {
|
||||
LL | / if i64::MIN < i_64 {
|
||||
LL | | i_64 -= 1;
|
||||
LL | | }
|
||||
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue