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: fix clippy::use_self #34

Merged
merged 1 commit into from
Feb 15, 2024
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
2 changes: 1 addition & 1 deletion src/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl AccessListInspector {
to: Address,
precompiles: impl IntoIterator<Item = Address>,
) -> Self {
AccessListInspector {
Self {
excluded: [from, to].into_iter().chain(precompiles).collect(),
access_list: access_list
.0
Expand Down
2 changes: 1 addition & 1 deletion src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 22 additions & 32 deletions src/stack/maybe_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@ pub enum MaybeOwnedInspector<INSP> {
impl<INSP> MaybeOwnedInspector<INSP> {
/// 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(),
}
}
}
Expand Down Expand Up @@ -72,31 +70,29 @@ where
{
fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>) {
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<DB>) {
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<DB>, 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<DB>) {
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(_) => {}
}
}

Expand All @@ -107,10 +103,10 @@ where
return_memory_offset: Range<usize>,
) -> Option<CallOutcome> {
match self {
MaybeOwnedInspector::Owned(insp) => {
Self::Owned(insp) => {
return insp.borrow_mut().call(context, inputs, return_memory_offset)
}
MaybeOwnedInspector::Stacked(_) => None,
Self::Stacked(_) => None,
}
}

Expand All @@ -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,
}
}

Expand All @@ -134,8 +128,8 @@ where
inputs: &mut CreateInputs,
) -> Option<CreateOutcome> {
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,
}
}

Expand All @@ -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(_) => {}
}
}
}
2 changes: 1 addition & 1 deletion src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()] }
}
}
2 changes: 1 addition & 1 deletion src/tracing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/fourbyte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where

impl From<FourByteInspector> for FourByteFrame {
fn from(value: FourByteInspector) -> Self {
FourByteFrame(
Self(
value
.inner
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions src/tracing/js/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<AccountInfo> {
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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<JsValue> {
Expand Down Expand Up @@ -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<JsObject> {
let Contract { caller, contract, value, input } = self;
let Self { caller, contract, value, input } = self;
let obj = JsObject::default();

let get_caller = FunctionObjectBuilder::new(
Expand Down Expand Up @@ -589,7 +589,7 @@ pub(crate) struct CallFrame {

impl CallFrame {
pub(crate) fn into_js_object(self, ctx: &mut Context<'_>) -> JsResult<JsObject> {
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(
Expand Down
48 changes: 24 additions & 24 deletions src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -421,19 +421,19 @@ impl std::fmt::Display for CallKind {
impl From<CallScheme> 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,
}
}
}

impl From<CreateScheme> 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,
}
}
}
Expand All @@ -442,23 +442,23 @@ impl From<CallKind> 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,
}
}
}

impl From<CallKind> 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,
}
}
}
Expand Down
Loading