Skip to content

Commit d13ea5c

Browse files
authored
Enable Clippy and rustfmt checks in CI (#85)
1 parent 5cf099a commit d13ea5c

4 files changed

Lines changed: 89 additions & 43 deletions

File tree

.github/workflows/rust.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v2
23-
- uses: actions-rs/toolchain@v1
23+
- uses: dtolnay/rust-toolchain@stable
2424
with:
2525
profile: minimal
2626
toolchain: ${{ matrix.rust }}
@@ -31,3 +31,43 @@ jobs:
3131
cargo build --verbose --features "$FEATURES" &&
3232
cargo test --verbose --features "$FEATURES" &&
3333
cargo test --verbose --release --features "$FEATURES"
34+
35+
clippy:
36+
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
# Run Clippy only on stable
41+
rust: [stable]
42+
43+
steps:
44+
- uses: actions/checkout@v2
45+
- uses: dtolnay/rust-toolchain@stable
46+
with:
47+
profile: minimal
48+
toolchain: ${{ matrix.rust }}
49+
components: clippy
50+
override: true
51+
- name: Run Clippy
52+
run: |
53+
cargo clippy
54+
55+
formatting:
56+
57+
runs-on: ubuntu-latest
58+
strategy:
59+
matrix:
60+
# Run formatting checks only on stable
61+
rust: [stable]
62+
63+
steps:
64+
- uses: actions/checkout@v2
65+
- uses: dtolnay/rust-toolchain@stable
66+
with:
67+
profile: minimal
68+
toolchain: ${{ matrix.rust }}
69+
components: rustfmt
70+
override: true
71+
- name: Run Clippy
72+
run: |
73+
cargo fmt --all --check

benches/benches.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#![feature(test)]
22

3-
extern crate test;
43
extern crate fixedbitset;
5-
use test::Bencher;
6-
use fixedbitset::{FixedBitSet, Block};
4+
extern crate test;
5+
use fixedbitset::{Block, FixedBitSet};
76
use std::mem::size_of;
7+
use test::Bencher;
88

99
#[inline]
1010
fn iter_ones_using_contains<F: FnMut(usize)>(fb: &FixedBitSet, f: &mut F) {
11-
for bit in 0 .. fb.len() {
12-
if fb.contains(bit) {
13-
f(bit);
14-
}
11+
for bit in 0..fb.len() {
12+
if fb.contains(bit) {
13+
f(bit);
14+
}
1515
}
1616
}
1717

@@ -62,9 +62,9 @@ fn bench_iter_ones_using_slice_directly_all_zero(b: &mut Bencher) {
6262
let fb = FixedBitSet::with_capacity(N);
6363

6464
b.iter(|| {
65-
let mut count = 0;
66-
iter_ones_using_slice_directly(&fb, &mut |_bit| count += 1);
67-
count
65+
let mut count = 0;
66+
iter_ones_using_slice_directly(&fb, &mut |_bit| count += 1);
67+
count
6868
});
6969
}
7070

@@ -75,9 +75,9 @@ fn bench_iter_ones_using_slice_directly_all_ones(b: &mut Bencher) {
7575
fb.insert_range(..);
7676

7777
b.iter(|| {
78-
let mut count = 0;
79-
iter_ones_using_slice_directly(&fb, &mut |_bit| count += 1);
80-
count
78+
let mut count = 0;
79+
iter_ones_using_slice_directly(&fb, &mut |_bit| count += 1);
80+
count
8181
});
8282
}
8383

@@ -115,9 +115,7 @@ fn bench_insert_range(b: &mut Bencher) {
115115
const N: usize = 1_000_000;
116116
let mut fb = FixedBitSet::with_capacity(N);
117117

118-
b.iter(|| {
119-
fb.insert_range(..)
120-
});
118+
b.iter(|| fb.insert_range(..));
121119
}
122120

123121
#[bench]

src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ impl<'a> Iterator for Difference<'a> {
531531
type Item = usize;
532532

533533
#[inline]
534+
#[allow(clippy::manual_find)]
534535
fn next(&mut self) -> Option<Self::Item> {
535-
while let Some(nxt) = self.iter.next() {
536+
for nxt in self.iter.by_ref() {
536537
if !self.other.contains(nxt) {
537538
return Some(nxt);
538539
}
@@ -569,8 +570,9 @@ impl<'a> Iterator for Intersection<'a> {
569570
type Item = usize; // the bit position of the '1'
570571

571572
#[inline]
573+
#[allow(clippy::manual_find)]
572574
fn next(&mut self) -> Option<Self::Item> {
573-
while let Some(nxt) = self.iter.next() {
575+
for nxt in self.iter.by_ref() {
574576
if self.other.contains(nxt) {
575577
return Some(nxt);
576578
}
@@ -619,9 +621,9 @@ impl Masks {
619621
let (last_block, last_rem) = div_rem(end);
620622

621623
Masks {
622-
first_block: first_block as usize,
624+
first_block,
623625
first_mask: Block::max_value() << first_rem,
624-
last_block: last_block as usize,
626+
last_block,
625627
last_mask: (Block::max_value() >> 1) >> (BITS - last_rem - 1),
626628
// this is equivalent to `MAX >> (BITS - x)` with correct semantics when x == 0.
627629
}
@@ -669,7 +671,7 @@ impl<'a> Iterator for Ones<'a> {
669671
#[inline]
670672
fn next(&mut self) -> Option<Self::Item> {
671673
while self.bitset == 0 {
672-
self.bitset = *self.remaining_blocks.next()?;
674+
self.bitset = *self.remaining_blocks.next()?;
673675
self.block_idx += BITS;
674676
}
675677
let t = self.bitset & (0 as Block).wrapping_sub(self.bitset);
@@ -749,13 +751,13 @@ impl<'a> BitAnd for &'a FixedBitSet {
749751
}
750752
}
751753

752-
impl<'a> BitAndAssign for FixedBitSet {
754+
impl BitAndAssign for FixedBitSet {
753755
fn bitand_assign(&mut self, other: Self) {
754756
self.intersect_with(&other);
755757
}
756758
}
757759

758-
impl<'a> BitAndAssign<&Self> for FixedBitSet {
760+
impl BitAndAssign<&Self> for FixedBitSet {
759761
fn bitand_assign(&mut self, other: &Self) {
760762
self.intersect_with(other);
761763
}
@@ -780,13 +782,13 @@ impl<'a> BitOr for &'a FixedBitSet {
780782
}
781783
}
782784

783-
impl<'a> BitOrAssign for FixedBitSet {
785+
impl BitOrAssign for FixedBitSet {
784786
fn bitor_assign(&mut self, other: Self) {
785787
self.union_with(&other);
786788
}
787789
}
788790

789-
impl<'a> BitOrAssign<&Self> for FixedBitSet {
791+
impl BitOrAssign<&Self> for FixedBitSet {
790792
fn bitor_assign(&mut self, other: &Self) {
791793
self.union_with(other);
792794
}
@@ -811,13 +813,13 @@ impl<'a> BitXor for &'a FixedBitSet {
811813
}
812814
}
813815

814-
impl<'a> BitXorAssign for FixedBitSet {
816+
impl BitXorAssign for FixedBitSet {
815817
fn bitxor_assign(&mut self, other: Self) {
816818
self.symmetric_difference_with(&other);
817819
}
818820
}
819821

820-
impl<'a> BitXorAssign<&Self> for FixedBitSet {
822+
impl BitXorAssign<&Self> for FixedBitSet {
821823
fn bitxor_assign(&mut self, other: &Self) {
822824
self.symmetric_difference_with(other);
823825
}
@@ -1671,4 +1673,4 @@ fn test_is_clear() {
16711673
fb.put(17);
16721674
fb.put(19);
16731675
assert!(!fb.is_clear());
1674-
}
1676+
}

src/range.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
1-
use std::ops::{
2-
RangeFull,
3-
RangeFrom,
4-
RangeTo,
5-
Range,
6-
};
1+
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
72

83
// Taken from https://github.com/bluss/odds/blob/master/src/range.rs.
94

105
/// **IndexRange** is implemented by Rust's built-in range types, produced
116
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
12-
pub trait IndexRange<T=usize> {
7+
pub trait IndexRange<T = usize> {
138
#[inline]
149
/// Start index (inclusive)
15-
fn start(&self) -> Option<T> { None }
10+
fn start(&self) -> Option<T> {
11+
None
12+
}
1613
#[inline]
1714
/// End index (exclusive)
18-
fn end(&self) -> Option<T> { None }
15+
fn end(&self) -> Option<T> {
16+
None
17+
}
1918
}
2019

21-
2220
impl<T> IndexRange<T> for RangeFull {}
2321

2422
impl<T: Copy> IndexRange<T> for RangeFrom<T> {
2523
#[inline]
26-
fn start(&self) -> Option<T> { Some(self.start) }
24+
fn start(&self) -> Option<T> {
25+
Some(self.start)
26+
}
2727
}
2828

2929
impl<T: Copy> IndexRange<T> for RangeTo<T> {
3030
#[inline]
31-
fn end(&self) -> Option<T> { Some(self.end) }
31+
fn end(&self) -> Option<T> {
32+
Some(self.end)
33+
}
3234
}
3335

3436
impl<T: Copy> IndexRange<T> for Range<T> {
3537
#[inline]
36-
fn start(&self) -> Option<T> { Some(self.start) }
38+
fn start(&self) -> Option<T> {
39+
Some(self.start)
40+
}
3741
#[inline]
38-
fn end(&self) -> Option<T> { Some(self.end) }
42+
fn end(&self) -> Option<T> {
43+
Some(self.end)
44+
}
3945
}

0 commit comments

Comments
 (0)