Skip to content

Commit

Permalink
Merge #696
Browse files Browse the repository at this point in the history
696: Fix some clippy warnings in tests and examples r=taiki-e a=taiki-e

I feel that some lints are too strict for test code, so this will only fix some warnings which I think are reasonable.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed May 4, 2021
2 parents c093db3 + b6eb76e commit 3e83987
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crossbeam-channel/examples/fibonacci.rs
Expand Up @@ -10,7 +10,7 @@ fn fibonacci(sender: Sender<u64>) {
while sender.send(x).is_ok() {
let tmp = x;
x = y;
y = tmp + y;
y += tmp;
}
}

Expand Down
6 changes: 1 addition & 5 deletions crossbeam-channel/examples/stopwatch.rs
Expand Up @@ -33,11 +33,7 @@ fn main() {

// Prints the elapsed time.
fn show(dur: Duration) {
println!(
"Elapsed: {}.{:03} sec",
dur.as_secs(),
dur.subsec_nanos() / 1_000_000
);
println!("Elapsed: {}.{:03} sec", dur.as_secs(), dur.subsec_millis());
}

let start = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/tests/golang.rs
Expand Up @@ -176,7 +176,7 @@ unsafe impl GlobalAlloc for Counter {
if !ret.is_null() {
ALLOCATED.fetch_add(layout.size(), SeqCst);
}
return ret;
ret
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
Expand Down
14 changes: 7 additions & 7 deletions crossbeam-deque/tests/fifo.rs
Expand Up @@ -167,7 +167,7 @@ fn stress() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand All @@ -178,7 +178,7 @@ fn stress() {
let mut expected = 0;
while expected < COUNT {
if rng.gen_range(0..3) == 0 {
while let Some(_) = w.pop() {
while w.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
} else {
Expand All @@ -188,7 +188,7 @@ fn stress() {
}

while hits.load(SeqCst) < COUNT {
while let Some(_) = w.pop() {
while w.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ fn no_starvation() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand All @@ -239,7 +239,7 @@ fn no_starvation() {
loop {
for i in 0..rng.gen_range(0..COUNT) {
if rng.gen_range(0..3) == 0 && my_hits == 0 {
while let Some(_) = w.pop() {
while w.pop().is_some() {
my_hits += 1;
}
} else {
Expand Down Expand Up @@ -300,7 +300,7 @@ fn destructors() {
remaining.fetch_sub(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
cnt += 1;
remaining.fetch_sub(1, SeqCst);
}
Expand All @@ -309,7 +309,7 @@ fn destructors() {
}

for _ in 0..STEPS {
if let Some(_) = w.pop() {
if w.pop().is_some() {
remaining.fetch_sub(1, SeqCst);
}
}
Expand Down
6 changes: 3 additions & 3 deletions crossbeam-deque/tests/injector.rs
Expand Up @@ -178,7 +178,7 @@ fn stress() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ fn no_starvation() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ fn destructors() {
remaining.fetch_sub(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
cnt += 1;
remaining.fetch_sub(1, SeqCst);
}
Expand Down
14 changes: 7 additions & 7 deletions crossbeam-deque/tests/lifo.rs
Expand Up @@ -167,7 +167,7 @@ fn stress() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand All @@ -178,7 +178,7 @@ fn stress() {
let mut expected = 0;
while expected < COUNT {
if rng.gen_range(0..3) == 0 {
while let Some(_) = w.pop() {
while w.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
} else {
Expand All @@ -188,7 +188,7 @@ fn stress() {
}

while hits.load(SeqCst) < COUNT {
while let Some(_) = w.pop() {
while w.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ fn no_starvation() {
hits.fetch_add(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
hits.fetch_add(1, SeqCst);
}
}
Expand All @@ -239,7 +239,7 @@ fn no_starvation() {
loop {
for i in 0..rng.gen_range(0..COUNT) {
if rng.gen_range(0..3) == 0 && my_hits == 0 {
while let Some(_) = w.pop() {
while w.pop().is_some() {
my_hits += 1;
}
} else {
Expand Down Expand Up @@ -300,7 +300,7 @@ fn destructors() {
remaining.fetch_sub(1, SeqCst);
}

while let Some(_) = w2.pop() {
while w2.pop().is_some() {
cnt += 1;
remaining.fetch_sub(1, SeqCst);
}
Expand All @@ -309,7 +309,7 @@ fn destructors() {
}

for _ in 0..STEPS {
if let Some(_) = w.pop() {
if w.pop().is_some() {
remaining.fetch_sub(1, SeqCst);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/src/atomic.rs
Expand Up @@ -1545,6 +1545,6 @@ mod tests {
#[test]
fn const_atomic_null() {
use super::Atomic;
const _: Atomic<u8> = Atomic::<u8>::null();
static _U: Atomic<u8> = Atomic::<u8>::null();
}
}
2 changes: 1 addition & 1 deletion crossbeam-skiplist/tests/base.rs
Expand Up @@ -164,7 +164,7 @@ fn len() {
assert_eq!(s.len(), 0);

for (i, &x) in [4, 2, 12, 8, 7, 11, 5].iter().enumerate() {
s.insert(x, x * 1, guard);
s.insert(x, x * 10, guard);
assert_eq!(s.len(), i + 1);
}

Expand Down
1 change: 1 addition & 0 deletions crossbeam-utils/tests/cache_padded.rs
Expand Up @@ -85,6 +85,7 @@ fn drops() {
assert_eq!(count.get(), 2);
}

#[allow(clippy::clone_on_copy)] // This is intentional.
#[test]
fn clone() {
let a = CachePadded::new(17);
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-utils/tests/sharded_lock.rs
Expand Up @@ -138,7 +138,7 @@ fn arc() {
fn arc_access_in_unwind() {
let arc = Arc::new(ShardedLock::new(1));
let arc2 = arc.clone();
let _ = thread::spawn(move || -> () {
let _ = thread::spawn(move || {
struct Unwinder {
i: Arc<ShardedLock<isize>>,
}
Expand Down

0 comments on commit 3e83987

Please sign in to comment.