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
       --> 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),
         |                             ~~~
  • Loading branch information
dtolnay committed Apr 6, 2024
1 parent 74d0670 commit 5b24f88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = &params.self_var;

Expand Down
10 changes: 5 additions & 5 deletions test_suite/tests/test_de_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ fn test_duration_overflow_seq() {
assert_de_tokens_error::<Duration>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(1_000_000_000),
Token::SeqEnd,
],
Expand All @@ -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,
Expand All @@ -1490,7 +1490,7 @@ fn test_systemtime_overflow_seq() {
assert_de_tokens_error::<SystemTime>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(1_000_000_000),
Token::SeqEnd,
],
Expand All @@ -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,
Expand All @@ -1522,7 +1522,7 @@ fn test_systemtime_overflow() {
assert_de_tokens_error::<SystemTime>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(0),
Token::SeqEnd,
],
Expand Down

0 comments on commit 5b24f88

Please sign in to comment.