Skip to content

Commit 03d6df9

Browse files
Seulgi Kimsgkim126
authored andcommitted
Upgrade clippy and fmt
This patch 1. removes redundant closures 2. removes an unreachable pattern 3. renames clippy::cognitive_complexity to clippy::cyclomatic_complexity 4. allows deprecated item(std::error::Error::cause) * Allow it until error-chain and quick-error macros are fixed. 5. removes a redundant import 6. makes clippy skip false alarms
1 parent 0f128d4 commit 03d6df9

File tree

29 files changed

+148
-108
lines changed

29 files changed

+148
-108
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ jobs:
5858
- SKIP=`.travis/check-change '^test/'` && if [[ "$SKIP" = "noskip" ]]; then CHECK_RUST=1; fi
5959
install:
6060
- if [[ $CHECK_RUST ]]; then
61-
rustup toolchain install nightly-2018-12-06 || exit 1;
62-
rustup component add rustfmt-preview --toolchain nightly-2018-12-06 || exit 1;
63-
rustup component add clippy-preview --toolchain nightly-2018-12-06 || exit 1;
61+
rustup toolchain install nightly-2019-04-11 || exit 1;
62+
rustup component add rustfmt-preview --toolchain nightly-2019-04-11 || exit 1;
63+
rustup component add clippy-preview --toolchain nightly-2019-04-11 || exit 1;
6464
fi
6565
- nvm install 10
6666
- nvm use 10
6767
- npm install -g yarn
6868
script:
6969
- if [[ $CHECK_RUST ]]; then
70-
cargo +nightly-2018-12-06 fmt -- --check || FAILED=1;
71-
cargo +nightly-2018-12-06 clippy --all --all-targets -- -D warnings || FAILED=1;
70+
cargo +nightly-2019-04-11 fmt -- --check || FAILED=1;
71+
cargo +nightly-2019-04-11 clippy --all --all-targets -- -D warnings || FAILED=1;
7272
fi; test ! $FAILED
7373
- cd test && yarn && yarn lint
7474
- stage: deploy

