diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index e5daf05..d918f5f 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -14,11 +14,20 @@ jobs: name: cargo-fmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get latest version of stable Rust run: rustup update stable - name: Check formatting with cargo fmt run: cargo fmt --all -- --check + clippy: + name: clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Lint code for quality and style with Clippy + run: cargo clippy --all test: strategy: matrix: @@ -26,7 +35,7 @@ jobs: runs-on: ${{ matrix.os }} name: test-${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get latest version of stable Rust run: rustup update stable - name: Run tests @@ -37,7 +46,7 @@ jobs: runs-on: ubuntu-latest name: cargo-tarpaulin steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get latest version of stable Rust run: rustup update stable - name: Install cargo-tarpaulin diff --git a/ssz/src/decode.rs b/ssz/src/decode.rs index 048f9f0..814aa70 100644 --- a/ssz/src/decode.rs +++ b/ssz/src/decode.rs @@ -26,21 +26,21 @@ pub enum DecodeError { /// An offset points “backwards” into the fixed-bytes portion of the message, essentially /// double-decoding bytes that will also be decoded as fixed-length. /// - /// https://notes.ethereum.org/ruKvDXl6QOW3gnqVYb8ezA?view#1-Offset-into-fixed-portion + /// OffsetIntoFixedPortion(usize), /// The first offset does not point to the byte that follows the fixed byte portion, /// essentially skipping a variable-length byte. /// - /// https://notes.ethereum.org/ruKvDXl6QOW3gnqVYb8ezA?view#2-Skip-first-variable-byte + /// OffsetSkipsVariableBytes(usize), /// An offset points to bytes prior to the previous offset. Depending on how you look at it, /// this either double-decodes bytes or makes the first offset a negative-length. /// - /// https://notes.ethereum.org/ruKvDXl6QOW3gnqVYb8ezA?view#3-Offsets-are-decreasing + /// OffsetsAreDecreasing(usize), /// An offset references byte indices that do not exist in the source bytes. /// - /// https://notes.ethereum.org/ruKvDXl6QOW3gnqVYb8ezA?view#4-Offsets-are-out-of-bounds + /// OffsetOutOfBounds(usize), /// A variable-length list does not have a fixed portion that is cleanly divisible by /// `BYTES_PER_LENGTH_OFFSET`. @@ -78,15 +78,15 @@ pub fn sanitize_offset( num_bytes: usize, num_fixed_bytes: Option, ) -> Result { - if num_fixed_bytes.map_or(false, |fixed_bytes| offset < fixed_bytes) { + if num_fixed_bytes.is_some_and(|fixed_bytes| offset < fixed_bytes) { Err(DecodeError::OffsetIntoFixedPortion(offset)) } else if previous_offset.is_none() - && num_fixed_bytes.map_or(false, |fixed_bytes| offset != fixed_bytes) + && num_fixed_bytes.is_some_and(|fixed_bytes| offset != fixed_bytes) { Err(DecodeError::OffsetSkipsVariableBytes(offset)) } else if offset > num_bytes { Err(DecodeError::OffsetOutOfBounds(offset)) - } else if previous_offset.map_or(false, |prev| prev > offset) { + } else if previous_offset.is_some_and(|prev| prev > offset) { Err(DecodeError::OffsetsAreDecreasing(offset)) } else { Ok(offset) diff --git a/ssz/src/decode/impls.rs b/ssz/src/decode/impls.rs index 6267e84..6c9b7b5 100644 --- a/ssz/src/decode/impls.rs +++ b/ssz/src/decode/impls.rs @@ -526,7 +526,7 @@ pub fn decode_list_of_variable_length_items let num_items = first_offset / BYTES_PER_LENGTH_OFFSET; - if max_len.map_or(false, |max| num_items > max) { + if max_len.is_some_and(|max| num_items > max) { return Err(DecodeError::BytesInvalid(format!( "Variable length list of {} items exceeds maximum of {:?}", num_items, max_len diff --git a/ssz/src/union_selector.rs b/ssz/src/union_selector.rs index 18bab09..2b01b89 100644 --- a/ssz/src/union_selector.rs +++ b/ssz/src/union_selector.rs @@ -2,7 +2,7 @@ use crate::*; /// Provides the one-byte "selector" from the SSZ union specification: /// -/// https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.3/ssz/simple-serialize.md#union +/// #[derive(Copy, Clone)] pub struct UnionSelector(u8); diff --git a/ssz_derive/src/lib.rs b/ssz_derive/src/lib.rs index 2e8d934..defd9ef 100644 --- a/ssz_derive/src/lib.rs +++ b/ssz_derive/src/lib.rs @@ -1,5 +1,6 @@ #![recursion_limit = "256"] -//! Provides procedural derive macros for the `Encode` and `Decode` traits of the `eth2_ssz` crate. +//! Provides procedural derive macros for the `Encode` and `Decode` traits of the `ethereum_ssz` +//! crate. //! //! ## Attributes //! @@ -288,11 +289,7 @@ fn parse_ssz_fields( let field_opts_candidates = field .attrs .iter() - .filter(|attr| { - attr.path() - .get_ident() - .map_or(false, |ident| *ident == "ssz") - }) + .filter(|attr| attr.path().get_ident().is_some_and(|ident| *ident == "ssz")) .collect::>(); if field_opts_candidates.len() > 1 { @@ -753,8 +750,8 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { /// ## Field attributes /// /// - `#[ssz(skip_deserializing)]`: during de-serialization the field will be instantiated from a -/// `Default` implementation. The decoder will assume that the field was not serialized at all -/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it). +/// `Default` implementation. The decoder will assume that the field was not serialized at all +/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it). fn ssz_decode_derive_struct(item: &DeriveInput, struct_data: &DataStruct) -> TokenStream { let name = &item.ident; let (impl_generics, ty_generics, where_clause) = &item.generics.split_for_impl(); @@ -903,8 +900,8 @@ fn ssz_decode_derive_struct(item: &DeriveInput, struct_data: &DataStruct) -> Tok /// ## Field attributes /// /// - `#[ssz(skip_deserializing)]`: during de-serialization the field will be instantiated from a -/// `Default` implementation. The decoder will assume that the field was not serialized at all -/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it). +/// `Default` implementation. The decoder will assume that the field was not serialized at all +/// (e.g., if it has been serialized, an error will be raised instead of `Default` overriding it). fn ssz_decode_derive_struct_transparent( item: &DeriveInput, struct_data: &DataStruct,