Skip to content

Commit

Permalink
Resolve legacy_numeric_constants clippy lints
Browse files Browse the repository at this point in the history
    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::<CONST>` 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::<CONST>` 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::<CONST>` 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::<CONST>` 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::<CONST>` 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::<CONST>` 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::<CONST>` 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::<CONST>` 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();
         |                                            ~~~
  • Loading branch information
dtolnay committed Apr 6, 2024
1 parent b1ebf38 commit 0baba28
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// 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),
)));
Expand Down Expand Up @@ -533,7 +533,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
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);
}
Expand Down Expand Up @@ -597,7 +597,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
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);
}
Expand Down Expand Up @@ -789,7 +789,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lexical/exponent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexical/rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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,
}
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down
34 changes: 8 additions & 26 deletions tests/lexical/exponent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
28 changes: 13 additions & 15 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
() => {
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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");
}
}
Expand Down

0 comments on commit 0baba28

Please sign in to comment.