Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make clippy happy #35

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
10 changes: 5 additions & 5 deletions ssz/src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
///
/// - `bytes` is not the minimal required bytes to represent a bitfield of `bit_len` bits.
/// - `bit_len` is not a multiple of 8 and `bytes` contains set bits that are higher than, or
/// equal to `bit_len`.
/// equal to `bit_len`.
fn from_raw_bytes(bytes: SmallVec<[u8; SMALLVEC_LEN]>, bit_len: usize) -> Result<Self, Error> {
if bit_len == 0 {
if bytes.len() == 1 && bytes[0] == 0 {
Expand All @@ -461,7 +461,7 @@
})
} else {
// Ensure there are no bits higher than `bit_len` that are set to true.
let (mask, _) = u8::max_value().overflowing_shr(8 - (bit_len as u32 % 8));
let (mask, _) = u8::MAX.overflowing_shr(8 - (bit_len as u32 % 8));

if (bytes.last().expect("Guarded against empty bytes") & !mask) == 0 {
Ok(Self {
Expand Down Expand Up @@ -559,7 +559,7 @@
i: usize,
}

impl<'a, T: BitfieldBehaviour> Iterator for BitIter<'a, T> {
impl<T: BitfieldBehaviour> Iterator for BitIter<'_, T> {
type Item = bool;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -679,7 +679,7 @@
let size = N::to_usize();
let mut vec = smallvec![0u8; size];
u.fill_buffer(&mut vec)?;
Ok(Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?)
Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)

Check warning on line 682 in ssz/src/bitfield.rs

View check run for this annotation

Codecov / codecov/patch

ssz/src/bitfield.rs#L682

Added line #L682 was not covered by tests
}
}

Expand All @@ -691,7 +691,7 @@
let size = std::cmp::min(rand, max_size);
let mut vec = smallvec![0u8; size];
u.fill_buffer(&mut vec)?;
Ok(Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)?)
Self::from_bytes(vec).map_err(|_| arbitrary::Error::IncorrectFormat)

Check warning on line 694 in ssz/src/bitfield.rs

View check run for this annotation

Codecov / codecov/patch

ssz/src/bitfield.rs#L694

Added line #L694 was not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 deletions ssz/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum DecodeError {
///
/// - It is `>= bytes.len()`.
/// - When decoding variable length items, the 1st offset points "backwards" into the fixed
/// length items (i.e., `length[0] < BYTES_PER_LENGTH_OFFSET`).
/// length items (i.e., `length[0] < BYTES_PER_LENGTH_OFFSET`).
/// - When decoding variable-length items, the `n`'th offset was less than the `n-1`'th offset.
OutOfBoundsByte { i: usize },
/// An offset points “backwards” into the fixed-bytes portion of the message, essentially
Expand Down Expand Up @@ -61,11 +61,11 @@ pub enum DecodeError {
///
/// - `offset`: the offset bytes (e.g., result of `read_offset(..)`).
/// - `previous_offset`: unless this is the first offset in the SSZ object, the value of the
/// previously-read offset. Used to ensure offsets are not decreasing.
/// previously-read offset. Used to ensure offsets are not decreasing.
/// - `num_bytes`: the total number of bytes in the SSZ object. Used to ensure the offset is not
/// out of bounds.
/// out of bounds.
/// - `num_fixed_bytes`: the number of fixed-bytes in the struct, if it is known. Used to ensure
/// that the first offset doesn't skip any variable bytes.
/// that the first offset doesn't skip any variable bytes.
///
/// ## References
///
Expand Down
2 changes: 1 addition & 1 deletion ssz/src/encode/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<T: Encode> Encode for Arc<T> {
}

// Encode transparently through references.
impl<'a, T: Encode> Encode for &'a T {
impl<T: Encode> Encode for &T {
fn is_ssz_fixed_len() -> bool {
T::is_ssz_fixed_len()
}
Expand Down
6 changes: 3 additions & 3 deletions ssz/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ mod test {
(0, 0),
(0, 1),
(1, 0),
(u8::max_value(), u16::max_value()),
(0, u16::max_value()),
(u8::max_value(), 0),
(u8::MAX, u16::MAX),
(0, u16::MAX),
(u8::MAX, 0),
(42, 12301),
];

Expand Down
4 changes: 2 additions & 2 deletions ssz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub use union_selector::UnionSelector;
pub const BYTES_PER_LENGTH_OFFSET: usize = 4;
/// The maximum value that can be represented using `BYTES_PER_LENGTH_OFFSET`.
#[cfg(target_pointer_width = "32")]
pub const MAX_LENGTH_VALUE: usize = (std::u32::MAX >> (8 * (4 - BYTES_PER_LENGTH_OFFSET))) as usize;
pub const MAX_LENGTH_VALUE: usize = (u32::MAX >> (8 * (4 - BYTES_PER_LENGTH_OFFSET))) as usize;
#[cfg(target_pointer_width = "64")]
pub const MAX_LENGTH_VALUE: usize = (std::u64::MAX >> (8 * (8 - BYTES_PER_LENGTH_OFFSET))) as usize;
pub const MAX_LENGTH_VALUE: usize = (u64::MAX >> (8 * (8 - BYTES_PER_LENGTH_OFFSET))) as usize;

/// The number of bytes used to indicate the variant of a union.
pub const BYTES_PER_UNION_SELECTOR: usize = 1;
Expand Down
10 changes: 5 additions & 5 deletions ssz/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod round_trip {
FixedLen { a: 1, b: 0, c: 1 },
];

let expected_encodings = vec![
let expected_encodings = [
// | u16--| u64----------------------------| u32----------|
vec![00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00],
vec![01, 00, 01, 00, 00, 00, 00, 00, 00, 00, 01, 00, 00, 00],
Expand Down Expand Up @@ -265,7 +265,7 @@ mod round_trip {
},
];

let expected_encodings = vec![
let expected_encodings = [
// 00..................................09
// | u16--| vec offset-----| u32------------| vec payload --------|
vec![00, 00, 10, 00, 00, 00, 00, 00, 00, 00],
Expand Down Expand Up @@ -354,9 +354,9 @@ mod round_trip {
(0, 0),
(0, 1),
(1, 0),
(u8::max_value(), u16::max_value()),
(0, u16::max_value()),
(u8::max_value(), 0),
(u8::MAX, u16::MAX),
(0, u16::MAX),
(u8::MAX, 0),
(42, 12301),
];

Expand Down
Loading