codechain/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Config {
5858

5959
pub fn miner_options(&self) -> Result<MinerOptions, String> {
6060
let (reseal_on_own_transaction, reseal_on_external_transaction) =
61-
match self.mining.reseal_on_txs.as_ref().map(|s| s.as_str()) {
61+
match self.mining.reseal_on_txs.as_ref().map(String::as_str) {
6262
Some("all") => (true, true),
6363
Some("own") => (true, false),
6464
Some("ext") => (false, true),

codechain/run_node.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use ccore::{
2525
Miner, MinerService, Scheme, Stratum, StratumConfig, StratumError, NUM_COLUMNS,
2626
};
2727
use cdiscovery::{Config, Discovery};
28-
use ckey::{Address, NetworkId};
28+
use ckey::{Address, NetworkId, PlatformAddress};
2929
use ckeystore::accounts_dir::RootDiskDirectory;
3030
use ckeystore::KeyStore;
3131
use clap::ArgMatches;
@@ -81,7 +81,7 @@ fn discovery_start(
8181
bucket_size: cfg.discovery_bucket_size.unwrap(),
8282
t_refresh: cfg.discovery_refresh.unwrap(),
8383
};
84-
let use_kademlia = match cfg.discovery_type.as_ref().map(|s| s.as_str()) {
84+
let use_kademlia = match cfg.discovery_type.as_ref().map(String::as_str) {
8585
Some("unstructured") => false,
8686
Some("kademlia") => true,
8787
Some(discovery_type) => return Err(format!("Unknown discovery {}", discovery_type)),
@@ -154,7 +154,7 @@ fn new_miner(
154154
}
155155
},
156156
EngineType::Solo => miner
157-
.set_author(config.mining.author.map_or(Address::default(), |a| a.into_address()))
157+
.set_author(config.mining.author.map_or(Address::default(), PlatformAddress::into_address))
158158
.expect("set_author never fails when Solo is used"),
159159
}
160160
}
@@ -203,7 +203,7 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
203203
}
204204

205205
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<KeyValueDB>, String> {
206-
let db_path = cfg.db_path.as_ref().map(|s| s.as_str()).unwrap();
206+
let db_path = cfg.db_path.as_ref().map(String::as_str).unwrap();
207207
let client_path = Path::new(db_path);
208208
let mut db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
209209

core/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'x> OpenBlock<'x> {
244244
})?;
245245
self.block.header.set_transactions_root(skewed_merkle_root(
246246
parent_transactions_root,
247-
self.block.transactions.iter().map(|e| e.rlp_bytes()),
247+
self.block.transactions.iter().map(Encodable::rlp_bytes),
248248
));
249249
self.block.header.set_state_root(state_root);
250250

core/src/blockchain/blockchain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ impl BlockChain {
391391
#[allow(dead_code)]
392392
pub fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition> {
393393
// slow path: loop back block by block
394+
#[allow(clippy::identity_conversion)]
395+
// This is a false alarm. https://github.com/rust-lang/rust-clippy/issues/3944
394396
for hash in self.ancestry_iter(parent_hash)? {
395397
let details = self.block_details(&hash)?;
396398

core/src/client/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Client {
199199
self.queue_transactions.fetch_sub(transactions.len(), AtomicOrdering::SeqCst);
200200
let transactions: Vec<UnverifiedTransaction> =
201201
transactions.iter().filter_map(|bytes| UntrustedRlp::new(bytes).as_val().ok()).collect();
202-
let hashes: Vec<_> = transactions.iter().map(|tx| tx.hash()).collect();
202+
let hashes: Vec<_> = transactions.iter().map(UnverifiedTransaction::hash).collect();
203203
self.notify(|notify| {
204204
notify.transactions_received(hashes.clone(), peer_id);
205205
});

core/src/consensus/tendermint/worker.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl Worker {
417417

418418
proposal.and_then(|proposal| {
419419
let block_hash = proposal.on.block_hash.expect("Proposal message always include block hash");
420-
let bytes = self.client().block(&BlockId::Hash(block_hash)).map(|block| block.into_inner());
420+
let bytes = self.client().block(&BlockId::Hash(block_hash)).map(encoded::Block::into_inner);
421421
bytes.map(|bytes| (proposal.signature, proposal.signer_index, bytes))
422422
})
423423
}
@@ -1093,6 +1093,8 @@ impl Worker {
10931093
let precommit_hash = message_hash(step, *header.parent_hash());
10941094
let mut counter = 0;
10951095

1096+
#[allow(clippy::identity_conversion)]
1097+
// This is a false alarm. https://github.com/rust-lang/rust-clippy/issues/3944
10961098
for (bitset_index, signature) in seal_view.signatures()? {
10971099
let public = self.validators.get(header.parent_hash(), bitset_index);
10981100
if !verify_schnorr(&public, &signature, &precommit_hash)? {

core/src/miner/miner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use kvdb::KeyValueDB;
3131
use parking_lot::{Mutex, RwLock};
3232
use primitives::{Bytes, H256};
3333

34-
use super::mem_pool::MemPool;
34+
use super::mem_pool::{Error as MemPoolError, MemPool};
3535
use super::mem_pool_types::{AccountDetails, MemPoolInput, TxOrigin, TxTimelock};
3636
use super::sealing_queue::SealingQueue;
3737
use super::work_notify::{NotifyWork, WorkPoster};
@@ -203,7 +203,7 @@ impl Miner {
203203

204204
/// Get `Some` `clone()` of the current pending block or `None` if we're not sealing.
205205
pub fn pending_block(&self, latest_block_number: BlockNumber) -> Option<Block> {
206-
self.map_pending_block(|b| b.to_base(), latest_block_number)
206+
self.map_pending_block(IsBlock::to_base, latest_block_number)
207207
}
208208

209209
/// Get `Some` `clone()` of the current pending block header or `None` if we're not sealing.
@@ -328,7 +328,7 @@ impl Miner {
328328
Err(e) => Err(e),
329329
Ok(()) => {
330330
let idx = insertion_results_index;
331-
let result = insertion_results[idx].clone().map_err(|x| x.into_core_error())?;
331+
let result = insertion_results[idx].clone().map_err(MemPoolError::into_core_error)?;
332332
inserted.push(tx_hashes[idx]);
333333
insertion_results_index += 1;
334334
Ok(result)

crypto/src/error.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use rcrypto;
18-
use ring;
19-
2017
quick_error! {
2118
#[derive(Debug)]
2219
pub enum Error {
@@ -48,32 +45,39 @@ quick_error! {
4845
}
4946
}
5047

51-
quick_error! {
52-
#[derive(Debug)]
53-
pub enum SymmError wraps PrivSymmErr {
54-
RustCrypto(e: rcrypto::symmetriccipher::SymmetricCipherError) {
55-
display("symmetric crypto error")
56-
from()
57-
}
58-
Ring(e: ring::error::Unspecified) {
59-
display("symmetric crypto error")
60-
cause(e)
61-
from()
62-
}
63-
Offset(x: usize) {
64-
display("offset {} greater than slice length", x)
48+
#[allow(deprecated)]
49+
mod errors {
50+
use rcrypto;
51+
use ring;
52+
53+
quick_error! {
54+
#[derive(Debug)]
55+
pub enum SymmError wraps PrivSymmErr {
56+
RustCrypto(e: rcrypto::symmetriccipher::SymmetricCipherError) {
57+
display("symmetric crypto error")
58+
from()
59+
}
60+
Ring(e: ring::error::Unspecified) {
61+
display("symmetric crypto error")
62+
cause(e)
63+
from()
64+
}
65+
Offset(x: usize) {
66+
display("offset {} greater than slice length", x)
67+
}
6568
}
6669
}
67-
}
6870

69-
impl From<ring::error::Unspecified> for SymmError {
70-
fn from(e: ring::error::Unspecified) -> SymmError {
71-
SymmError(PrivSymmErr::Ring(e))
71+
impl From<ring::error::Unspecified> for SymmError {
72+
fn from(e: ring::error::Unspecified) -> SymmError {
73+
SymmError(PrivSymmErr::Ring(e))
74+
}
7275
}
73-
}
7476

75-
impl From<rcrypto::symmetriccipher::SymmetricCipherError> for SymmError {
76-
fn from(e: rcrypto::symmetriccipher::SymmetricCipherError) -> SymmError {
77-
SymmError(PrivSymmErr::RustCrypto(e))
77+
impl From<rcrypto::symmetriccipher::SymmetricCipherError> for SymmError {
78+
fn from(e: rcrypto::symmetriccipher::SymmetricCipherError) -> SymmError {
79+
SymmError(PrivSymmErr::RustCrypto(e))
80+
}
7881
}
7982
}
83+
pub use self::errors::SymmError;

discovery/src/extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl NetworkExtension<Never> for Extension {
104104

105105
addresses
106106
.into_iter()
107-
.map(|kademlia_id| kademlia_id.into())
107+
.map(From::from)
108108
.take(::std::cmp::min(self.config.bucket_size, len) as usize)
109109
.collect()
110110
} else {

0 commit comments

Comments
 (0)