Skip to content

Commit d1343fc

Browse files
committed
Fix various warnings
Warnings reported by CI and by `cargo clippy --all-targets --all-features -- -D warnings`
1 parent 03c28ad commit d1343fc

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

benches/benches/generators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn reseeding_bytes(c: &mut Criterion) {
196196
g.throughput(criterion::Throughput::Bytes(1024 * 1024));
197197

198198
fn bench(g: &mut BenchmarkGroup<WallTime>, thresh: u64) {
199-
let name = format!("chacha20_{}k", thresh);
199+
let name = format!("chacha20_{thresh}k");
200200
g.bench_function(name.as_str(), |b| {
201201
let mut rng = ReseedingRng::<ChaCha20Core, _>::new(thresh * 1024, OsRng).unwrap();
202202
let mut buf = [0u8; 1024 * 1024];

benches/benches/seq_choose.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn bench(c: &mut Criterion) {
3030

3131
let lens = [(1, 1000), (950, 1000), (10, 100), (90, 100)];
3232
for (amount, len) in lens {
33-
let name = format!("seq_slice_choose_multiple_{}_of_{}", amount, len);
33+
let name = format!("seq_slice_choose_multiple_{amount}_of_{len}");
3434
c.bench_function(name.as_str(), |b| {
3535
let mut rng = Pcg32::from_rng(&mut rand::rng());
3636
let mut buf = [0i32; 1000];
@@ -54,7 +54,7 @@ pub fn bench(c: &mut Criterion) {
5454

5555
let lens = [(1, 1000), (950, 1000), (10, 100), (90, 100)];
5656
for (amount, len) in lens {
57-
let name = format!("seq_slice_choose_multiple_weighted_{}_of_{}", amount, len);
57+
let name = format!("seq_slice_choose_multiple_weighted_{amount}_of_{len}");
5858
c.bench_function(name.as_str(), |b| {
5959
let mut rng = Pcg32::from_rng(&mut rand::rng());
6060
let mut buf = [0i32; 1000];

benches/benches/weighted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn bench(c: &mut Criterion) {
4949
(1000, 1_000_000, "1M"),
5050
];
5151
for (amount, length, len_name) in lens {
52-
let name = format!("weighted_sample_indices_{}_of_{}", amount, len_name);
52+
let name = format!("weighted_sample_indices_{amount}_of_{len_name}");
5353
c.bench_function(name.as_str(), |b| {
5454
let length = black_box(length);
5555
let amount = black_box(amount);

rand_core/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ mod test {
557557
}
558558
rng.next_u32();
559559

560-
let result = rng.next_u64();
560+
let _ = rng.next_u64();
561561
assert_eq!(rng.index(), 1);
562562
}
563563
}

rand_core/src/impls.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,39 +179,39 @@ mod test {
179179
fn test_fill_via_u32_chunks() {
180180
let src_orig = [1u32, 2, 3];
181181

182-
let mut src = src_orig;
182+
let src = src_orig;
183183
let mut dst = [0u8; 11];
184-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (3, 11));
184+
assert_eq!(fill_via_chunks(&src, &mut dst), (3, 11));
185185
assert_eq!(dst, [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0]);
186186

187-
let mut src = src_orig;
187+
let src = src_orig;
188188
let mut dst = [0u8; 13];
189-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (3, 12));
189+
assert_eq!(fill_via_chunks(&src, &mut dst), (3, 12));
190190
assert_eq!(dst, [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0]);
191191

192-
let mut src = src_orig;
192+
let src = src_orig;
193193
let mut dst = [0u8; 5];
194-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (2, 5));
194+
assert_eq!(fill_via_chunks(&src, &mut dst), (2, 5));
195195
assert_eq!(dst, [1, 0, 0, 0, 2]);
196196
}
197197

198198
#[test]
199199
fn test_fill_via_u64_chunks() {
200200
let src_orig = [1u64, 2];
201201

202-
let mut src = src_orig;
202+
let src = src_orig;
203203
let mut dst = [0u8; 11];
204-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (2, 11));
204+
assert_eq!(fill_via_chunks(&src, &mut dst), (2, 11));
205205
assert_eq!(dst, [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0]);
206206

207-
let mut src = src_orig;
207+
let src = src_orig;
208208
let mut dst = [0u8; 17];
209-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (2, 16));
209+
assert_eq!(fill_via_chunks(&src, &mut dst), (2, 16));
210210
assert_eq!(dst, [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0]);
211211

212-
let mut src = src_orig;
212+
let src = src_orig;
213213
let mut dst = [0u8; 5];
214-
assert_eq!(fill_via_chunks(&mut src, &mut dst), (1, 5));
214+
assert_eq!(fill_via_chunks(&src, &mut dst), (1, 5));
215215
assert_eq!(dst, [1, 0, 0, 0, 0]);
216216
}
217217
}

rand_core/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,11 @@ mod test {
764764
let mut rng = rng.unwrap_mut();
765765

766766
assert_eq!(rng.next_u32(), 4);
767-
let mut rng2 = rng.re();
768-
assert_eq!(rng2.next_u32(), 4);
769-
drop(rng2);
767+
{
768+
let mut rng2 = rng.re();
769+
assert_eq!(rng2.next_u32(), 4);
770+
// Make sure rng2 is dropped.
771+
}
770772
assert_eq!(rng.next_u32(), 4);
771773
}
772774
}

src/seq/iterator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ pub trait IteratorRandom: Iterator + Sized {
137137
//
138138
// Clippy is wrong here: we need to iterate over all entries with the RNG to
139139
// ensure that choosing is *stable*.
140+
// "allow(unknown_lints)" can be removed when switching to at least
141+
// rust-version 1.86.0, see:
142+
// https://rust-lang.github.io/rust-clippy/master/index.html#double_ended_iterator_last
143+
#[allow(unknown_lints)]
140144
#[allow(clippy::double_ended_iterator_last)]
141145
fn choose_stable<R>(mut self, rng: &mut R) -> Option<Self::Item>
142146
where

src/seq/slice.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ pub trait IndexedRandom: Index<usize> {
8787
/// }
8888
/// ```
8989
#[cfg(feature = "alloc")]
90-
fn choose_multiple<R>(&self, rng: &mut R, amount: usize) -> SliceChooseIter<Self, Self::Output>
90+
fn choose_multiple<R>(
91+
&self,
92+
rng: &mut R,
93+
amount: usize,
94+
) -> SliceChooseIter<'_, Self, Self::Output>
9195
where
9296
Self::Output: Sized,
9397
R: Rng + ?Sized,
@@ -209,7 +213,7 @@ pub trait IndexedRandom: Index<usize> {
209213
rng: &mut R,
210214
amount: usize,
211215
weight: F,
212-
) -> Result<SliceChooseIter<Self, Self::Output>, WeightError>
216+
) -> Result<SliceChooseIter<'_, Self, Self::Output>, WeightError>
213217
where
214218
Self::Output: Sized,
215219
R: Rng + ?Sized,

0 commit comments

Comments
 (0)