Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

## Unreleased

### Fixed

- Derived `Encode`/`Decode` for enums no longer fails under `#![deny(trivial_numeric_casts)]` ([#740](https://github.com/paritytech/parity-scale-codec/issues/740))

### [3.7.5] - 2025-05-20

### Fixed
Expand Down
1 change: 1 addition & 0 deletions derive/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn quote(
quote_spanned! { v.span() =>
#[allow(clippy::unnecessary_cast)]
#[allow(clippy::cast_possible_truncation)]
#[allow(trivial_numeric_casts)]
__codec_x_edqy if __codec_x_edqy == (#index) as ::core::primitive::u8 => {
// NOTE: This lambda is necessary to work around an upstream bug
// where each extra branch results in excessive stack usage:
Expand Down
3 changes: 3 additions & 0 deletions derive/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ fn impl_encode(data: &Data, type_name: &Ident, crate_path: &syn::Path) -> TokenS
let encoding = quote_spanned! { f.span() =>
#type_name :: #name { #( ref #encoding_names, )* } => {
#[allow(clippy::unnecessary_cast)]
#[allow(trivial_numeric_casts)]
#dest.push_byte((#index) as ::core::primitive::u8);
#encode_fields
}
Expand Down Expand Up @@ -370,6 +371,7 @@ fn impl_encode(data: &Data, type_name: &Ident, crate_path: &syn::Path) -> TokenS
let encoding = quote_spanned! { f.span() =>
#type_name :: #name ( #( ref #encoding_names, )* ) => {
#[allow(clippy::unnecessary_cast)]
#[allow(trivial_numeric_casts)]
#dest.push_byte((#index) as ::core::primitive::u8);
#encode_fields
}
Expand All @@ -388,6 +390,7 @@ fn impl_encode(data: &Data, type_name: &Ident, crate_path: &syn::Path) -> TokenS
#type_name :: #name => {
#[allow(clippy::unnecessary_cast)]
#[allow(clippy::cast_possible_truncation)]
#[allow(trivial_numeric_casts)]
#dest.push_byte((#index) as ::core::primitive::u8);
}
};
Expand Down
1 change: 1 addition & 0 deletions derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn const_eval_check_variant_indexes(
const _: () = {
#[allow(clippy::unnecessary_cast)]
#[allow(clippy::cast_possible_truncation)]
#[allow(trivial_numeric_casts)]
const indices: [(usize, &'static str); #len] = [#( #recurse_indices ,)*];

const fn search_for_invalid_index(array: &[(usize, &'static str); #len]) -> (bool, usize) {
Expand Down
8 changes: 8 additions & 0 deletions tests/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//! This file is checked by clippy to make sure that the code generated by the derive macro
//! doesn't spew out warnings/errors in users' code.

#![deny(trivial_numeric_casts)]

use parity_scale_codec_derive::{Decode, DecodeWithMemTracking, Encode};

#[repr(u8)]
Expand All @@ -24,3 +26,9 @@ pub enum CLike {
Foo = 0,
Bar = 1,
}

#[derive(Decode, DecodeWithMemTracking, Encode)]
pub enum UnitVariants {
One,
Two,
}
Loading