Skip to content

fix: suppress trivial_numeric_casts in derived Encode/Decode - #825

Merged
bkchr merged 1 commit into
paritytech:masterfrom
Tyagiquamar:fix/trivial-numeric-casts-enum-derive
Sep 13, 2026
Merged

bkchr merged 1 commit into
paritytech:masterfrom
Tyagiquamar:fix/trivial-numeric-casts-enum-derive

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

  • Derived Encode/Decode for enums emitted (index) as usize / as u8 even when the index was already that type, so crates with #![deny(trivial_numeric_casts)] failed to compile a two-variant enum.
  • Allow trivial_numeric_casts on the generated index checks and match arms, matching the existing clippy::unnecessary_cast allows.
  • tests/clippy.rs now denys that lint and includes a unit enum matching the report.

Test plan

  • cargo +stable test --locked --test clippy
  • cargo +stable clippy --locked --test clippy -- -Dwarnings
  • CI fmt / clippy / tests jobs

Fixes #740

Generated enum index casts are already usize/u8 in the common
cases, so deny(trivial_numeric_casts) in downstream crates failed
to compile a simple enum. Allow the lint next to the existing
clippy cast allows.

Fixes paritytech#740
@Tyagiquamar

Tyagiquamar commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@bkchr when you have a chance, could you take a look at this? It addresses #740 by allowing trivial_numeric_casts on generated enum index checks in derive(Encode, Decode), with tests ensuring crates with #![deny(trivial_numeric_casts)] compile cleanly. Happy to adjust anything needed.

@bkchr
bkchr merged commit 3fc36f5 into paritytech:master Sep 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output of Encode/Decode macros does not pass trivial_numeric_casts lint

2 participants