From 9b54e51522aa453a3dd6ba4fb9a727e2f5361dba Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:11:20 +0200 Subject: [PATCH] chore: fix `clippy::use_self` (#34) `cargo clippy --workspace --all-features --fix -- -Wclippy::use_self && cargo fmt`. NFC --- src/access_list.rs | 2 +- src/opcode.rs | 2 +- src/stack/maybe_owned.rs | 54 ++++++++++++++++---------------------- src/stack/mod.rs | 2 +- src/tracing/arena.rs | 4 +-- src/tracing/config.rs | 2 +- src/tracing/fourbyte.rs | 2 +- src/tracing/js/bindings.rs | 12 ++++----- src/tracing/types.rs | 48 ++++++++++++++++----------------- 9 files changed, 59 insertions(+), 69 deletions(-) diff --git a/src/access_list.rs b/src/access_list.rs index 7034432d..7abb4e05 100644 --- a/src/access_list.rs +++ b/src/access_list.rs @@ -27,7 +27,7 @@ impl AccessListInspector { to: Address, precompiles: impl IntoIterator, ) -> Self { - AccessListInspector { + Self { excluded: [from, to].into_iter().chain(precompiles).collect(), access_list: access_list .0 diff --git a/src/opcode.rs b/src/opcode.rs index f431aeeb..ba03610a 100644 --- a/src/opcode.rs +++ b/src/opcode.rs @@ -16,7 +16,7 @@ pub struct OpcodeCounterInspector { impl OpcodeCounterInspector { /// Creates a new instance of the inspector. pub fn new() -> Self { - OpcodeCounterInspector { opcode_counts: HashMap::new(), opcode_gas: HashMap::new() } + Self { opcode_counts: HashMap::new(), opcode_gas: HashMap::new() } } /// Returns the opcode counts collected during transaction execution. diff --git a/src/stack/maybe_owned.rs b/src/stack/maybe_owned.rs index 4f2535b6..307bc54b 100644 --- a/src/stack/maybe_owned.rs +++ b/src/stack/maybe_owned.rs @@ -25,23 +25,21 @@ pub enum MaybeOwnedInspector { impl MaybeOwnedInspector { /// Create a new _owned_ instance pub fn new_owned(inspector: INSP) -> Self { - MaybeOwnedInspector::Owned(Rc::new(RefCell::new(inspector))) + Self::Owned(Rc::new(RefCell::new(inspector))) } /// Creates a [MaybeOwnedInspector::Stacked] clone of this type. pub fn clone_stacked(&self) -> Self { match self { - MaybeOwnedInspector::Owned(gas) | MaybeOwnedInspector::Stacked(gas) => { - MaybeOwnedInspector::Stacked(Rc::clone(gas)) - } + Self::Owned(gas) | Self::Stacked(gas) => Self::Stacked(Rc::clone(gas)), } } /// Returns a reference to the inspector. pub fn as_ref(&self) -> Ref<'_, INSP> { match self { - MaybeOwnedInspector::Owned(insp) => insp.borrow(), - MaybeOwnedInspector::Stacked(insp) => insp.borrow(), + Self::Owned(insp) => insp.borrow(), + Self::Stacked(insp) => insp.borrow(), } } } @@ -72,31 +70,29 @@ where { fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { match self { - MaybeOwnedInspector::Owned(insp) => { - insp.borrow_mut().initialize_interp(interp, context) - } - MaybeOwnedInspector::Stacked(_) => {} + Self::Owned(insp) => insp.borrow_mut().initialize_interp(interp, context), + Self::Stacked(_) => {} } } fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { match self { - MaybeOwnedInspector::Owned(insp) => insp.borrow_mut().step(interp, context), - MaybeOwnedInspector::Stacked(_) => {} + Self::Owned(insp) => insp.borrow_mut().step(interp, context), + Self::Stacked(_) => {} } } fn log(&mut self, context: &mut EvmContext, log: &Log) { match self { - MaybeOwnedInspector::Owned(insp) => return insp.borrow_mut().log(context, log), - MaybeOwnedInspector::Stacked(_) => {} + Self::Owned(insp) => return insp.borrow_mut().log(context, log), + Self::Stacked(_) => {} } } fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { match self { - MaybeOwnedInspector::Owned(insp) => insp.borrow_mut().step_end(interp, context), - MaybeOwnedInspector::Stacked(_) => {} + Self::Owned(insp) => insp.borrow_mut().step_end(interp, context), + Self::Stacked(_) => {} } } @@ -107,10 +103,10 @@ where return_memory_offset: Range, ) -> Option { match self { - MaybeOwnedInspector::Owned(insp) => { + Self::Owned(insp) => { return insp.borrow_mut().call(context, inputs, return_memory_offset) } - MaybeOwnedInspector::Stacked(_) => None, + Self::Stacked(_) => None, } } @@ -121,10 +117,8 @@ where outcome: CallOutcome, ) -> CallOutcome { match self { - MaybeOwnedInspector::Owned(insp) => { - insp.borrow_mut().call_end(context, inputs, outcome) - } - MaybeOwnedInspector::Stacked(_) => outcome, + Self::Owned(insp) => insp.borrow_mut().call_end(context, inputs, outcome), + Self::Stacked(_) => outcome, } } @@ -134,8 +128,8 @@ where inputs: &mut CreateInputs, ) -> Option { match self { - MaybeOwnedInspector::Owned(insp) => return insp.borrow_mut().create(context, inputs), - MaybeOwnedInspector::Stacked(_) => None, + Self::Owned(insp) => return insp.borrow_mut().create(context, inputs), + Self::Stacked(_) => None, } } @@ -146,19 +140,15 @@ where outcome: CreateOutcome, ) -> CreateOutcome { match self { - MaybeOwnedInspector::Owned(insp) => { - return insp.borrow_mut().create_end(context, inputs, outcome) - } - MaybeOwnedInspector::Stacked(_) => outcome, + Self::Owned(insp) => return insp.borrow_mut().create_end(context, inputs, outcome), + Self::Stacked(_) => outcome, } } fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) { match self { - MaybeOwnedInspector::Owned(insp) => { - return insp.borrow_mut().selfdestruct(contract, target, value) - } - MaybeOwnedInspector::Stacked(_) => {} + Self::Owned(insp) => return insp.borrow_mut().selfdestruct(contract, target, value), + Self::Stacked(_) => {} } } } diff --git a/src/stack/mod.rs b/src/stack/mod.rs index aa241f17..378995c8 100644 --- a/src/stack/mod.rs +++ b/src/stack/mod.rs @@ -53,7 +53,7 @@ impl Debug for InspectorStack { impl InspectorStack { /// Create a new inspector stack. pub fn new(config: InspectorStackConfig) -> Self { - let mut stack = InspectorStack { hook: config.hook, ..Default::default() }; + let mut stack = Self { hook: config.hook, ..Default::default() }; if config.use_printer_tracer { stack.custom_print_tracer = Some(CustomPrintTracer::default()); diff --git a/src/tracing/arena.rs b/src/tracing/arena.rs index 247f1591..f5adcd80 100644 --- a/src/tracing/arena.rs +++ b/src/tracing/arena.rs @@ -80,13 +80,13 @@ pub(crate) enum PushTraceKind { impl PushTraceKind { #[inline] const fn is_attach_to_parent(&self) -> bool { - matches!(self, PushTraceKind::PushAndAttachToParent) + matches!(self, Self::PushAndAttachToParent) } } impl Default for CallTraceArena { fn default() -> Self { // The first node is the root node - CallTraceArena { arena: vec![Default::default()] } + Self { arena: vec![Default::default()] } } } diff --git a/src/tracing/config.rs b/src/tracing/config.rs index 4fb04a57..2f60d2dd 100644 --- a/src/tracing/config.rs +++ b/src/tracing/config.rs @@ -76,7 +76,7 @@ impl TracingInspectorConfig { let needs_vm_trace = trace_types.contains(&TraceType::VmTrace); let snap_type = if needs_vm_trace { StackSnapshotType::Pushes } else { StackSnapshotType::None }; - TracingInspectorConfig::default_parity() + Self::default_parity() .set_steps(needs_vm_trace) .set_stack_snapshots(snap_type) .set_memory_snapshots(needs_vm_trace) diff --git a/src/tracing/fourbyte.rs b/src/tracing/fourbyte.rs index 7893bc1d..0018f108 100644 --- a/src/tracing/fourbyte.rs +++ b/src/tracing/fourbyte.rs @@ -66,7 +66,7 @@ where impl From for FourByteFrame { fn from(value: FourByteInspector) -> Self { - FourByteFrame( + Self( value .inner .into_iter() diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index df356024..e20dcfb8 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -224,7 +224,7 @@ impl MemoryRef { /// Creates a new stack reference pub(crate) fn new(mem: &SharedMemory) -> (Self, GcGuard<'_, SharedMemory>) { let (inner, guard) = GuardedNullableGc::r#ref(mem); - (MemoryRef(inner), guard) + (Self(inner), guard) } fn len(&self) -> usize { @@ -316,7 +316,7 @@ impl StateRef { /// Creates a new stack reference pub(crate) fn new(state: &State) -> (Self, GcGuard<'_, State>) { let (inner, guard) = GuardedNullableGc::r#ref(state); - (StateRef(inner), guard) + (Self(inner), guard) } fn get_account(&self, address: &Address) -> Option { @@ -341,7 +341,7 @@ where /// Creates a new stack reference fn new<'a>(db: DB) -> (Self, GcGuard<'a, DB>) { let (inner, guard) = GuardedNullableGc::owned(db); - (GcDb(inner), guard) + (Self(inner), guard) } } @@ -416,7 +416,7 @@ impl StackRef { /// Creates a new stack reference pub(crate) fn new(stack: &Stack) -> (Self, GcGuard<'_, Stack>) { let (inner, guard) = GuardedNullableGc::r#ref(stack); - (StackRef(inner), guard) + (Self(inner), guard) } fn peek(&self, idx: usize, ctx: &mut Context<'_>) -> JsResult { @@ -497,7 +497,7 @@ impl Contract { /// /// Caution: this expects a global property `bigint` to be present. pub(crate) fn into_js_object(self, context: &mut Context<'_>) -> JsResult { - let Contract { caller, contract, value, input } = self; + let Self { caller, contract, value, input } = self; let obj = JsObject::default(); let get_caller = FunctionObjectBuilder::new( @@ -589,7 +589,7 @@ pub(crate) struct CallFrame { impl CallFrame { pub(crate) fn into_js_object(self, ctx: &mut Context<'_>) -> JsResult { - let CallFrame { contract: Contract { caller, contract, value, input }, kind, gas } = self; + let Self { contract: Contract { caller, contract, value, input }, kind, gas } = self; let obj = JsObject::default(); let get_from = FunctionObjectBuilder::new( diff --git a/src/tracing/types.rs b/src/tracing/types.rs index fde13488..786994a5 100644 --- a/src/tracing/types.rs +++ b/src/tracing/types.rs @@ -377,41 +377,41 @@ impl CallKind { /// Returns true if the call is a create #[inline] pub const fn is_any_create(&self) -> bool { - matches!(self, CallKind::Create | CallKind::Create2) + matches!(self, Self::Create | Self::Create2) } /// Returns true if the call is a delegate of some sorts #[inline] pub const fn is_delegate(&self) -> bool { - matches!(self, CallKind::DelegateCall | CallKind::CallCode) + matches!(self, Self::DelegateCall | Self::CallCode) } /// Returns true if the call is [CallKind::StaticCall]. #[inline] pub const fn is_static_call(&self) -> bool { - matches!(self, CallKind::StaticCall) + matches!(self, Self::StaticCall) } } impl std::fmt::Display for CallKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - CallKind::Call => { + Self::Call => { write!(f, "CALL") } - CallKind::StaticCall => { + Self::StaticCall => { write!(f, "STATICCALL") } - CallKind::CallCode => { + Self::CallCode => { write!(f, "CALLCODE") } - CallKind::DelegateCall => { + Self::DelegateCall => { write!(f, "DELEGATECALL") } - CallKind::Create => { + Self::Create => { write!(f, "CREATE") } - CallKind::Create2 => { + Self::Create2 => { write!(f, "CREATE2") } } @@ -421,10 +421,10 @@ impl std::fmt::Display for CallKind { impl From for CallKind { fn from(scheme: CallScheme) -> Self { match scheme { - CallScheme::Call => CallKind::Call, - CallScheme::StaticCall => CallKind::StaticCall, - CallScheme::CallCode => CallKind::CallCode, - CallScheme::DelegateCall => CallKind::DelegateCall, + CallScheme::Call => Self::Call, + CallScheme::StaticCall => Self::StaticCall, + CallScheme::CallCode => Self::CallCode, + CallScheme::DelegateCall => Self::DelegateCall, } } } @@ -432,8 +432,8 @@ impl From for CallKind { impl From for CallKind { fn from(create: CreateScheme) -> Self { match create { - CreateScheme::Create => CallKind::Create, - CreateScheme::Create2 { .. } => CallKind::Create2, + CreateScheme::Create => Self::Create, + CreateScheme::Create2 { .. } => Self::Create2, } } } @@ -442,10 +442,10 @@ impl From for ActionType { fn from(kind: CallKind) -> Self { match kind { CallKind::Call | CallKind::StaticCall | CallKind::DelegateCall | CallKind::CallCode => { - ActionType::Call + Self::Call } - CallKind::Create => ActionType::Create, - CallKind::Create2 => ActionType::Create, + CallKind::Create => Self::Create, + CallKind::Create2 => Self::Create, } } } @@ -453,12 +453,12 @@ impl From for ActionType { impl From for CallType { fn from(ty: CallKind) -> Self { match ty { - CallKind::Call => CallType::Call, - CallKind::StaticCall => CallType::StaticCall, - CallKind::CallCode => CallType::CallCode, - CallKind::DelegateCall => CallType::DelegateCall, - CallKind::Create => CallType::None, - CallKind::Create2 => CallType::None, + CallKind::Call => Self::Call, + CallKind::StaticCall => Self::StaticCall, + CallKind::CallCode => Self::CallCode, + CallKind::DelegateCall => Self::DelegateCall, + CallKind::Create => Self::None, + CallKind::Create2 => Self::None, } } }