Skip to content

Commit

Permalink
Fix all clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas committed Jan 14, 2025
1 parent 40b031d commit 77b712d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
3 changes: 3 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ impl Machine {
}

/// Copy and get the return value of the machine, if any.
#[allow(clippy::slow_vector_initialization)]
// Clippy complains about not using `no_std`. However, we need to support
// `no_std` and we can't use that.
pub fn return_value(&self) -> Vec<u8> {
if self.return_range.start > U256::from(usize::MAX) {
let mut ret = Vec::new();
Expand Down
8 changes: 5 additions & 3 deletions core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ impl Memory {
&self.data
}

/// Resize the memory, making it cover the memory region of `offset..(offset
/// + len)`, with 32 bytes as the step. If the length is zero, this function
/// does nothing.
/// Resize the memory, making it cover the memory region of `offset..(offset + len)`,
/// with 32 bytes as the step. If the length is zero, this function does nothing.
pub fn resize_offset(&mut self, offset: U256, len: U256) -> Result<(), ExitError> {
if len == U256::zero() {
return Ok(());
Expand Down Expand Up @@ -79,6 +78,9 @@ impl Memory {
///
/// Value of `size` is considered trusted. If they're too large,
/// the program can run out of memory, or it can overflow.
#[allow(clippy::slow_vector_initialization)]
// Clippy complains about not using `vec!`. However, we need to support
// `no_std` and we can't use that.
pub fn get(&self, offset: usize, size: usize) -> Vec<u8> {
let mut ret = Vec::new();
ret.resize(size, 0);
Expand Down
2 changes: 1 addition & 1 deletion gasometer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ struct Inner<'config> {
config: &'config Config,
}

impl<'config> Inner<'config> {
impl Inner<'_> {
fn memory_gas(&self, memory: MemoryCost) -> Result<u64, ExitError> {
let from = memory.offset;
let len = memory.len;
Expand Down
6 changes: 3 additions & 3 deletions src/backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'vicinity> MemoryBackend<'vicinity> {
}
}

impl<'vicinity> Backend for MemoryBackend<'vicinity> {
impl Backend for MemoryBackend<'_> {
fn gas_price(&self) -> U256 {
self.vicinity.gas_price
}
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'vicinity> Backend for MemoryBackend<'vicinity> {
}
}

impl<'vicinity> ApplyBackend for MemoryBackend<'vicinity> {
impl ApplyBackend for MemoryBackend<'_> {
fn apply<A, I, L>(&mut self, values: A, logs: L, delete_empty: bool)
where
A: IntoIterator<Item = Apply<I>>,
Expand All @@ -189,7 +189,7 @@ impl<'vicinity> ApplyBackend for MemoryBackend<'vicinity> {
reset_storage,
} => {
let is_empty = {
let account = self.state.entry(address).or_insert_with(Default::default);
let account = self.state.entry(address).or_default();
account.balance = basic.balance;
account.nonce = basic.nonce;
if let Some(code) = code {
Expand Down
10 changes: 5 additions & 5 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
let mut stream = rlp::RlpStream::new_list(2);
stream.append(&caller);
stream.append(&nonce);
H256::from_slice(Keccak256::digest(&stream.out()).as_slice()).into()
H256::from_slice(Keccak256::digest(stream.out()).as_slice()).into()
}
CreateScheme::Fixed(naddress) => naddress,
}
Expand Down Expand Up @@ -1087,8 +1087,8 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
pub struct StackExecutorCallInterrupt<'borrow>(TaggedRuntime<'borrow>);
pub struct StackExecutorCreateInterrupt<'borrow>(TaggedRuntime<'borrow>);

impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Handler
for StackExecutor<'config, 'precompiles, S, P>
impl<'config, S: StackState<'config>, P: PrecompileSet> Handler
for StackExecutor<'config, '_, S, P>
{
type CreateInterrupt = StackExecutorCreateInterrupt<'static>;
type CreateFeedback = Infallible;
Expand Down Expand Up @@ -1397,8 +1397,8 @@ struct StackExecutorHandle<'inner, 'config, 'precompiles, S, P> {
is_static: bool,
}

impl<'inner, 'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> PrecompileHandle
for StackExecutorHandle<'inner, 'config, 'precompiles, S, P>
impl<'config, S: StackState<'config>, P: PrecompileSet> PrecompileHandle
for StackExecutorHandle<'_, 'config, '_, S, P>
{
// Perform subcall in provided context.
/// Precompile specifies in which context the subcall is executed.
Expand Down
4 changes: 2 additions & 2 deletions src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub struct MemoryStackState<'backend, 'config, B> {
substate: MemoryStackSubstate<'config>,
}

impl<'backend, 'config, B: Backend> Backend for MemoryStackState<'backend, 'config, B> {
impl<B: Backend> Backend for MemoryStackState<'_, '_, B> {
fn gas_price(&self) -> U256 {
self.backend.gas_price()
}
Expand Down Expand Up @@ -515,7 +515,7 @@ impl<'backend, 'config, B: Backend> Backend for MemoryStackState<'backend, 'conf
}
}

impl<'backend, 'config, B: Backend> StackState<'config> for MemoryStackState<'backend, 'config, B> {
impl<'config, B: Backend> StackState<'config> for MemoryStackState<'_, 'config, B> {
fn metadata(&self) -> &StackSubstateMetadata<'config> {
self.substate.metadata()
}
Expand Down
4 changes: 2 additions & 2 deletions src/maybe_borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum MaybeBorrowed<'a, T> {
Owned(T),
}

impl<'a, T> core::ops::Deref for MaybeBorrowed<'a, T> {
impl<T> core::ops::Deref for MaybeBorrowed<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
Expand All @@ -24,7 +24,7 @@ impl<'a, T> core::ops::Deref for MaybeBorrowed<'a, T> {
}
}

impl<'a, T> core::ops::DerefMut for MaybeBorrowed<'a, T> {
impl<T> core::ops::DerefMut for MaybeBorrowed<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
Self::Borrowed(x) => x,
Expand Down

0 comments on commit 77b712d

Please sign in to comment.