From 3450c8a9f1be60dc6fd98a7e0d9d9cb5c296d6d3 Mon Sep 17 00:00:00 2001 From: Hoverbear Date: Tue, 18 Sep 2018 11:11:38 -0700 Subject: [PATCH] Use the newly available stable clippy. Fix lints. --- .travis.yml | 10 +++++----- README.md | 6 ++---- benches/benches.rs | 1 + benches/suites/progress.rs | 2 +- benches/suites/raft.rs | 2 +- benches/suites/raw_node.rs | 2 +- rust-toolchain | 1 + src/eraftpb.rs | 2 +- src/errors.rs | 4 ++-- src/lib.rs | 1 - src/progress.rs | 2 +- src/raft.rs | 5 +---- src/raft_log.rs | 2 +- src/raw_node.rs | 5 +---- src/storage.rs | 8 ++++---- tests/integration_cases/test_raft.rs | 22 +++++++++++----------- tests/integration_cases/test_raw_node.rs | 10 +++++----- tests/test_util/mod.rs | 18 ++++++++++++------ tests/tests.rs | 1 - 19 files changed, 51 insertions(+), 53 deletions(-) create mode 100644 rust-toolchain diff --git a/.travis.yml b/.travis.yml index 5af91827f..3d41529da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,17 +10,17 @@ rust: matrix: include: - # This build uses stable and checks rustfmt (clippy is not on stable). + # This build uses stable and checks rustfmt and clippy. + # We don't check them on nightly since their lints and formatting may differ. - rust: stable install: - rustup component add rustfmt-preview + - rustup component add clippy-preview before_script: - cargo fmt --all -- --check + - cargo clippy --all -- -D clippy + # Since many users will use nightlies, also test that. - rust: nightly - install: - - rustup component add clippy-preview --toolchain nightly - before_script: - - cargo clippy --all -- -D clippy::all script: diff --git a/README.md b/README.md index fdd594b55..d081aca4b 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,7 @@ A complete Raft model contains 4 essential parts: Using `rustup` you can get started this way: ```bash -rustup override set stable -rustup toolchain install nightly -rustup component add clippy-review --nightly +rustup component add clippy-preview rustup component add rustfmt-preview ``` @@ -46,7 +44,7 @@ In order to have your PR merged running the following must finish without error: ```bash cargo test --all && \ -cargo +nightly clippy --all && \ +cargo clippy --all -- -D clippy && \ cargo fmt --all -- --check ``` diff --git a/benches/benches.rs b/benches/benches.rs index 6b034e269..b4c518d0b 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] // Due to criterion we need this to avoid warnings. +#![cfg_attr(feature = "cargo-clippy", allow(let_and_return))] // Benches often artificially return values. Allow it. extern crate criterion; extern crate env_logger; diff --git a/benches/suites/progress.rs b/benches/suites/progress.rs index 8de69e6c2..b9c2e9a8f 100644 --- a/benches/suites/progress.rs +++ b/benches/suites/progress.rs @@ -8,7 +8,7 @@ pub fn bench_progress(c: &mut Criterion) { pub fn bench_progress_default(c: &mut Criterion) { let bench = |b: &mut Bencher| { // No setup. - b.iter(|| Progress::default()); + b.iter(Progress::default); }; c.bench_function("Progress::default", bench); diff --git a/benches/suites/raft.rs b/benches/suites/raft.rs index 30d7213b9..ce92361c4 100644 --- a/benches/suites/raft.rs +++ b/benches/suites/raft.rs @@ -59,7 +59,7 @@ pub fn bench_raft_campaign(c: &mut Criterion) { "CampaignTransfer", ]; // Skip the first since it's 0,0 - for msg in msgs.iter() { + for msg in &msgs { c.bench_function( &format!("Raft::campaign ({}, {}, {})", voters, learners, msg), bench(*voters, *learners, msg.as_bytes()), diff --git a/benches/suites/raw_node.rs b/benches/suites/raw_node.rs index 3760463d3..b657d208f 100644 --- a/benches/suites/raw_node.rs +++ b/benches/suites/raw_node.rs @@ -17,7 +17,7 @@ fn quick_raw_node() -> RawNode { pub fn bench_raw_node_new(c: &mut Criterion) { let bench = |b: &mut Bencher| { // No setup. - b.iter(|| quick_raw_node()); + b.iter(quick_raw_node); }; c.bench_function("RawNode::new", bench); diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 000000000..870bbe4e5 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +stable \ No newline at end of file diff --git a/src/eraftpb.rs b/src/eraftpb.rs index 18bae7dfa..f65846554 100644 --- a/src/eraftpb.rs +++ b/src/eraftpb.rs @@ -3,7 +3,7 @@ // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![cfg_attr(feature = "cargo-clippy", allow(clippy::all))] +#![cfg_attr(feature = "cargo-clippy", allow(clippy))] #![cfg_attr(rustfmt, rustfmt_skip)] diff --git a/src/errors.rs b/src/errors.rs index 4a7ea6f1f..2ad61aecd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -67,7 +67,7 @@ quick_error! { } impl cmp::PartialEq for Error { - #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] + #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] fn eq(&self, other: &Error) -> bool { match (self, other) { (&Error::StepPeerNotFound, &Error::StepPeerNotFound) => true, @@ -112,7 +112,7 @@ quick_error! { } impl cmp::PartialEq for StorageError { - #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] + #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] fn eq(&self, other: &StorageError) -> bool { match (self, other) { (&StorageError::Compacted, &StorageError::Compacted) => true, diff --git a/src/lib.rs b/src/lib.rs index 4c99d8603..21d4446c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -261,7 +261,6 @@ For more information, check out an [example](examples/single_mem_node/main.rs#L1 */ #![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] -#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))] #![deny(missing_docs)] #[cfg(feature = "failpoint")] diff --git a/src/progress.rs b/src/progress.rs index d2a87c2d5..18b8bf4f4 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -452,7 +452,7 @@ mod test { buffer: Vec::with_capacity(10), ..Default::default() }; - inflight2.buffer.extend_from_slice(&vec![0, 0, 0, 0, 0]); + inflight2.buffer.extend_from_slice(&[0, 0, 0, 0, 0]); for i in 0..5 { inflight2.add(i); diff --git a/src/raft.rs b/src/raft.rs index 6413455b9..b6cf67216 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -572,10 +572,7 @@ impl Raft { self.bcast_heartbeat_with_ctx(ctx) } - #[cfg_attr( - feature = "cargo-clippy", - allow(clippy::needless_pass_by_value) - )] + #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] fn bcast_heartbeat_with_ctx(&mut self, ctx: Option>) { let self_id = self.id; let mut prs = self.take_prs(); diff --git a/src/raft_log.rs b/src/raft_log.rs index 83d7f1c80..facc04977 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -955,7 +955,7 @@ mod test { let (offset, num) = (100u64, 100u64); let (last, half) = (offset + num, offset + num / 2); let halfe = new_entry(half, half); - let halfe_size = protobuf::Message::compute_size(&halfe) as u64; + let halfe_size = u64::from(protobuf::Message::compute_size(&halfe)); let store = MemStorage::new(); store diff --git a/src/raw_node.rs b/src/raw_node.rs index 43524a430..7e62a0b11 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -286,10 +286,7 @@ impl RawNode { } /// ProposeConfChange proposes a config change. - #[cfg_attr( - feature = "cargo-clippy", - allow(clippy::needless_pass_by_value) - )] + #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { let data = protobuf::Message::write_to_bytes(&cc)?; let mut m = Message::new(); diff --git a/src/storage.rs b/src/storage.rs index d51565c8f..4e8a10761 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -409,26 +409,26 @@ mod test { ( 4, 7, - (size_of(&ents[1]) + size_of(&ents[2])) as u64, + u64::from(size_of(&ents[1]) + size_of(&ents[2])), Ok(vec![new_entry(4, 4), new_entry(5, 5)]), ), ( 4, 7, - (size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3]) / 2) as u64, + u64::from(size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3]) / 2), Ok(vec![new_entry(4, 4), new_entry(5, 5)]), ), ( 4, 7, - (size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3]) - 1) as u64, + u64::from(size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3]) - 1), Ok(vec![new_entry(4, 4), new_entry(5, 5)]), ), // all ( 4, 7, - (size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3])) as u64, + u64::from(size_of(&ents[1]) + size_of(&ents[2]) + size_of(&ents[3])), Ok(vec![new_entry(4, 4), new_entry(5, 5), new_entry(6, 6)]), ), ]; diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index 1365eeade..591e09130 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -45,10 +45,10 @@ fn new_progress( ins_size: usize, ) -> Progress { Progress { - state: state, - matched: matched, - next_idx: next_idx, - pending_snapshot: pending_snapshot, + state, + matched, + next_idx, + pending_snapshot, ins: Inflights::new(ins_size), ..Default::default() } @@ -110,12 +110,12 @@ fn new_raft_log(ents: &[Entry], offset: u64, committed: u64) -> RaftLog 0.000001 { + if (got - wprobability).abs() > 0.000_001 { panic!("#{}: probability = {}, want {}", i, got, wprobability); } } diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index f74b98507..cd60c8301 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -33,7 +33,7 @@ use test_util::*; fn new_peer(id: u64) -> Peer { Peer { - id: id, + id, ..Default::default() } } @@ -64,11 +64,11 @@ fn new_ready( must_sync: bool, ) -> Ready { Ready { - ss: ss, - hs: hs, - entries: entries, + ss, + hs, + entries, committed_entries: Some(committed_entries), - must_sync: must_sync, + must_sync, ..Default::default() } } diff --git a/tests/test_util/mod.rs b/tests/test_util/mod.rs index d9b433f74..7fc04a3ad 100644 --- a/tests/test_util/mod.rs +++ b/tests/test_util/mod.rs @@ -52,12 +52,17 @@ pub fn new_storage() -> MemStorage { MemStorage::new() } -pub fn new_test_config(id: u64, peers: Vec, election: usize, heartbeat: usize) -> Config { +pub fn new_test_config( + id: u64, + peers: Vec, + election_tick: usize, + heartbeat_tick: usize, +) -> Config { Config { - id: id, - peers: peers, - election_tick: election, - heartbeat_tick: heartbeat, + id, + peers, + election_tick, + heartbeat_tick, max_size_per_msg: NO_LIMIT, max_inflight_msgs: 256, ..Default::default() @@ -224,6 +229,7 @@ struct Connem { to: u64, } +#[allow(declare_interior_mutable_const)] pub const NOP_STEPPER: Option = Some(Interface { raft: None }); #[derive(Default)] @@ -322,7 +328,7 @@ impl Network { } pub fn drop(&mut self, from: u64, to: u64, perc: f64) { - self.dropm.insert(Connem { from: from, to: to }, perc); + self.dropm.insert(Connem { from, to }, perc); } pub fn cut(&mut self, one: u64, other: u64) { diff --git a/tests/tests.rs b/tests/tests.rs index 269942437..d19c5d013 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -12,7 +12,6 @@ // limitations under the License. #![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] -#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))] #![cfg_attr(feature = "failpoint", allow(dead_code, unused_imports))] #[macro_use]