Fixing clippy warnings (#1568)

* Fixing clippy warnings

* Fixing more warnings
This commit is contained in:
Tomasz Drwięga 2016-07-10 13:18:33 +02:00 committed by Arkadiy Paronyan
parent ae757afe15
commit d7caae2241
9 changed files with 43 additions and 26 deletions

View File

@ -587,14 +587,14 @@ impl Client {
} }
/// Notify us that the network has been started. /// Notify us that the network has been started.
pub fn network_started(&self, url: &String) { pub fn network_started(&self, url: &str) {
let mut previous_enode = self.previous_enode.locked(); let mut previous_enode = self.previous_enode.locked();
if let Some(ref u) = *previous_enode { if let Some(ref u) = *previous_enode {
if u == url { if u == url {
return; return;
} }
} }
*previous_enode = Some(url.clone()); *previous_enode = Some(url.into());
info!(target: "mode", "Public node URL: {}", url.apply(Colour::White.bold())); info!(target: "mode", "Public node URL: {}", url.apply(Colour::White.bold()));
} }
} }

View File

@ -93,11 +93,11 @@ impl Default for MinerOptions {
pub struct GasPriceCalibratorOptions { pub struct GasPriceCalibratorOptions {
/// Base transaction price to match against. /// Base transaction price to match against.
pub usd_per_tx: f32, pub usd_per_tx: f32,
/// How frequently we should recalibrate. /// How frequently we should recalibrate.
pub recalibration_period: Duration, pub recalibration_period: Duration,
} }
/// The gas price validator variant for a GasPricer. /// The gas price validator variant for a `GasPricer`.
pub struct GasPriceCalibrator { pub struct GasPriceCalibrator {
options: GasPriceCalibratorOptions, options: GasPriceCalibratorOptions,

View File

@ -158,21 +158,19 @@ impl Configuration {
die!("{}: Invalid duration given. See parity --help for more information.", s) die!("{}: Invalid duration given. See parity --help for more information.", s)
}; };
Duration::from_secs(match s { Duration::from_secs(match s {
"daily" => 24 * 60 * 60,
"twice-daily" => 12 * 60 * 60, "twice-daily" => 12 * 60 * 60,
"hourly" => 60 * 60,
"half-hourly" => 30 * 60, "half-hourly" => 30 * 60,
"1second" | "1 second" | "second" => 1, "1second" | "1 second" | "second" => 1,
"1minute" | "1 minute" | "minute" => 60, "1minute" | "1 minute" | "minute" => 60,
"1hour" | "1 hour" | "hour" => 60 * 60, "hourly" | "1hour" | "1 hour" | "hour" => 60 * 60,
"1day" | "1 day" | "day" => 24 * 60 * 60, "daily" | "1day" | "1 day" | "day" => 24 * 60 * 60,
x if x.ends_with("seconds") => FromStr::from_str(&x[0..x.len() - 7]).unwrap_or_else(bad), x if x.ends_with("seconds") => FromStr::from_str(&x[0..x.len() - 7]).unwrap_or_else(bad),
x if x.ends_with("minutes") => FromStr::from_str(&x[0..x.len() - 7]).unwrap_or_else(bad) * 60, x if x.ends_with("minutes") => FromStr::from_str(&x[0..x.len() - 7]).unwrap_or_else(bad) * 60,
x if x.ends_with("hours") => FromStr::from_str(&x[0..x.len() - 5]).unwrap_or_else(bad) * 60 * 60, x if x.ends_with("hours") => FromStr::from_str(&x[0..x.len() - 5]).unwrap_or_else(bad) * 60 * 60,
x if x.ends_with("days") => FromStr::from_str(&x[0..x.len() - 4]).unwrap_or_else(bad) * 24 * 60 * 60, x if x.ends_with("days") => FromStr::from_str(&x[0..x.len() - 4]).unwrap_or_else(bad) * 24 * 60 * 60,
x => FromStr::from_str(x).unwrap_or_else(bad), x => FromStr::from_str(x).unwrap_or_else(bad),
}) })
} }
pub fn gas_pricer(&self) -> GasPricer { pub fn gas_pricer(&self) -> GasPricer {
match self.args.flag_gasprice.as_ref() { match self.args.flag_gasprice.as_ref() {

View File

@ -75,7 +75,6 @@ impl Informant {
} }
} }
#[cfg_attr(feature="dev", allow(match_bool))]
pub fn tick<Message>(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService<Message>)>) where Message: Send + Sync + Clone + 'static { pub fn tick<Message>(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService<Message>)>) where Message: Send + Sync + Clone + 'static {
let elapsed = self.last_tick.unwrapped_read().elapsed(); let elapsed = self.last_tick.unwrapped_read().elapsed();
if elapsed < Duration::from_secs(5) { if elapsed < Duration::from_secs(5) {

View File

@ -20,6 +20,7 @@
#![cfg_attr(feature="dev", feature(plugin))] #![cfg_attr(feature="dev", feature(plugin))]
#![cfg_attr(feature="dev", plugin(clippy))] #![cfg_attr(feature="dev", plugin(clippy))]
#![cfg_attr(feature="dev", allow(useless_format))] #![cfg_attr(feature="dev", allow(useless_format))]
#![cfg_attr(feature="dev", allow(match_bool))]
extern crate docopt; extern crate docopt;
extern crate num_cpus; extern crate num_cpus;

View File

@ -21,7 +21,6 @@ use std::sync::{Arc, Weak, Mutex};
use std::collections::HashSet; use std::collections::HashSet;
use jsonrpc_core::*; use jsonrpc_core::*;
use util::Lockable; use util::Lockable;
use util::numbers::*;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::filter::Filter as EthcoreFilter; use ethcore::filter::Filter as EthcoreFilter;
use ethcore::client::{BlockChainClient, BlockID}; use ethcore::client::{BlockChainClient, BlockID};

View File

@ -18,7 +18,7 @@ use std::str::FromStr;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
use util::{Lockable, RwLockable}; use util::RwLockable;
use util::hash::{Address, H256, FixedHash}; use util::hash::{Address, H256, FixedHash};
use util::numbers::{Uint, U256}; use util::numbers::{Uint, U256};
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;

View File

@ -92,7 +92,7 @@ impl<T: SimpleMigration> Migration for T {
} }
} }
if batch.len() != 0 { if !batch.is_empty() {
try!(commit_batch(dest, &batch)); try!(commit_batch(dest, &batch));
} }
@ -189,12 +189,12 @@ impl Manager {
// start with the old db. // start with the old db.
let old_path_str = try!(old_path.to_str().ok_or(Error::MigrationImpossible)); let old_path_str = try!(old_path.to_str().ok_or(Error::MigrationImpossible));
let mut cur_db = try!(Database::open(&db_config, old_path_str).map_err(|s| Error::Custom(s))); let mut cur_db = try!(Database::open(&db_config, old_path_str).map_err(Error::Custom));
for migration in migrations { for migration in migrations {
// open the target temporary database. // open the target temporary database.
temp_path = temp_idx.path(&db_root); temp_path = temp_idx.path(&db_root);
let temp_path_str = try!(temp_path.to_str().ok_or(Error::MigrationImpossible)); let temp_path_str = try!(temp_path.to_str().ok_or(Error::MigrationImpossible));
let mut new_db = try!(Database::open(&db_config, temp_path_str).map_err(|s| Error::Custom(s))); let mut new_db = try!(Database::open(&db_config, temp_path_str).map_err(Error::Custom));
// perform the migration from cur_db to new_db. // perform the migration from cur_db to new_db.
try!(migration.migrate(&cur_db, &self.config, &mut new_db)); try!(migration.migrate(&cur_db, &self.config, &mut new_db));

View File

@ -1,16 +1,33 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! An owning, nibble-oriented byte vector. //! An owning, nibble-oriented byte vector.
use ::NibbleSlice; use ::NibbleSlice;
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Debug)]
/// Owning, nibble-oriented byte vector. Counterpart to NibbleSlice. /// Owning, nibble-oriented byte vector. Counterpart to `NibbleSlice`.
pub struct NibbleVec { pub struct NibbleVec {
inner: Vec<u8>, inner: Vec<u8>,
len: usize, len: usize,
} }
impl NibbleVec { impl NibbleVec {
/// Make a new NibbleVec /// Make a new `NibbleVec`
pub fn new() -> Self { pub fn new() -> Self {
NibbleVec { NibbleVec {
inner: Vec::new(), inner: Vec::new(),
@ -18,7 +35,7 @@ impl NibbleVec {
} }
} }
/// Make a NibbleVec with capacity for `n` nibbles. /// Make a `NibbleVec` with capacity for `n` nibbles.
pub fn with_capacity(n: usize) -> Self { pub fn with_capacity(n: usize) -> Self {
NibbleVec { NibbleVec {
inner: Vec::with_capacity((n / 2) + (n % 2)), inner: Vec::with_capacity((n / 2) + (n % 2)),
@ -26,10 +43,13 @@ impl NibbleVec {
} }
} }
/// Length of the NibbleVec /// Length of the `NibbleVec`
pub fn len(&self) -> usize { self.len } pub fn len(&self) -> usize { self.len }
/// Capacity of the NibbleVec. /// Retrurns true if `NibbleVec` has zero length
pub fn is_empty(&self) -> bool { self.len == 0 }
/// Capacity of the `NibbleVec`.
pub fn capacity(&self) -> usize { self.inner.capacity() * 2 } pub fn capacity(&self) -> usize { self.inner.capacity() * 2 }
/// Try to get the nibble at the given offset. /// Try to get the nibble at the given offset.
@ -41,7 +61,7 @@ impl NibbleVec {
} }
} }
/// Push a nibble onto the NibbleVec. Ignores the high 4 bits. /// Push a nibble onto the `NibbleVec`. Ignores the high 4 bits.
pub fn push(&mut self, nibble: u8) { pub fn push(&mut self, nibble: u8) {
let nibble = nibble & 0x0F; let nibble = nibble & 0x0F;
@ -54,9 +74,9 @@ impl NibbleVec {
self.len += 1; self.len += 1;
} }
/// Try to pop a nibble off the NibbleVec. Fails if len == 0. /// Try to pop a nibble off the `NibbleVec`. Fails if len == 0.
pub fn pop(&mut self) -> Option<u8> { pub fn pop(&mut self) -> Option<u8> {
if self.len == 0 { if self.is_empty() {
return None; return None;
} }
@ -72,7 +92,7 @@ impl NibbleVec {
Some(nibble) Some(nibble)
} }
/// Try to treat this NibbleVec as a NibbleSlice. Works only if len is even. /// Try to treat this `NibbleVec` as a `NibbleSlice`. Works only if len is even.
pub fn as_nibbleslice(&self) -> Option<NibbleSlice> { pub fn as_nibbleslice(&self) -> Option<NibbleSlice> {
if self.len % 2 == 0 { if self.len % 2 == 0 {
Some(NibbleSlice::new(self.inner())) Some(NibbleSlice::new(self.inner()))
@ -127,4 +147,4 @@ mod tests {
let v2: NibbleVec = v.as_nibbleslice().unwrap().into(); let v2: NibbleVec = v.as_nibbleslice().unwrap().into();
assert_eq!(v, v2); assert_eq!(v, v2);
} }
} }