From 5b24f88e73caa9c607527b5b4696fc34263cd238 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Apr 2024 19:18:03 -0700 Subject: [PATCH] Resolve legacy_numeric_constants clippy lints warning: usage of a legacy numeric method --> serde_derive/src/ser.rs:292:51 | 292 | assert!(fields.len() as u64 <= u64::from(u32::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 | 292 | assert!(fields.len() as u64 <= u64::from(u32::MAX)); | ~~~ warning: usage of a legacy numeric method --> serde_derive/src/ser.rs:400:53 | 400 | assert!(variants.len() as u64 <= u64::from(u32::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 | 400 | assert!(variants.len() as u64 <= u64::from(u32::MAX)); | ~~~ warning: usage of a legacy numeric method --> test_suite/tests/test_de_error.rs:1462:29 | 1462 | Token::U64(u64::max_value()), | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `-W clippy::legacy-numeric-constants` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::legacy_numeric_constants)]` help: use the associated constant instead | 1462 | Token::U64(u64::MAX), | ~~~ warning: usage of a legacy numeric method --> test_suite/tests/test_de_error.rs:1479:29 | 1479 | Token::U64(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 | 1479 | Token::U64(u64::MAX), | ~~~ warning: usage of a legacy numeric method --> test_suite/tests/test_de_error.rs:1493:29 | 1493 | Token::U64(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 | 1493 | Token::U64(u64::MAX), | ~~~ warning: usage of a legacy numeric method --> test_suite/tests/test_de_error.rs:1510:29 | 1510 | Token::U64(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 | 1510 | Token::U64(u64::MAX), | ~~~ --- serde_derive/src/ser.rs | 4 ++-- test_suite/tests/test_de_error.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index 3be51ee52..7d89d2212 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -289,7 +289,7 @@ fn serialize_tuple_struct( } fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Container) -> Fragment { - assert!(fields.len() as u64 <= u64::from(u32::max_value())); + assert!(fields.len() as u64 <= u64::from(u32::MAX)); if cattrs.has_flatten() { serialize_struct_as_map(params, fields, cattrs) @@ -397,7 +397,7 @@ fn serialize_struct_as_map( } fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Container) -> Fragment { - assert!(variants.len() as u64 <= u64::from(u32::max_value())); + assert!(variants.len() as u64 <= u64::from(u32::MAX)); let self_var = ¶ms.self_var; diff --git a/test_suite/tests/test_de_error.rs b/test_suite/tests/test_de_error.rs index d1ea2b910..cf4bec86b 100644 --- a/test_suite/tests/test_de_error.rs +++ b/test_suite/tests/test_de_error.rs @@ -1459,7 +1459,7 @@ fn test_duration_overflow_seq() { assert_de_tokens_error::( &[ Token::Seq { len: Some(2) }, - Token::U64(u64::max_value()), + Token::U64(u64::MAX), Token::U32(1_000_000_000), Token::SeqEnd, ], @@ -1476,7 +1476,7 @@ fn test_duration_overflow_struct() { len: 2, }, Token::Str("secs"), - Token::U64(u64::max_value()), + Token::U64(u64::MAX), Token::Str("nanos"), Token::U32(1_000_000_000), Token::StructEnd, @@ -1490,7 +1490,7 @@ fn test_systemtime_overflow_seq() { assert_de_tokens_error::( &[ Token::Seq { len: Some(2) }, - Token::U64(u64::max_value()), + Token::U64(u64::MAX), Token::U32(1_000_000_000), Token::SeqEnd, ], @@ -1507,7 +1507,7 @@ fn test_systemtime_overflow_struct() { len: 2, }, Token::Str("secs_since_epoch"), - Token::U64(u64::max_value()), + Token::U64(u64::MAX), Token::Str("nanos_since_epoch"), Token::U32(1_000_000_000), Token::StructEnd, @@ -1522,7 +1522,7 @@ fn test_systemtime_overflow() { assert_de_tokens_error::( &[ Token::Seq { len: Some(2) }, - Token::U64(u64::max_value()), + Token::U64(u64::MAX), Token::U32(0), Token::SeqEnd, ],