Skip to content

Commit e0292f3

Browse files
authored
Merge pull request #1363 from vks/clippy
Fix clippy warnings
2 parents ef89cbe + c427cff commit e0292f3

16 files changed

+44
-41
lines changed

benches/seq_choose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn bench(c: &mut Criterion) {
2323
}
2424

2525
fn bench_rng<Rng: RngCore + SeedableRng>(c: &mut Criterion, rng_name: &'static str) {
26-
for length in [1, 2, 3, 10, 100, 1000].map(|x| black_box(x)) {
26+
for length in [1, 2, 3, 10, 100, 1000].map(black_box) {
2727
c.bench_function(
2828
format!("choose_size-hinted_from_{length}_{rng_name}").as_str(),
2929
|b| {

benches/shuffle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn bench(c: &mut Criterion) {
2323
}
2424

2525
fn bench_rng<Rng: RngCore + SeedableRng>(c: &mut Criterion, rng_name: &'static str) {
26-
for length in [1, 2, 3, 10, 100, 1000, 10000].map(|x| black_box(x)) {
26+
for length in [1, 2, 3, 10, 100, 1000, 10000].map(black_box) {
2727
c.bench_function(format!("shuffle_{length}_{rng_name}").as_str(), |b| {
2828
let mut rng = Rng::seed_from_u64(123);
2929
let mut vec: Vec<usize> = (0..length).collect();

rand_core/src/block.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,20 +470,20 @@ mod test {
470470
let mut rng3 = rng1.clone();
471471

472472
let mut a = [0; 16];
473-
(&mut a[..4]).copy_from_slice(&rng1.next_u32().to_le_bytes());
474-
(&mut a[4..12]).copy_from_slice(&rng1.next_u64().to_le_bytes());
475-
(&mut a[12..]).copy_from_slice(&rng1.next_u32().to_le_bytes());
473+
a[..4].copy_from_slice(&rng1.next_u32().to_le_bytes());
474+
a[4..12].copy_from_slice(&rng1.next_u64().to_le_bytes());
475+
a[12..].copy_from_slice(&rng1.next_u32().to_le_bytes());
476476

477477
let mut b = [0; 16];
478-
(&mut b[..4]).copy_from_slice(&rng2.next_u32().to_le_bytes());
479-
(&mut b[4..8]).copy_from_slice(&rng2.next_u32().to_le_bytes());
480-
(&mut b[8..]).copy_from_slice(&rng2.next_u64().to_le_bytes());
478+
b[..4].copy_from_slice(&rng2.next_u32().to_le_bytes());
479+
b[4..8].copy_from_slice(&rng2.next_u32().to_le_bytes());
480+
b[8..].copy_from_slice(&rng2.next_u64().to_le_bytes());
481481
assert_eq!(a, b);
482482

483483
let mut c = [0; 16];
484-
(&mut c[..8]).copy_from_slice(&rng3.next_u64().to_le_bytes());
485-
(&mut c[8..12]).copy_from_slice(&rng3.next_u32().to_le_bytes());
486-
(&mut c[12..]).copy_from_slice(&rng3.next_u32().to_le_bytes());
484+
c[..8].copy_from_slice(&rng3.next_u64().to_le_bytes());
485+
c[8..12].copy_from_slice(&rng3.next_u32().to_le_bytes());
486+
c[12..].copy_from_slice(&rng3.next_u32().to_le_bytes());
487487
assert_eq!(a, c);
488488
}
489489

@@ -520,22 +520,22 @@ mod test {
520520
let mut rng3 = rng1.clone();
521521

522522
let mut a = [0; 16];
523-
(&mut a[..4]).copy_from_slice(&rng1.next_u32().to_le_bytes());
524-
(&mut a[4..12]).copy_from_slice(&rng1.next_u64().to_le_bytes());
525-
(&mut a[12..]).copy_from_slice(&rng1.next_u32().to_le_bytes());
523+
a[..4].copy_from_slice(&rng1.next_u32().to_le_bytes());
524+
a[4..12].copy_from_slice(&rng1.next_u64().to_le_bytes());
525+
a[12..].copy_from_slice(&rng1.next_u32().to_le_bytes());
526526

527527
let mut b = [0; 16];
528-
(&mut b[..4]).copy_from_slice(&rng2.next_u32().to_le_bytes());
529-
(&mut b[4..8]).copy_from_slice(&rng2.next_u32().to_le_bytes());
530-
(&mut b[8..]).copy_from_slice(&rng2.next_u64().to_le_bytes());
528+
b[..4].copy_from_slice(&rng2.next_u32().to_le_bytes());
529+
b[4..8].copy_from_slice(&rng2.next_u32().to_le_bytes());
530+
b[8..].copy_from_slice(&rng2.next_u64().to_le_bytes());
531531
assert_ne!(a, b);
532532
assert_eq!(&a[..4], &b[..4]);
533533
assert_eq!(&a[4..12], &b[8..]);
534534

535535
let mut c = [0; 16];
536-
(&mut c[..8]).copy_from_slice(&rng3.next_u64().to_le_bytes());
537-
(&mut c[8..12]).copy_from_slice(&rng3.next_u32().to_le_bytes());
538-
(&mut c[12..]).copy_from_slice(&rng3.next_u32().to_le_bytes());
536+
c[..8].copy_from_slice(&rng3.next_u64().to_le_bytes());
537+
c[8..12].copy_from_slice(&rng3.next_u32().to_le_bytes());
538+
c[12..].copy_from_slice(&rng3.next_u32().to_le_bytes());
539539
assert_eq!(b, c);
540540
}
541541
}

rand_distr/src/binomial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Distribution<u64> for Binomial {
127127
let mut u: f64 = rng.gen();
128128
let mut x = 0;
129129

130-
while u > r as f64 {
130+
while u > r {
131131
u -= r;
132132
x += 1;
133133
if x > BINV_MAX_X {
@@ -332,7 +332,7 @@ mod test {
332332
}
333333

334334
let mean = results.iter().sum::<f64>() / results.len() as f64;
335-
assert!((mean as f64 - expected_mean).abs() < expected_mean / 50.0);
335+
assert!((mean - expected_mean).abs() < expected_mean / 50.0);
336336

337337
let variance =
338338
results.iter().map(|x| (x - mean) * (x - mean)).sum::<f64>() / results.len() as f64;

rand_distr/src/cauchy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ mod test {
142142
let distr = Cauchy::new(m, s).unwrap();
143143
let mut rng = crate::test::rng(353);
144144
for x in buf {
145-
*x = rng.sample(&distr);
145+
*x = rng.sample(distr);
146146
}
147147
}
148148

rand_distr/src/geometric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Geometric {
5959
/// Construct a new `Geometric` with the given shape parameter `p`
6060
/// (probability of success on each trial).
6161
pub fn new(p: f64) -> Result<Self, Error> {
62-
if !p.is_finite() || p < 0.0 || p > 1.0 {
62+
if !p.is_finite() || !(0.0..=1.0).contains(&p) {
6363
Err(Error::InvalidProbability)
6464
} else if p == 0.0 || p >= 2.0 / 3.0 {
6565
Ok(Geometric { p, pi: p, k: 0 })
@@ -198,7 +198,7 @@ mod test {
198198
}
199199

200200
let mean = results.iter().sum::<f64>() / results.len() as f64;
201-
assert!((mean as f64 - expected_mean).abs() < expected_mean / 40.0);
201+
assert!((mean - expected_mean).abs() < expected_mean / 40.0);
202202

203203
let variance =
204204
results.iter().map(|x| (x - mean) * (x - mean)).sum::<f64>() / results.len() as f64;
@@ -230,7 +230,7 @@ mod test {
230230
}
231231

232232
let mean = results.iter().sum::<f64>() / results.len() as f64;
233-
assert!((mean as f64 - expected_mean).abs() < expected_mean / 50.0);
233+
assert!((mean - expected_mean).abs() < expected_mean / 50.0);
234234

235235
let variance =
236236
results.iter().map(|x| (x - mean) * (x - mean)).sum::<f64>() / results.len() as f64;

rand_distr/src/hypergeometric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl Distribution<u64> for Hypergeometric {
244244
let mut u = rng.gen::<f64>();
245245
while u > p && x < k as i64 { // the paper erroneously uses `until n < p`, which doesn't make any sense
246246
u -= p;
247-
p *= ((n1 as i64 - x as i64) * (k as i64 - x as i64)) as f64;
248-
p /= ((x as i64 + 1) * (n2 as i64 - k as i64 + 1 + x as i64)) as f64;
247+
p *= ((n1 as i64 - x) * (k as i64 - x)) as f64;
248+
p /= ((x + 1) * (n2 as i64 - k as i64 + 1 + x)) as f64;
249249
x += 1;
250250
}
251251
x
@@ -397,7 +397,7 @@ mod test {
397397
}
398398

399399
let mean = results.iter().sum::<f64>() / results.len() as f64;
400-
assert!((mean as f64 - expected_mean).abs() < expected_mean / 50.0);
400+
assert!((mean - expected_mean).abs() < expected_mean / 50.0);
401401

402402
let variance =
403403
results.iter().map(|x| (x - mean) * (x - mean)).sum::<f64>() / results.len() as f64;

rand_distr/src/normal_inverse_gaussian.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ where
7676
{
7777
fn sample<R>(&self, rng: &mut R) -> F
7878
where R: Rng + ?Sized {
79-
let inv_gauss = rng.sample(&self.inverse_gaussian);
79+
let inv_gauss = rng.sample(self.inverse_gaussian);
8080

8181
self.beta * inv_gauss + inv_gauss.sqrt() * rng.sample(StandardNormal)
8282
}

rand_distr/src/skew_normal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ mod tests {
247247
let mut rng = crate::test::rng(213);
248248
let mut buf = [0.0; 4];
249249
for x in &mut buf {
250-
*x = rng.sample(&skew_normal);
250+
*x = rng.sample(skew_normal);
251251
}
252252
for value in buf.iter() {
253253
assert!(value.is_nan());

src/distributions/bernoulli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ mod test {
206206
let distr = Bernoulli::new(0.4532).unwrap();
207207
let mut buf = [false; 10];
208208
for x in &mut buf {
209-
*x = rng.sample(&distr);
209+
*x = rng.sample(distr);
210210
}
211211
assert_eq!(buf, [
212212
true, false, false, true, false, false, true, true, true, true

src/distributions/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ mod tests {
268268
let mut rng = crate::test::rng(0x6f44f5646c2a7334);
269269
let mut buf = [zero; 3];
270270
for x in &mut buf {
271-
*x = rng.sample(&distr);
271+
*x = rng.sample(distr);
272272
}
273273
assert_eq!(&buf, expected);
274274
}

src/distributions/other.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ mod tests {
328328
let mut rng = crate::test::rng(807);
329329
let mut buf = [zero; 5];
330330
for x in &mut buf {
331-
*x = rng.sample(&distr);
331+
*x = rng.sample(distr);
332332
}
333333
assert_eq!(&buf, expected);
334334
}

src/distributions/uniform.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ mod tests {
16761676

16771677
#[test]
16781678
fn test_uniform_from_std_range_bad_limits() {
1679+
#![allow(clippy::reversed_empty_ranges)]
16791680
assert!(Uniform::try_from(100..10).is_err());
16801681
assert!(Uniform::try_from(100..100).is_err());
16811682
assert!(Uniform::try_from(100.0..10.0).is_err());
@@ -1695,6 +1696,7 @@ mod tests {
16951696

16961697
#[test]
16971698
fn test_uniform_from_std_range_inclusive_bad_limits() {
1699+
#![allow(clippy::reversed_empty_ranges)]
16981700
assert!(Uniform::try_from(100..=10).is_err());
16991701
assert!(Uniform::try_from(100..=99).is_err());
17001702
assert!(Uniform::try_from(100.0..=10.0).is_err());
@@ -1760,6 +1762,6 @@ mod tests {
17601762
assert_eq!(Uniform::new(1.0, 2.0).unwrap(), Uniform::new(1.0, 2.0).unwrap());
17611763

17621764
// To cover UniformInt
1763-
assert_eq!(Uniform::new(1 as u32, 2 as u32).unwrap(), Uniform::new(1 as u32, 2 as u32).unwrap());
1765+
assert_eq!(Uniform::new(1_u32, 2_u32).unwrap(), Uniform::new(1_u32, 2_u32).unwrap());
17641766
}
17651767
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#![allow(
5555
clippy::float_cmp,
5656
clippy::neg_cmp_op_on_partial_ord,
57+
clippy::nonminimal_bool
5758
)]
5859

5960
#[cfg(feature = "std")] extern crate std;

src/seq/coin_flipper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl<R: RngCore> CoinFlipper<R> {
3737

3838
if self.flip_c_heads(c) {
3939
let numerator = 1 << c;
40-
return self.gen_ratio(numerator, d);
40+
self.gen_ratio(numerator, d)
4141
} else {
42-
return false;
42+
false
4343
}
4444
}
4545

src/seq/index.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ impl PartialEq for IndexVec {
105105
fn eq(&self, other: &IndexVec) -> bool {
106106
use self::IndexVec::*;
107107
match (self, other) {
108-
(&U32(ref v1), &U32(ref v2)) => v1 == v2,
109-
(&USize(ref v1), &USize(ref v2)) => v1 == v2,
110-
(&U32(ref v1), &USize(ref v2)) => {
108+
(U32(v1), U32(v2)) => v1 == v2,
109+
(USize(v1), USize(v2)) => v1 == v2,
110+
(U32(v1), USize(v2)) => {
111111
(v1.len() == v2.len()) && (v1.iter().zip(v2.iter()).all(|(x, y)| *x as usize == *y))
112112
}
113-
(&USize(ref v1), &U32(ref v2)) => {
113+
(USize(v1), U32(v2)) => {
114114
(v1.len() == v2.len()) && (v1.iter().zip(v2.iter()).all(|(x, y)| *x == *y as usize))
115115
}
116116
}

0 commit comments

Comments
 (0)