Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the newly available stable clippy. Fix lints. #124

Merged
merged 2 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ 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
```

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
```

Expand Down
1 change: 1 addition & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion benches/suites/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion benches/suites/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion benches/suites/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn quick_raw_node() -> RawNode<MemStorage> {
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);
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
2 changes: 1 addition & 1 deletion src/eraftpb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,7 @@ impl<T: Storage> Raft<T> {
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<Vec<u8>>) {
let self_id = self.id;
let mut prs = self.take_prs();
Expand Down
2 changes: 1 addition & 1 deletion src/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ impl<T: Storage> RawNode<T> {
}

/// 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<u8>, cc: ConfChange) -> Result<()> {
let data = protobuf::Message::write_to_bytes(&cc)?;
let mut m = Message::new();
Expand Down
8 changes: 4 additions & 4 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]),
),
];
Expand Down
22 changes: 11 additions & 11 deletions tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -110,12 +110,12 @@ fn new_raft_log(ents: &[Entry], offset: u64, committed: u64) -> RaftLog<MemStora
let store = MemStorage::new();
store.wl().append(ents).expect("");
RaftLog {
store: store,
store,
unstable: Unstable {
offset: offset,
offset,
..Default::default()
},
committed: committed,
committed,
..Default::default()
}
}
Expand Down Expand Up @@ -263,8 +263,8 @@ fn test_progress_is_paused() {
];
for (i, &(state, paused, w)) in tests.iter().enumerate() {
let p = Progress {
state: state,
paused: paused,
state,
paused,
ins: Inflights::new(256),
..Default::default()
};
Expand Down Expand Up @@ -581,7 +581,7 @@ fn test_vote_from_any_state_for_type(vt: MessageType) {
msg.set_log_term(new_term);
msg.set_index(42);
r.step(msg)
.expect(&format!("{:?},{:?}: step failed", vt, state));
.unwrap_or_else(|_| panic!("{:?},{:?}: step failed", vt, state));
assert_eq!(
r.msgs.len(),
1,
Expand Down Expand Up @@ -1177,7 +1177,7 @@ fn test_pass_election_timeout() {
if round {
got = (got * 10.0 + 0.5).floor() / 10.0;
}
if (got - wprobability).abs() > 0.000001 {
if (got - wprobability).abs() > 0.000_001 {
panic!("#{}: probability = {}, want {}", i, got, wprobability);
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_cases/test_raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use test_util::*;

fn new_peer(id: u64) -> Peer {
Peer {
id: id,
id,
..Default::default()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down
18 changes: 12 additions & 6 deletions tests/test_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ pub fn new_storage() -> MemStorage {
MemStorage::new()
}

pub fn new_test_config(id: u64, peers: Vec<u64>, election: usize, heartbeat: usize) -> Config {
pub fn new_test_config(
id: u64,
peers: Vec<u64>,
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()
Expand Down Expand Up @@ -224,6 +229,7 @@ struct Connem {
to: u64,
}

#[allow(declare_interior_mutable_const)]
pub const NOP_STEPPER: Option<Interface> = Some(Interface { raft: None });

#[derive(Default)]
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down