Skip to content

Commit 3e83987

Browse files
bors[bot]taiki-e
andauthored
Merge #696
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>
2 parents c093db3 + b6eb76e commit 3e83987

File tree

10 files changed

+24
-27
lines changed

10 files changed

+24
-27
lines changed

crossbeam-channel/examples/fibonacci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn fibonacci(sender: Sender<u64>) {
1010
while sender.send(x).is_ok() {
1111
let tmp = x;
1212
x = y;
13-
y = tmp + y;
13+
y += tmp;
1414
}
1515
}
1616

crossbeam-channel/examples/stopwatch.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ fn main() {
3333

3434
// Prints the elapsed time.
3535
fn show(dur: Duration) {
36-
println!(
37-
"Elapsed: {}.{:03} sec",
38-
dur.as_secs(),
39-
dur.subsec_nanos() / 1_000_000
40-
);
36+
println!("Elapsed: {}.{:03} sec", dur.as_secs(), dur.subsec_millis());
4137
}
4238

4339
let start = Instant::now();

crossbeam-channel/tests/golang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ unsafe impl GlobalAlloc for Counter {
176176
if !ret.is_null() {
177177
ALLOCATED.fetch_add(layout.size(), SeqCst);
178178
}
179-
return ret;
179+
ret
180180
}
181181

182182
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {

crossbeam-deque/tests/fifo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn stress() {
167167
hits.fetch_add(1, SeqCst);
168168
}
169169

170-
while let Some(_) = w2.pop() {
170+
while w2.pop().is_some() {
171171
hits.fetch_add(1, SeqCst);
172172
}
173173
}
@@ -178,7 +178,7 @@ fn stress() {
178178
let mut expected = 0;
179179
while expected < COUNT {
180180
if rng.gen_range(0..3) == 0 {
181-
while let Some(_) = w.pop() {
181+
while w.pop().is_some() {
182182
hits.fetch_add(1, SeqCst);
183183
}
184184
} else {
@@ -188,7 +188,7 @@ fn stress() {
188188
}
189189

190190
while hits.load(SeqCst) < COUNT {
191-
while let Some(_) = w.pop() {
191+
while w.pop().is_some() {
192192
hits.fetch_add(1, SeqCst);
193193
}
194194
}
@@ -227,7 +227,7 @@ fn no_starvation() {
227227
hits.fetch_add(1, SeqCst);
228228
}
229229

230-
while let Some(_) = w2.pop() {
230+
while w2.pop().is_some() {
231231
hits.fetch_add(1, SeqCst);
232232
}
233233
}
@@ -239,7 +239,7 @@ fn no_starvation() {
239239
loop {
240240
for i in 0..rng.gen_range(0..COUNT) {
241241
if rng.gen_range(0..3) == 0 && my_hits == 0 {
242-
while let Some(_) = w.pop() {
242+
while w.pop().is_some() {
243243
my_hits += 1;
244244
}
245245
} else {
@@ -300,7 +300,7 @@ fn destructors() {
300300
remaining.fetch_sub(1, SeqCst);
301301
}
302302

303-
while let Some(_) = w2.pop() {
303+
while w2.pop().is_some() {
304304
cnt += 1;
305305
remaining.fetch_sub(1, SeqCst);
306306
}
@@ -309,7 +309,7 @@ fn destructors() {
309309
}
310310

311311
for _ in 0..STEPS {
312-
if let Some(_) = w.pop() {
312+
if w.pop().is_some() {
313313
remaining.fetch_sub(1, SeqCst);
314314
}
315315
}

crossbeam-deque/tests/injector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn stress() {
178178
hits.fetch_add(1, SeqCst);
179179
}
180180

181-
while let Some(_) = w2.pop() {
181+
while w2.pop().is_some() {
182182
hits.fetch_add(1, SeqCst);
183183
}
184184
}
@@ -238,7 +238,7 @@ fn no_starvation() {
238238
hits.fetch_add(1, SeqCst);
239239
}
240240

241-
while let Some(_) = w2.pop() {
241+
while w2.pop().is_some() {
242242
hits.fetch_add(1, SeqCst);
243243
}
244244
}
@@ -311,7 +311,7 @@ fn destructors() {
311311
remaining.fetch_sub(1, SeqCst);
312312
}
313313

314-
while let Some(_) = w2.pop() {
314+
while w2.pop().is_some() {
315315
cnt += 1;
316316
remaining.fetch_sub(1, SeqCst);
317317
}

crossbeam-deque/tests/lifo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn stress() {
167167
hits.fetch_add(1, SeqCst);
168168
}
169169

170-
while let Some(_) = w2.pop() {
170+
while w2.pop().is_some() {
171171
hits.fetch_add(1, SeqCst);
172172
}
173173
}
@@ -178,7 +178,7 @@ fn stress() {
178178
let mut expected = 0;
179179
while expected < COUNT {
180180
if rng.gen_range(0..3) == 0 {
181-
while let Some(_) = w.pop() {
181+
while w.pop().is_some() {
182182
hits.fetch_add(1, SeqCst);
183183
}
184184
} else {
@@ -188,7 +188,7 @@ fn stress() {
188188
}
189189

190190
while hits.load(SeqCst) < COUNT {
191-
while let Some(_) = w.pop() {
191+
while w.pop().is_some() {
192192
hits.fetch_add(1, SeqCst);
193193
}
194194
}
@@ -227,7 +227,7 @@ fn no_starvation() {
227227
hits.fetch_add(1, SeqCst);
228228
}
229229

230-
while let Some(_) = w2.pop() {
230+
while w2.pop().is_some() {
231231
hits.fetch_add(1, SeqCst);
232232
}
233233
}
@@ -239,7 +239,7 @@ fn no_starvation() {
239239
loop {
240240
for i in 0..rng.gen_range(0..COUNT) {
241241
if rng.gen_range(0..3) == 0 && my_hits == 0 {
242-
while let Some(_) = w.pop() {
242+
while w.pop().is_some() {
243243
my_hits += 1;
244244
}
245245
} else {
@@ -300,7 +300,7 @@ fn destructors() {
300300
remaining.fetch_sub(1, SeqCst);
301301
}
302302

303-
while let Some(_) = w2.pop() {
303+
while w2.pop().is_some() {
304304
cnt += 1;
305305
remaining.fetch_sub(1, SeqCst);
306306
}
@@ -309,7 +309,7 @@ fn destructors() {
309309
}
310310

311311
for _ in 0..STEPS {
312-
if let Some(_) = w.pop() {
312+
if w.pop().is_some() {
313313
remaining.fetch_sub(1, SeqCst);
314314
}
315315
}

crossbeam-epoch/src/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,6 @@ mod tests {
15451545
#[test]
15461546
fn const_atomic_null() {
15471547
use super::Atomic;
1548-
const _: Atomic<u8> = Atomic::<u8>::null();
1548+
static _U: Atomic<u8> = Atomic::<u8>::null();
15491549
}
15501550
}

crossbeam-skiplist/tests/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn len() {
164164
assert_eq!(s.len(), 0);
165165

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

crossbeam-utils/tests/cache_padded.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn drops() {
8585
assert_eq!(count.get(), 2);
8686
}
8787

88+
#[allow(clippy::clone_on_copy)] // This is intentional.
8889
#[test]
8990
fn clone() {
9091
let a = CachePadded::new(17);

crossbeam-utils/tests/sharded_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn arc() {
138138
fn arc_access_in_unwind() {
139139
let arc = Arc::new(ShardedLock::new(1));
140140
let arc2 = arc.clone();
141-
let _ = thread::spawn(move || -> () {
141+
let _ = thread::spawn(move || {
142142
struct Unwinder {
143143
i: Arc<ShardedLock<isize>>,
144144
}

0 commit comments

Comments
 (0)