From d7caae22416d26a20bdd83671ef787b490ad71c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 10 Jul 2016 13:18:33 +0200 Subject: [PATCH] Fixing clippy warnings (#1568) * Fixing clippy warnings * Fixing more warnings --- ethcore/src/client/client.rs | 4 ++-- ethcore/src/miner/miner.rs | 4 ++-- parity/configuration.rs | 8 +++---- parity/informant.rs | 1 - parity/main.rs | 1 + rpc/src/v1/impls/eth_filter.rs | 1 - rpc/src/v1/tests/mocked/eth.rs | 2 +- util/src/migration/mod.rs | 6 ++--- util/src/nibblevec.rs | 42 +++++++++++++++++++++++++--------- 9 files changed, 43 insertions(+), 26 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 043b35410..0c6a2c005 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -587,14 +587,14 @@ impl Client { } /// 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(); if let Some(ref u) = *previous_enode { if u == url { return; } } - *previous_enode = Some(url.clone()); + *previous_enode = Some(url.into()); info!(target: "mode", "Public node URL: {}", url.apply(Colour::White.bold())); } } diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 297f8227b..c5e4b4a5c 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -93,11 +93,11 @@ impl Default for MinerOptions { pub struct GasPriceCalibratorOptions { /// Base transaction price to match against. pub usd_per_tx: f32, - /// How frequently we should recalibrate. + /// How frequently we should recalibrate. pub recalibration_period: Duration, } -/// The gas price validator variant for a GasPricer. +/// The gas price validator variant for a `GasPricer`. pub struct GasPriceCalibrator { options: GasPriceCalibratorOptions, diff --git a/parity/configuration.rs b/parity/configuration.rs index ec5f99608..5bf632e41 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -158,21 +158,19 @@ impl Configuration { die!("{}: Invalid duration given. See parity --help for more information.", s) }; Duration::from_secs(match s { - "daily" => 24 * 60 * 60, "twice-daily" => 12 * 60 * 60, - "hourly" => 60 * 60, "half-hourly" => 30 * 60, "1second" | "1 second" | "second" => 1, "1minute" | "1 minute" | "minute" => 60, - "1hour" | "1 hour" | "hour" => 60 * 60, - "1day" | "1 day" | "day" => 24 * 60 * 60, + "hourly" | "1hour" | "1 hour" | "hour" => 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("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("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), }) - } + } pub fn gas_pricer(&self) -> GasPricer { match self.args.flag_gasprice.as_ref() { diff --git a/parity/informant.rs b/parity/informant.rs index 25ec5ca8b..5f2818f31 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -75,7 +75,6 @@ impl Informant { } } - #[cfg_attr(feature="dev", allow(match_bool))] pub fn tick(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService)>) where Message: Send + Sync + Clone + 'static { let elapsed = self.last_tick.unwrapped_read().elapsed(); if elapsed < Duration::from_secs(5) { diff --git a/parity/main.rs b/parity/main.rs index c36345034..0cf7dd67c 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -20,6 +20,7 @@ #![cfg_attr(feature="dev", feature(plugin))] #![cfg_attr(feature="dev", plugin(clippy))] #![cfg_attr(feature="dev", allow(useless_format))] +#![cfg_attr(feature="dev", allow(match_bool))] extern crate docopt; extern crate num_cpus; diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 017e0ad32..c12783c1b 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -21,7 +21,6 @@ use std::sync::{Arc, Weak, Mutex}; use std::collections::HashSet; use jsonrpc_core::*; use util::Lockable; -use util::numbers::*; use ethcore::miner::MinerService; use ethcore::filter::Filter as EthcoreFilter; use ethcore::client::{BlockChainClient, BlockID}; diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 9e0067c8c..112624baf 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -18,7 +18,7 @@ use std::str::FromStr; use std::collections::HashMap; use std::sync::{Arc, RwLock}; use jsonrpc_core::IoHandler; -use util::{Lockable, RwLockable}; +use util::RwLockable; use util::hash::{Address, H256, FixedHash}; use util::numbers::{Uint, U256}; use ethcore::account_provider::AccountProvider; diff --git a/util/src/migration/mod.rs b/util/src/migration/mod.rs index 4a51893c0..fddb51fca 100644 --- a/util/src/migration/mod.rs +++ b/util/src/migration/mod.rs @@ -92,7 +92,7 @@ impl Migration for T { } } - if batch.len() != 0 { + if !batch.is_empty() { try!(commit_batch(dest, &batch)); } @@ -189,12 +189,12 @@ impl Manager { // start with the old db. 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 { // open the target temporary database. temp_path = temp_idx.path(&db_root); 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. try!(migration.migrate(&cur_db, &self.config, &mut new_db)); diff --git a/util/src/nibblevec.rs b/util/src/nibblevec.rs index dac022929..15bd60cb0 100644 --- a/util/src/nibblevec.rs +++ b/util/src/nibblevec.rs @@ -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 . + + //! An owning, nibble-oriented byte vector. use ::NibbleSlice; -#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] -/// Owning, nibble-oriented byte vector. Counterpart to NibbleSlice. +#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Debug)] +/// Owning, nibble-oriented byte vector. Counterpart to `NibbleSlice`. pub struct NibbleVec { inner: Vec, len: usize, } impl NibbleVec { - /// Make a new NibbleVec + /// Make a new `NibbleVec` pub fn new() -> Self { NibbleVec { 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 { NibbleVec { 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 } - /// 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 } /// 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) { let nibble = nibble & 0x0F; @@ -54,9 +74,9 @@ impl NibbleVec { 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 { - if self.len == 0 { + if self.is_empty() { return None; } @@ -72,7 +92,7 @@ impl NibbleVec { 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 { if self.len % 2 == 0 { Some(NibbleSlice::new(self.inner())) @@ -127,4 +147,4 @@ mod tests { let v2: NibbleVec = v.as_nibbleslice().unwrap().into(); assert_eq!(v, v2); } -} \ No newline at end of file +}