Fixing clippy warnings
This commit is contained in:
@@ -24,6 +24,7 @@ pub type LogBloom = H2048;
|
||||
/// Constant 2048-bit datum for 0. Often used as a default.
|
||||
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
|
||||
|
||||
#[allow(enum_variant_names)]
|
||||
/// Semantic boolean for when a seal/signature is included.
|
||||
pub enum Seal {
|
||||
/// The seal/signature is included.
|
||||
|
||||
@@ -87,6 +87,7 @@ struct QueueSignal {
|
||||
}
|
||||
|
||||
impl QueueSignal {
|
||||
#[allow(bool_comparison)]
|
||||
fn set(&self) {
|
||||
if self.signalled.compare_and_swap(false, true, AtomicOrdering::Relaxed) == false {
|
||||
self.message_channel.send(UserMessage(SyncMessage::BlockVerified)).expect("Error sending BlockVerified message");
|
||||
|
||||
@@ -212,7 +212,7 @@ impl Memory for Vec<u8> {
|
||||
fn write(&mut self, offset: U256, value: U256) {
|
||||
let off = offset.low_u64() as usize;
|
||||
let mut val = value;
|
||||
|
||||
|
||||
let end = off + 32;
|
||||
for pos in 0..32 {
|
||||
self[end - pos - 1] = val.low_u64() as u8;
|
||||
@@ -229,7 +229,7 @@ impl Memory for Vec<u8> {
|
||||
fn resize(&mut self, new_size: usize) {
|
||||
self.resize(new_size, 0);
|
||||
}
|
||||
|
||||
|
||||
fn expand(&mut self, size: usize) {
|
||||
if size > self.len() {
|
||||
Memory::resize(self, size)
|
||||
@@ -258,6 +258,7 @@ impl<'a> CodeReader<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(enum_variant_names)]
|
||||
enum InstructionCost {
|
||||
Gas(U256),
|
||||
GasMem(U256, U256),
|
||||
@@ -282,7 +283,7 @@ impl evm::Evm for Interpreter {
|
||||
let code = ¶ms.code.as_ref().unwrap();
|
||||
let valid_jump_destinations = self.find_jump_destinations(&code);
|
||||
|
||||
let mut current_gas = params.gas.clone();
|
||||
let mut current_gas = params.gas;
|
||||
let mut stack = VecStack::with_capacity(ext.schedule().stack_limit, U256::zero());
|
||||
let mut mem = vec![];
|
||||
let mut reader = CodeReader {
|
||||
@@ -331,7 +332,7 @@ impl evm::Evm for Interpreter {
|
||||
let pos = try!(self.verify_jump(position, &valid_jump_destinations));
|
||||
reader.position = pos;
|
||||
},
|
||||
InstructionResult::StopExecutionWithGasLeft(gas_left) => {
|
||||
InstructionResult::StopExecutionWithGasLeft(gas_left) => {
|
||||
current_gas = gas_left;
|
||||
reader.position = code.len();
|
||||
},
|
||||
@@ -380,10 +381,9 @@ impl Interpreter {
|
||||
|
||||
let gas = if self.is_zero(&val) && !self.is_zero(newval) {
|
||||
schedule.sstore_set_gas
|
||||
} else if !self.is_zero(&val) && self.is_zero(newval) {
|
||||
// Refund is added when actually executing sstore
|
||||
schedule.sstore_reset_gas
|
||||
} else {
|
||||
// Refund for below case is added when actually executing sstore
|
||||
// !self.is_zero(&val) && self.is_zero(newval)
|
||||
schedule.sstore_reset_gas
|
||||
};
|
||||
InstructionCost::Gas(U256::from(gas))
|
||||
@@ -406,10 +406,7 @@ impl Interpreter {
|
||||
let gas = U256::from(schedule.sha3_gas) + (U256::from(schedule.sha3_word_gas) * words);
|
||||
InstructionCost::GasMem(gas, try!(self.mem_needed(stack.peek(0), stack.peek(1))))
|
||||
},
|
||||
instructions::CALLDATACOPY => {
|
||||
InstructionCost::GasMemCopy(default_gas, try!(self.mem_needed(stack.peek(0), stack.peek(2))), stack.peek(2).clone())
|
||||
},
|
||||
instructions::CODECOPY => {
|
||||
instructions::CALLDATACOPY | instructions::CODECOPY => {
|
||||
InstructionCost::GasMemCopy(default_gas, try!(self.mem_needed(stack.peek(0), stack.peek(2))), stack.peek(2).clone())
|
||||
},
|
||||
instructions::EXTCODECOPY => {
|
||||
@@ -432,7 +429,7 @@ impl Interpreter {
|
||||
try!(self.mem_needed(stack.peek(5), stack.peek(6))),
|
||||
try!(self.mem_needed(stack.peek(3), stack.peek(4)))
|
||||
);
|
||||
|
||||
|
||||
let address = u256_to_address(stack.peek(1));
|
||||
|
||||
if instruction == instructions::CALL && !ext.exists(&address) {
|
||||
@@ -529,8 +526,8 @@ impl Interpreter {
|
||||
params: &ActionParams,
|
||||
ext: &mut evm::Ext,
|
||||
instruction: Instruction,
|
||||
code: &mut CodeReader,
|
||||
mem: &mut Memory,
|
||||
code: &mut CodeReader,
|
||||
mem: &mut Memory,
|
||||
stack: &mut Stack<U256>
|
||||
) -> Result<InstructionResult, evm::Error> {
|
||||
match instruction {
|
||||
@@ -559,7 +556,7 @@ impl Interpreter {
|
||||
|
||||
let contract_code = mem.read_slice(init_off, init_size);
|
||||
let can_create = ext.balance(¶ms.address) >= endowment && ext.depth() < ext.schedule().max_depth;
|
||||
|
||||
|
||||
if !can_create {
|
||||
stack.push(U256::zero());
|
||||
return Ok(InstructionResult::Ok);
|
||||
@@ -638,7 +635,7 @@ impl Interpreter {
|
||||
Ok(InstructionResult::Ok)
|
||||
}
|
||||
};
|
||||
},
|
||||
},
|
||||
instructions::RETURN => {
|
||||
let init_off = stack.pop_back();
|
||||
let init_size = stack.pop_back();
|
||||
@@ -832,20 +829,20 @@ impl Interpreter {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_instructions_requirements(&self,
|
||||
info: &instructions::InstructionInfo,
|
||||
stack_limit: usize,
|
||||
fn verify_instructions_requirements(&self,
|
||||
info: &instructions::InstructionInfo,
|
||||
stack_limit: usize,
|
||||
stack: &Stack<U256>) -> Result<(), evm::Error> {
|
||||
if !stack.has(info.args) {
|
||||
Err(evm::Error::StackUnderflow {
|
||||
instruction: info.name,
|
||||
wanted: info.args,
|
||||
wanted: info.args,
|
||||
on_stack: stack.size()
|
||||
})
|
||||
} else if stack.size() - info.args + info.ret > stack_limit {
|
||||
Err(evm::Error::OutOfStack {
|
||||
instruction: info.name,
|
||||
wanted: info.ret - info.args,
|
||||
wanted: info.ret - info.args,
|
||||
limit: stack_limit
|
||||
})
|
||||
} else {
|
||||
@@ -919,7 +916,7 @@ impl Interpreter {
|
||||
stack.push(if !self.is_zero(&b) {
|
||||
a.overflowing_div(b).0
|
||||
} else {
|
||||
U256::zero()
|
||||
U256::zero()
|
||||
});
|
||||
},
|
||||
instructions::MOD => {
|
||||
@@ -978,9 +975,9 @@ impl Interpreter {
|
||||
let (a, neg_a) = get_and_reset_sign(stack.pop_back());
|
||||
let (b, neg_b) = get_and_reset_sign(stack.pop_back());
|
||||
|
||||
let is_positive_lt = a < b && (neg_a | neg_b) == false;
|
||||
let is_negative_lt = a > b && (neg_a & neg_b) == true;
|
||||
let has_different_signs = neg_a == true && neg_b == false;
|
||||
let is_positive_lt = a < b && !(neg_a | neg_b);
|
||||
let is_negative_lt = a > b && (neg_a & neg_b);
|
||||
let has_different_signs = neg_a && !neg_b;
|
||||
|
||||
stack.push(self.bool_to_u256(is_positive_lt | is_negative_lt | has_different_signs));
|
||||
},
|
||||
@@ -993,9 +990,9 @@ impl Interpreter {
|
||||
let (a, neg_a) = get_and_reset_sign(stack.pop_back());
|
||||
let (b, neg_b) = get_and_reset_sign(stack.pop_back());
|
||||
|
||||
let is_positive_gt = a > b && (neg_a | neg_b) == false;
|
||||
let is_negative_gt = a < b && (neg_a & neg_b) == true;
|
||||
let has_different_signs = neg_a == false && neg_b == true;
|
||||
let is_positive_gt = a > b && !(neg_a | neg_b);
|
||||
let is_negative_gt = a < b && (neg_a & neg_b);
|
||||
let has_different_signs = !neg_a && neg_b;
|
||||
|
||||
stack.push(self.bool_to_u256(is_positive_gt | is_negative_gt | has_different_signs));
|
||||
},
|
||||
@@ -1175,7 +1172,7 @@ mod tests {
|
||||
let schedule = evm::Schedule::default();
|
||||
let current_mem_size = 0;
|
||||
let mem_size = U256::from(5);
|
||||
|
||||
|
||||
// when
|
||||
let (mem_cost, mem_size) = interpreter.mem_gas_cost(&schedule, current_mem_size, &mem_size).unwrap();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ struct FakeLogEntry {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Debug)]
|
||||
#[allow(enum_variant_names)] // Common prefix is C ;)
|
||||
enum FakeCallType {
|
||||
CALL, CREATE
|
||||
}
|
||||
@@ -59,7 +60,7 @@ struct FakeExt {
|
||||
}
|
||||
|
||||
impl FakeExt {
|
||||
fn new() -> Self {
|
||||
fn new() -> Self {
|
||||
FakeExt::default()
|
||||
}
|
||||
}
|
||||
@@ -104,13 +105,13 @@ impl Ext for FakeExt {
|
||||
ContractCreateResult::Failed
|
||||
}
|
||||
|
||||
fn call(&mut self,
|
||||
gas: &U256,
|
||||
sender_address: &Address,
|
||||
receive_address: &Address,
|
||||
fn call(&mut self,
|
||||
gas: &U256,
|
||||
sender_address: &Address,
|
||||
receive_address: &Address,
|
||||
value: Option<U256>,
|
||||
data: &[u8],
|
||||
code_address: &Address,
|
||||
data: &[u8],
|
||||
code_address: &Address,
|
||||
_output: &mut [u8]) -> MessageCallResult {
|
||||
|
||||
self.calls.insert(FakeCall {
|
||||
@@ -176,7 +177,7 @@ fn test_stack_underflow() {
|
||||
let vm : Box<evm::Evm> = Box::new(super::interpreter::Interpreter);
|
||||
vm.exec(params, &mut ext).unwrap_err()
|
||||
};
|
||||
|
||||
|
||||
match err {
|
||||
evm::Error::StackUnderflow {wanted, on_stack, ..} => {
|
||||
assert_eq!(wanted, 2);
|
||||
@@ -353,7 +354,7 @@ evm_test!{test_log_sender: test_log_sender_jit, test_log_sender_int}
|
||||
fn test_log_sender(factory: super::Factory) {
|
||||
// 60 ff - push ff
|
||||
// 60 00 - push 00
|
||||
// 53 - mstore
|
||||
// 53 - mstore
|
||||
// 33 - sender
|
||||
// 60 20 - push 20
|
||||
// 60 00 - push 0
|
||||
@@ -449,7 +450,7 @@ fn test_author(factory: super::Factory) {
|
||||
|
||||
evm_test!{test_timestamp: test_timestamp_jit, test_timestamp_int}
|
||||
fn test_timestamp(factory: super::Factory) {
|
||||
let timestamp = 0x1234;
|
||||
let timestamp = 0x1234;
|
||||
let code = "42600055".from_hex().unwrap();
|
||||
|
||||
let mut params = ActionParams::default();
|
||||
@@ -469,7 +470,7 @@ fn test_timestamp(factory: super::Factory) {
|
||||
|
||||
evm_test!{test_number: test_number_jit, test_number_int}
|
||||
fn test_number(factory: super::Factory) {
|
||||
let number = 0x1234;
|
||||
let number = 0x1234;
|
||||
let code = "43600055".from_hex().unwrap();
|
||||
|
||||
let mut params = ActionParams::default();
|
||||
|
||||
@@ -363,7 +363,7 @@ mod tests {
|
||||
&Address::new(),
|
||||
&Address::new(),
|
||||
Some(U256::from_str("0000000000000000000000000000000000000000000000000000000000150000").unwrap()),
|
||||
&vec![],
|
||||
&[],
|
||||
&Address::new(),
|
||||
&mut output);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,15 @@
|
||||
#![feature(cell_extras)]
|
||||
#![feature(augmented_assignments)]
|
||||
#![feature(plugin)]
|
||||
// Clippy
|
||||
#![plugin(clippy)]
|
||||
#![allow(needless_range_loop, match_bool)]
|
||||
// TODO [todr] not really sure
|
||||
#![allow(needless_range_loop)]
|
||||
// Shorter than if-else
|
||||
#![allow(match_bool)]
|
||||
// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref.
|
||||
#![allow(clone_on_copy)]
|
||||
|
||||
|
||||
//! Ethcore library
|
||||
//!
|
||||
@@ -54,7 +61,7 @@
|
||||
//! cd parity
|
||||
//! cargo build --release
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! - OSX:
|
||||
//!
|
||||
//! ```bash
|
||||
@@ -124,8 +131,8 @@ mod executive;
|
||||
mod externalities;
|
||||
mod verification;
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
#[cfg(feature="json-tests")]
|
||||
#[cfg(feature="json-tests")]
|
||||
mod json_tests;
|
||||
|
||||
Reference in New Issue
Block a user