From 0baba2877595e31d57adafd5db2f94074f4a4c2e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Apr 2024 19:05:51 -0700 Subject: [PATCH] Resolve legacy_numeric_constants clippy lints warning: usage of a legacy numeric method --> src/de.rs:484:73 | 484 | ... if overflow!(significand * 10 + digit, u64::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 484 | if overflow!(significand * 10 + digit, u64::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/de.rs:536:57 | 536 | if overflow!(significand * 10 + digit, u64::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 536 | if overflow!(significand * 10 + digit, u64::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/de.rs:600:49 | 600 | if overflow!(exp * 10 + digit, i32::max_value()) { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 600 | if overflow!(exp * 10 + digit, i32::MAX) { | ~~~ warning: usage of a legacy numeric method --> src/number.rs:100:39 | 100 | N::PosInt(v) => v <= i64::max_value() as u64, | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 100 | N::PosInt(v) => v <= i64::MAX as u64, | ~~~ warning: usage of a legacy numeric method --> src/number.rs:192:30 | 192 | if n <= i64::max_value() as u64 { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 192 | if n <= i64::MAX as u64 { | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/exponent.rs:11:21 | 11 | if value > i32::max_value() as usize { | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 11 | if value > i32::MAX as usize { | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/exponent.rs:12:14 | 12 | i32::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 12 | i32::MAX | ~~~ warning: usage of a legacy numeric method --> tests/../src/lexical/rounding.rs:28:14 | 28 | u64::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 28 | u64::MAX | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:21:34 | 21 | scientific_exponent(i32::min_value(), 0, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 21 | scientific_exponent(i32::MIN, 0, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:22:14 | 22 | i32::min_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 22 | i32::MIN | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:25:34 | 25 | scientific_exponent(i32::min_value(), 0, 5), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 25 | scientific_exponent(i32::MIN, 0, 5), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:26:14 | 26 | i32::min_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 26 | i32::MIN | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:31:34 | 31 | scientific_exponent(i32::max_value(), 0, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 31 | scientific_exponent(i32::MAX, 0, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:32:14 | 32 | i32::max_value() - 1 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 32 | i32::MAX - 1 | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:35:34 | 35 | scientific_exponent(i32::max_value(), 5, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 35 | scientific_exponent(i32::MAX, 5, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:36:14 | 36 | i32::max_value() | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 36 | i32::MAX | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:45:32 | 45 | mantissa_exponent(i32::max_value(), 5, 0), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 45 | mantissa_exponent(i32::MAX, 5, 0), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:46:14 | 46 | i32::max_value() - 5 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 46 | i32::MAX - 5 | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:48:39 | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 48 | assert_eq!(mantissa_exponent(i32::MAX, 0, 5), i32::max_value()); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:48:64 | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 48 | assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::MAX); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:49:39 | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 49 | assert_eq!(mantissa_exponent(i32::MIN, 5, 0), i32::min_value()); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:49:64 | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 49 | assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::MIN); | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:51:32 | 51 | mantissa_exponent(i32::min_value(), 0, 5), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 51 | mantissa_exponent(i32::MIN, 0, 5), | ~~~ warning: usage of a legacy numeric method --> tests/lexical/exponent.rs:52:14 | 52 | i32::min_value() + 5 | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 52 | i32::MIN + 5 | ~~~ warning: importing legacy numeric constants --> tests/test.rs:47:11 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i16::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default warning: importing legacy numeric constants --> tests/test.rs:47:16 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i32::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:47:21 | 47 | use std::{i16, i32, i64, i8}; | ^^^ | = help: remove this import = note: then `i64::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:47:26 | 47 | use std::{i16, i32, i64, i8}; | ^^ | = help: remove this import = note: then `i8::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:11 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u16::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:16 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u32::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:21 | 48 | use std::{u16, u32, u64, u8}; | ^^^ | = help: remove this import = note: then `u64::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: importing legacy numeric constants --> tests/test.rs:48:26 | 48 | use std::{u16, u32, u64, u8}; | ^^ | = help: remove this import = note: then `u8::` will resolve to the respective associated constant = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants warning: usage of a legacy numeric constant --> tests/test.rs:161:22 | 161 | let v = to_value(::std::f64::NAN.copysign(1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 161 | let v = to_value(f64::NAN.copysign(1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:164:22 | 164 | let v = to_value(::std::f64::NAN.copysign(-1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 164 | let v = to_value(f64::NAN.copysign(-1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:167:22 | 167 | let v = to_value(::std::f64::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 167 | let v = to_value(f64::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:170:23 | 170 | let v = to_value(-::std::f64::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 170 | let v = to_value(-f64::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:173:22 | 173 | let v = to_value(::std::f32::NAN.copysign(1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 173 | let v = to_value(f32::NAN.copysign(1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:176:22 | 176 | let v = to_value(::std::f32::NAN.copysign(-1.0)).unwrap(); | ^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 176 | let v = to_value(f32::NAN.copysign(-1.0)).unwrap(); | ~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:179:22 | 179 | let v = to_value(::std::f32::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 179 | let v = to_value(f32::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric constant --> tests/test.rs:182:23 | 182 | let v = to_value(-::std::f32::INFINITY).unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 182 | let v = to_value(-f32::INFINITY).unwrap(); | ~~~~~~~~~~~~~ warning: usage of a legacy numeric method --> tests/test.rs:2243:26 | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2243 | let signed = &[i128::MIN, -1, 0, 1, i128::max_value()]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2243:55 | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2243 | let signed = &[i128::min_value(), -1, 0, 1, i128::MAX]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2244:34 | 2244 | let unsigned = &[0, 1, u128::max_value()]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2244 | let unsigned = &[0, 1, u128::MAX]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2280:36 | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2280 | let signed = &[i128::from(i64::MIN), i128::from(u64::max_value())]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2280:66 | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2280 | let signed = &[i128::from(i64::min_value()), i128::from(u64::MAX)]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2281:41 | 2281 | let unsigned = &[0, u128::from(u64::max_value())]; | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2281 | let unsigned = &[0, u128::from(u64::MAX)]; | ~~~ warning: usage of a legacy numeric method --> tests/test.rs:2294:44 | 2294 | let err = to_value(u128::from(u64::max_value()) + 1).unwrap_err(); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 2294 | let err = to_value(u128::from(u64::MAX) + 1).unwrap_err(); | ~~~ --- src/de.rs | 8 ++++---- src/lexical/exponent.rs | 4 ++-- src/lexical/rounding.rs | 2 +- src/number.rs | 8 ++++---- tests/lexical/exponent.rs | 34 ++++++++-------------------------- tests/test.rs | 28 +++++++++++++--------------- 6 files changed, 32 insertions(+), 52 deletions(-) diff --git a/src/de.rs b/src/de.rs index 7154f84d2..c7774f687 100644 --- a/src/de.rs +++ b/src/de.rs @@ -481,7 +481,7 @@ impl<'de, R: Read<'de>> Deserializer { // try to keep the number as a `u64` until we grow // too large. At that point, switch to parsing the // value as a `f64`. - if overflow!(significand * 10 + digit, u64::max_value()) { + if overflow!(significand * 10 + digit, u64::MAX) { return Ok(ParserNumber::F64(tri!( self.parse_long_integer(positive, significand), ))); @@ -533,7 +533,7 @@ impl<'de, R: Read<'de>> Deserializer { while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) { let digit = (c - b'0') as u64; - if overflow!(significand * 10 + digit, u64::max_value()) { + if overflow!(significand * 10 + digit, u64::MAX) { let exponent = exponent_before_decimal_point + exponent_after_decimal_point; return self.parse_decimal_overflow(positive, significand, exponent); } @@ -597,7 +597,7 @@ impl<'de, R: Read<'de>> Deserializer { self.eat_char(); let digit = (c - b'0') as i32; - if overflow!(exp * 10 + digit, i32::max_value()) { + if overflow!(exp * 10 + digit, i32::MAX) { let zero_significand = significand == 0; return self.parse_exponent_overflow(positive, zero_significand, positive_exp); } @@ -789,7 +789,7 @@ impl<'de, R: Read<'de>> Deserializer { self.eat_char(); let digit = (c - b'0') as i32; - if overflow!(exp * 10 + digit, i32::max_value()) { + if overflow!(exp * 10 + digit, i32::MAX) { let zero_significand = self.scratch.iter().all(|&digit| digit == b'0'); return self.parse_exponent_overflow(positive, zero_significand, positive_exp); } diff --git a/src/lexical/exponent.rs b/src/lexical/exponent.rs index 6fc51977e..5e27de893 100644 --- a/src/lexical/exponent.rs +++ b/src/lexical/exponent.rs @@ -8,8 +8,8 @@ /// the mantissa we do not overflow for comically-long exponents. #[inline] fn into_i32(value: usize) -> i32 { - if value > i32::max_value() as usize { - i32::max_value() + if value > i32::MAX as usize { + i32::MAX } else { value as i32 } diff --git a/src/lexical/rounding.rs b/src/lexical/rounding.rs index 6ec1292aa..634487522 100644 --- a/src/lexical/rounding.rs +++ b/src/lexical/rounding.rs @@ -25,7 +25,7 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 { debug_assert!(n <= bits, "lower_n_mask() overflow in shl."); if n == bits { - u64::max_value() + u64::MAX } else { (1 << n) - 1 } diff --git a/src/number.rs b/src/number.rs index b0231a87b..878a3dcb2 100644 --- a/src/number.rs +++ b/src/number.rs @@ -82,7 +82,7 @@ impl Number { /// ``` /// # use serde_json::json; /// # - /// let big = i64::max_value() as u64 + 10; + /// let big = i64::MAX as u64 + 10; /// let v = json!({ "a": 64, "b": big, "c": 256.0 }); /// /// assert!(v["a"].is_i64()); @@ -97,7 +97,7 @@ impl Number { pub fn is_i64(&self) -> bool { #[cfg(not(feature = "arbitrary_precision"))] match self.n { - N::PosInt(v) => v <= i64::max_value() as u64, + N::PosInt(v) => v <= i64::MAX as u64, N::NegInt(_) => true, N::Float(_) => false, } @@ -177,7 +177,7 @@ impl Number { /// ``` /// # use serde_json::json; /// # - /// let big = i64::max_value() as u64 + 10; + /// let big = i64::MAX as u64 + 10; /// let v = json!({ "a": 64, "b": big, "c": 256.0 }); /// /// assert_eq!(v["a"].as_i64(), Some(64)); @@ -189,7 +189,7 @@ impl Number { #[cfg(not(feature = "arbitrary_precision"))] match self.n { N::PosInt(n) => { - if n <= i64::max_value() as u64 { + if n <= i64::MAX as u64 { Some(n as i64) } else { None diff --git a/tests/lexical/exponent.rs b/tests/lexical/exponent.rs index f7a847be3..c109ff07d 100644 --- a/tests/lexical/exponent.rs +++ b/tests/lexical/exponent.rs @@ -17,38 +17,20 @@ fn scientific_exponent_test() { assert_eq!(scientific_exponent(-10, 2, 20), -9); // Underflow - assert_eq!( - scientific_exponent(i32::min_value(), 0, 0), - i32::min_value() - ); - assert_eq!( - scientific_exponent(i32::min_value(), 0, 5), - i32::min_value() - ); + assert_eq!(scientific_exponent(i32::MIN, 0, 0), i32::MIN); + assert_eq!(scientific_exponent(i32::MIN, 0, 5), i32::MIN); // Overflow - assert_eq!( - scientific_exponent(i32::max_value(), 0, 0), - i32::max_value() - 1 - ); - assert_eq!( - scientific_exponent(i32::max_value(), 5, 0), - i32::max_value() - ); + assert_eq!(scientific_exponent(i32::MAX, 0, 0), i32::MAX - 1); + assert_eq!(scientific_exponent(i32::MAX, 5, 0), i32::MAX); } #[test] fn mantissa_exponent_test() { assert_eq!(mantissa_exponent(10, 5, 0), 5); assert_eq!(mantissa_exponent(0, 5, 0), -5); - assert_eq!( - mantissa_exponent(i32::max_value(), 5, 0), - i32::max_value() - 5 - ); - assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value()); - assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value()); - assert_eq!( - mantissa_exponent(i32::min_value(), 0, 5), - i32::min_value() + 5 - ); + assert_eq!(mantissa_exponent(i32::MAX, 5, 0), i32::MAX - 5); + assert_eq!(mantissa_exponent(i32::MAX, 0, 5), i32::MAX); + assert_eq!(mantissa_exponent(i32::MIN, 5, 0), i32::MIN); + assert_eq!(mantissa_exponent(i32::MIN, 0, 5), i32::MIN + 5); } diff --git a/tests/test.rs b/tests/test.rs index c227b9066..7e6adad76 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -44,8 +44,6 @@ use std::marker::PhantomData; use std::mem; use std::str::FromStr; use std::{f32, f64}; -use std::{i16, i32, i64, i8}; -use std::{u16, u32, u64, u8}; macro_rules! treemap { () => { @@ -158,28 +156,28 @@ fn test_write_f64() { #[test] fn test_encode_nonfinite_float_yields_null() { - let v = to_value(::std::f64::NAN.copysign(1.0)).unwrap(); + let v = to_value(f64::NAN.copysign(1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f64::NAN.copysign(-1.0)).unwrap(); + let v = to_value(f64::NAN.copysign(-1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f64::INFINITY).unwrap(); + let v = to_value(f64::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(-::std::f64::INFINITY).unwrap(); + let v = to_value(-f64::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::NAN.copysign(1.0)).unwrap(); + let v = to_value(f32::NAN.copysign(1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::NAN.copysign(-1.0)).unwrap(); + let v = to_value(f32::NAN.copysign(-1.0)).unwrap(); assert!(v.is_null()); - let v = to_value(::std::f32::INFINITY).unwrap(); + let v = to_value(f32::INFINITY).unwrap(); assert!(v.is_null()); - let v = to_value(-::std::f32::INFINITY).unwrap(); + let v = to_value(-f32::INFINITY).unwrap(); assert!(v.is_null()); } @@ -2240,8 +2238,8 @@ fn null_invalid_type() { #[test] fn test_integer128() { - let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()]; - let unsigned = &[0, 1, u128::max_value()]; + let signed = &[i128::MIN, -1, 0, 1, i128::MAX]; + let unsigned = &[0, 1, u128::MAX]; for integer128 in signed { let expected = integer128.to_string(); @@ -2277,8 +2275,8 @@ fn test_integer128() { #[test] fn test_integer128_to_value() { - let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())]; - let unsigned = &[0, u128::from(u64::max_value())]; + let signed = &[i128::from(i64::MIN), i128::from(u64::MAX)]; + let unsigned = &[0, u128::from(u64::MAX)]; for integer128 in signed { let expected = integer128.to_string(); @@ -2291,7 +2289,7 @@ fn test_integer128_to_value() { } if !cfg!(feature = "arbitrary_precision") { - let err = to_value(u128::from(u64::max_value()) + 1).unwrap_err(); + let err = to_value(u128::from(u64::MAX) + 1).unwrap_err(); assert_eq!(err.to_string(), "number out of range"); } }