From 2a70cd3998a5e2f7da93cab4736fdb031577f015 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Sat, 19 May 2018 16:55:33 +0200 Subject: [PATCH] Update Rust, Clippy, Rustfmt. Clippy 0.0.202 fixes a bug that prevented using it here. https://github.com/rust-lang-nursery/rust-clippy/issues/2594 --- .travis.yml | 6 +++--- ci/script.sh | 4 +++- src/main.rs | 38 ++++++++++++++++++++++---------------- src/stats.rs | 6 ++++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6eb9dae..9fd8c0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ dist: trusty language: rust services: docker sudo: required -rust: nightly-2018-04-19 +rust: nightly-2018-05-19 cache: cargo env: @@ -24,7 +24,7 @@ before_install: - set -e - rustup self update - rustup component add rustfmt-preview - # - cargo install clippy -f --vers=0.0.195 + - cargo install clippy -f --vers=0.0.202 install: - sh ci/install.sh @@ -44,7 +44,7 @@ deploy: file_glob: true file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* on: - condition: $TRAVIS_RUST_VERSION = nightly-2018-04-19 + condition: $TRAVIS_RUST_VERSION = nightly-2018-05-19 tags: true provider: releases skip_cleanup: true diff --git a/ci/script.sh b/ci/script.sh index d56a9cf..8a1b892 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -1,7 +1,7 @@ set -ex main() { - cargo fmt -- --write-mode=diff + cargo fmt -- --check cross build --target $TARGET cross build --target $TARGET --release @@ -14,6 +14,8 @@ main() { cross test --target $TARGET --release cross build --target $TARGET --release + + cross clippy --tests --all-features -- -D clippy } # we don't run the "test phase" when doing deploys diff --git a/src/main.rs b/src/main.rs index affaca0..a5a5f53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,22 +31,28 @@ use web3::futures::Future; /// The maximum age in seconds of the latest block. const MAX_BLOCK_AGE: u64 = 60 * 60; -use_contract!( - net_con, - "NetworkConsensus", - "abi/PoaNetworkConsensus.abi.json" -); -use_contract!( - voting, - "VotingToChangeKeys", - "abi/VotingToChangeKeys.abi.json" -); -use_contract!( - val_meta, - "ValidatorMetadata", - "abi/ValidatorMetadata.abi.json" -); -use_contract!(key_mgr, "KeysManager", "abi/KeysManager.abi.json"); +// The `use_contract!` macro triggers several Clippy warnings. +#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, redundant_closure, needless_update))] +mod contracts { + use_contract!( + net_con, + "NetworkConsensus", + "abi/PoaNetworkConsensus.abi.json" + ); + use_contract!( + voting, + "VotingToChangeKeys", + "abi/VotingToChangeKeys.abi.json" + ); + use_contract!( + val_meta, + "ValidatorMetadata", + "abi/ValidatorMetadata.abi.json" + ); + use_contract!(key_mgr, "KeysManager", "abi/KeysManager.abi.json"); +} + +use contracts::*; #[derive(Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] diff --git a/src/stats.rs b/src/stats.rs index 882098e..1b5a25f 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -29,7 +29,8 @@ impl Stats { /// `votes` are the ones that were actually cast. pub fn add_ballot(&mut self, voters: &[Address], votes: &[voting::logs::Vote]) { for voter in voters { - let mut vs = self.voter_stats + let mut vs = self + .voter_stats .entry(voter.clone()) .or_insert_with(VoterStats::default); vs.ballots += 1; @@ -59,7 +60,8 @@ impl Stats { impl Display for Stats { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let mut lines: Vec = self.voter_stats + let mut lines: Vec = self + .voter_stats .iter() .map(|(addr, s)| DisplayLine { votes_per_thousand: s.voted * 1000 / s.ballots,