From 447a4ec795202fdaf9cb3e2792d3828d0cfcb60c Mon Sep 17 00:00:00 2001 From: Daniel Philip Watson Date: Mon, 13 Apr 2026 01:46:41 -0400 Subject: [PATCH 1/5] add must_use to partial_shuffle --- src/seq/slice.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/seq/slice.rs b/src/seq/slice.rs index 1b8a068eae..80ccd39cc7 100644 --- a/src/seq/slice.rs +++ b/src/seq/slice.rs @@ -437,6 +437,23 @@ pub trait SliceRandom: IndexedMutRandom { /// will perform a full shuffle. /// /// For slices, complexity is `O(m)` where `m = amount`. + /// + /// # Warning + /// + /// The position of the returned slices within the original slice is not guaranteed. + /// + /// # Example + /// + /// ``` + /// use rand::seq::SliceRandom; + /// + /// let mut rng = rand::rng(); + /// let mut y = [1, 2, 3, 4, 5]; + /// let (shuffled, rest) = y.partial_shuffle(&mut rng, 3); + /// assert_eq!(shuffled.len(), 3); + /// assert_eq!(rest.len(), 2); + /// ``` + #[must_use = "the returned subslices should be used to access the shuffled elements; their position within the original slice is an implementation detail"] fn partial_shuffle( &mut self, rng: &mut R, From 27bf3a7d25a8696ca33701c296303d2cd561b0d1 Mon Sep 17 00:00:00 2001 From: Daniel Philip Watson Date: Mon, 13 Apr 2026 03:43:23 -0400 Subject: [PATCH 2/5] ignore must_use in shuffle bench --- benches/benches/shuffle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/benches/shuffle.rs b/benches/benches/shuffle.rs index 8ace45a5a1..ec9cab4017 100644 --- a/benches/benches/shuffle.rs +++ b/benches/benches/shuffle.rs @@ -52,7 +52,7 @@ fn bench_rng(c: &mut Criterion, rng_name: &'static str) { let mut rng = R::seed_from_u64(123); let mut vec: Vec = (0..length).collect(); b.iter(|| { - vec.partial_shuffle(&mut rng, length / 2); + let _ = vec.partial_shuffle(&mut rng, length / 2); vec[0] }) }); From 527a4e705c644dc62139801cd5ef5bcbad2fc7dc Mon Sep 17 00:00:00 2001 From: Daniel Philip Watson Date: Mon, 13 Apr 2026 03:45:36 -0400 Subject: [PATCH 3/5] ignore must_use in shuffle wrapper --- src/seq/slice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seq/slice.rs b/src/seq/slice.rs index 80ccd39cc7..660fab7b60 100644 --- a/src/seq/slice.rs +++ b/src/seq/slice.rs @@ -481,7 +481,7 @@ impl SliceRandom for [T] { // There is no need to shuffle an empty or single element slice return; } - self.partial_shuffle(rng, self.len()); + let _ = self.partial_shuffle(rng, self.len()); } fn partial_shuffle(&mut self, rng: &mut R, amount: usize) -> (&mut [T], &mut [T]) From 7099ce52b95b604c808a6ccba8fb621aff151f64 Mon Sep 17 00:00:00 2001 From: Daniel Philip Watson Date: Mon, 13 Apr 2026 03:56:17 -0400 Subject: [PATCH 4/5] trim whitespace --- src/seq/slice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seq/slice.rs b/src/seq/slice.rs index 660fab7b60..e309e0ed23 100644 --- a/src/seq/slice.rs +++ b/src/seq/slice.rs @@ -441,7 +441,7 @@ pub trait SliceRandom: IndexedMutRandom { /// # Warning /// /// The position of the returned slices within the original slice is not guaranteed. - /// + /// /// # Example /// /// ``` From 90df0cfcd384e5c06ad9c6d5fd1e067842960391 Mon Sep 17 00:00:00 2001 From: Daniel Philip Watson Date: Mon, 13 Apr 2026 04:13:29 -0400 Subject: [PATCH 5/5] more whitespace --- src/seq/slice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seq/slice.rs b/src/seq/slice.rs index e309e0ed23..86291f702b 100644 --- a/src/seq/slice.rs +++ b/src/seq/slice.rs @@ -440,7 +440,7 @@ pub trait SliceRandom: IndexedMutRandom { /// /// # Warning /// - /// The position of the returned slices within the original slice is not guaranteed. + /// The position of the returned slices within the original slice is not guaranteed. /// /// # Example ///