Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Run cargo fix on a few of the worst offenders #10854

Merged
merged 8 commits into from
Jul 9, 2019
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
22 changes: 11 additions & 11 deletions ethcore/db/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ pub trait Key<T> {
/// Should be used to write value into database.
pub trait Writable {
/// Writes the value into the database.
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: AsRef<[u8]>;
fn write<T, R>(&mut self, col: Option<u32>, key: &dyn Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: AsRef<[u8]>;

/// Deletes key from the databse.
fn delete<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>) where T: rlp::Encodable, R: AsRef<[u8]>;
fn delete<T, R>(&mut self, col: Option<u32>, key: &dyn Key<T, Target = R>) where T: rlp::Encodable, R: AsRef<[u8]>;

/// Writes the value into the database and updates the cache.
fn write_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut Cache<K, T>, key: K, value: T, policy: CacheUpdatePolicy) where
fn write_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut dyn Cache<K, T>, key: K, value: T, policy: CacheUpdatePolicy) where
K: Key<T, Target = R> + Hash + Eq,
T: rlp::Encodable,
R: AsRef<[u8]> {
Expand All @@ -113,7 +113,7 @@ pub trait Writable {
}

/// Writes the values into the database and updates the cache.
fn extend_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut Cache<K, T>, values: HashMap<K, T>, policy: CacheUpdatePolicy) where
fn extend_with_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut dyn Cache<K, T>, values: HashMap<K, T>, policy: CacheUpdatePolicy) where
K: Key<T, Target = R> + Hash + Eq,
T: rlp::Encodable,
R: AsRef<[u8]> {
Expand All @@ -134,7 +134,7 @@ pub trait Writable {
}

/// Writes and removes the values into the database and updates the cache.
fn extend_with_option_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut Cache<K, Option<T>>, values: HashMap<K, Option<T>>, policy: CacheUpdatePolicy) where
fn extend_with_option_cache<K, T, R>(&mut self, col: Option<u32>, cache: &mut dyn Cache<K, Option<T>>, values: HashMap<K, Option<T>>, policy: CacheUpdatePolicy) where
K: Key<T, Target = R> + Hash + Eq,
T: rlp::Encodable,
R: AsRef<[u8]> {
Expand Down Expand Up @@ -165,7 +165,7 @@ pub trait Writable {
/// Should be used to read values from database.
pub trait Readable {
/// Returns value for given key.
fn read<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> Option<T> where
fn read<T, R>(&self, col: Option<u32>, key: &dyn Key<T, Target = R>) -> Option<T> where
T: rlp::Decodable,
R: AsRef<[u8]>;

Expand All @@ -189,7 +189,7 @@ pub trait Readable {
}

/// Returns true if given value exists.
fn exists<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> bool where R: AsRef<[u8]>;
fn exists<T, R>(&self, col: Option<u32>, key: &dyn Key<T, Target = R>) -> bool where R: AsRef<[u8]>;

/// Returns true if given value exists either in cache or in database.
fn exists_with_cache<K, T, R, C>(&self, col: Option<u32>, cache: &RwLock<C>, key: &K) -> bool where
Expand All @@ -208,25 +208,25 @@ pub trait Readable {
}

impl Writable for DBTransaction {
fn write<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: AsRef<[u8]> {
fn write<T, R>(&mut self, col: Option<u32>, key: &dyn Key<T, Target = R>, value: &T) where T: rlp::Encodable, R: AsRef<[u8]> {
self.put(col, key.key().as_ref(), &rlp::encode(value));
}

fn delete<T, R>(&mut self, col: Option<u32>, key: &Key<T, Target = R>) where T: rlp::Encodable, R: AsRef<[u8]> {
fn delete<T, R>(&mut self, col: Option<u32>, key: &dyn Key<T, Target = R>) where T: rlp::Encodable, R: AsRef<[u8]> {
self.delete(col, key.key().as_ref());
}
}

impl<KVDB: KeyValueDB + ?Sized> Readable for KVDB {
fn read<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> Option<T>
fn read<T, R>(&self, col: Option<u32>, key: &dyn Key<T, Target = R>) -> Option<T>
where T: rlp::Decodable, R: AsRef<[u8]> {
self.get(col, key.key().as_ref())
.expect(&format!("db get failed, key: {:?}", key.key().as_ref()))
.map(|v| rlp::decode(&v).expect("decode db value failed") )

}

fn exists<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>) -> bool where R: AsRef<[u8]> {
fn exists<T, R>(&self, col: Option<u32>, key: &dyn Key<T, Target = R>) -> bool where R: AsRef<[u8]> {
let result = self.get(col, key.key().as_ref());

match result {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Factory {
impl Factory {
/// Create fresh instance of VM
/// Might choose implementation depending on supplied gas.
pub fn create(&self, params: ActionParams, schedule: &Schedule, depth: usize) -> Box<Exec> {
pub fn create(&self, params: ActionParams, schedule: &Schedule, depth: usize) -> Box<dyn Exec> {
match self.evm {
VMType::Interpreter => if Self::can_fit_in_usize(&params.gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(params, self.evm_cache.clone(), schedule, depth))
Expand Down
6 changes: 3 additions & 3 deletions ethcore/evm/src/interpreter/gasometer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ impl<Gas: evm::CostType> Gasometer<Gas> {
/// it will be the amount of gas that the current context provides to the child context.
pub fn requirements(
&mut self,
ext: &vm::Ext,
ext: &dyn vm::Ext,
instruction: Instruction,
info: &InstructionInfo,
stack: &Stack<U256>,
stack: &dyn Stack<U256>,
current_mem_size: usize,
) -> vm::Result<InstructionRequirements<Gas>> {
let schedule = ext.schedule();
Expand Down Expand Up @@ -402,7 +402,7 @@ fn calculate_eip1283_sstore_gas<Gas: evm::CostType>(schedule: &Schedule, origina
)
}

pub fn handle_eip1283_sstore_clears_refund(ext: &mut vm::Ext, original: &U256, current: &U256, new: &U256) {
pub fn handle_eip1283_sstore_clears_refund(ext: &mut dyn vm::Ext, original: &U256, current: &U256, new: &U256) {
let sstore_clears_schedule = ext.schedule().sstore_refund_gas;

if current == new {
Expand Down
6 changes: 3 additions & 3 deletions ethcore/evm/src/interpreter/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
#[test]
fn test_memory_read_and_write() {
// given
let mem: &mut Memory = &mut vec![];
let mem: &mut dyn Memory = &mut vec![];
mem.resize(0x80 + 32);

// when
Expand All @@ -149,7 +149,7 @@ mod tests {
#[test]
fn test_memory_read_and_write_byte() {
// given
let mem: &mut Memory = &mut vec![];
let mem: &mut dyn Memory = &mut vec![];
mem.resize(32);

// when
Expand All @@ -163,7 +163,7 @@ mod tests {

#[test]
fn test_memory_read_slice_and_write_slice() {
let mem: &mut Memory = &mut vec![];
let mem: &mut dyn Memory = &mut vec![];
mem.resize(32);

{
Expand Down
26 changes: 13 additions & 13 deletions ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub struct Interpreter<Cost: CostType> {
}

impl<Cost: 'static + CostType> vm::Exec for Interpreter<Cost> {
fn exec(mut self: Box<Self>, ext: &mut vm::Ext) -> vm::ExecTrapResult<GasLeft> {
fn exec(mut self: Box<Self>, ext: &mut dyn vm::Ext) -> vm::ExecTrapResult<GasLeft> {
loop {
let result = self.step(ext);
match result {
Expand All @@ -215,7 +215,7 @@ impl<Cost: 'static + CostType> vm::Exec for Interpreter<Cost> {
}

impl<Cost: 'static + CostType> vm::ResumeCall for Interpreter<Cost> {
fn resume_call(mut self: Box<Self>, result: MessageCallResult) -> Box<vm::Exec> {
fn resume_call(mut self: Box<Self>, result: MessageCallResult) -> Box<dyn vm::Exec> {
{
let this = &mut *self;
let (out_off, out_size) = this.resume_output_range.take().expect("Box<ResumeCall> is obtained from a call opcode; resume_output_range is always set after those opcodes are executed; qed");
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<Cost: 'static + CostType> vm::ResumeCall for Interpreter<Cost> {
}

impl<Cost: 'static + CostType> vm::ResumeCreate for Interpreter<Cost> {
fn resume_create(mut self: Box<Self>, result: ContractCreateResult) -> Box<vm::Exec> {
fn resume_create(mut self: Box<Self>, result: ContractCreateResult) -> Box<dyn vm::Exec> {
match result {
ContractCreateResult::Created(address, gas_left) => {
self.stack.push(address_to_u256(address));
Expand Down Expand Up @@ -296,7 +296,7 @@ impl<Cost: CostType> Interpreter<Cost> {

/// Execute a single step on the VM.
#[inline(always)]
pub fn step(&mut self, ext: &mut vm::Ext) -> InterpreterResult {
pub fn step(&mut self, ext: &mut dyn vm::Ext) -> InterpreterResult {
if self.done {
return InterpreterResult::Stopped;
}
Expand All @@ -318,7 +318,7 @@ impl<Cost: CostType> Interpreter<Cost> {

/// Inner helper function for step.
#[inline(always)]
fn step_inner(&mut self, ext: &mut vm::Ext) -> Result<Never, InterpreterResult> {
fn step_inner(&mut self, ext: &mut dyn vm::Ext) -> Result<Never, InterpreterResult> {
let result = match self.resume_result.take() {
Some(result) => result,
None => {
Expand Down Expand Up @@ -414,7 +414,7 @@ impl<Cost: CostType> Interpreter<Cost> {
Err(InterpreterResult::Continue)
}

fn verify_instruction(&self, ext: &vm::Ext, instruction: Instruction, info: &InstructionInfo) -> vm::Result<()> {
fn verify_instruction(&self, ext: &dyn vm::Ext, instruction: Instruction, info: &InstructionInfo) -> vm::Result<()> {
let schedule = ext.schedule();

if (instruction == instructions::DELEGATECALL && !schedule.have_delegate_call) ||
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<Cost: CostType> Interpreter<Cost> {

fn mem_written(
instruction: Instruction,
stack: &Stack<U256>
stack: &dyn Stack<U256>
) -> Option<(usize, usize)> {
let read = |pos| stack.peek(pos).low_u64() as usize;
let written = match instruction {
Expand All @@ -470,7 +470,7 @@ impl<Cost: CostType> Interpreter<Cost> {

fn store_written(
instruction: Instruction,
stack: &Stack<U256>
stack: &dyn Stack<U256>
) -> Option<(U256, U256)> {
match instruction {
instructions::SSTORE => Some((stack.peek(0).clone(), stack.peek(1).clone())),
Expand All @@ -481,7 +481,7 @@ impl<Cost: CostType> Interpreter<Cost> {
fn exec_instruction(
&mut self,
gas: Cost,
ext: &mut vm::Ext,
ext: &mut dyn vm::Ext,
instruction: Instruction,
provided: Option<Cost>
) -> vm::Result<InstructionResult<Cost>> {
Expand Down Expand Up @@ -1108,7 +1108,7 @@ impl<Cost: CostType> Interpreter<Cost> {
Ok(InstructionResult::Ok)
}

fn copy_data_to_memory(mem: &mut Vec<u8>, stack: &mut Stack<U256>, source: &[u8]) {
fn copy_data_to_memory(mem: &mut Vec<u8>, stack: &mut dyn Stack<U256>, source: &[u8]) {
let dest_offset = stack.pop_back();
let source_offset = stack.pop_back();
let size = stack.pop_back();
Expand Down Expand Up @@ -1191,7 +1191,7 @@ mod tests {
use vm::tests::{FakeExt, test_finalize};
use ethereum_types::Address;

fn interpreter(params: ActionParams, ext: &vm::Ext) -> Box<Exec> {
fn interpreter(params: ActionParams, ext: &dyn vm::Ext) -> Box<dyn Exec> {
Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth())
}

Expand All @@ -1210,7 +1210,7 @@ mod tests {
ext.tracing = true;

let gas_left = {
let mut vm = interpreter(params, &ext);
let vm = interpreter(params, &ext);
test_finalize(vm.exec(&mut ext).ok().unwrap()).unwrap()
};

Expand All @@ -1232,7 +1232,7 @@ mod tests {
ext.tracing = true;

let err = {
let mut vm = interpreter(params, &ext);
let vm = interpreter(params, &ext);
test_finalize(vm.exec(&mut ext).ok().unwrap()).err().unwrap()
};

Expand Down
Loading