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] }) }); diff --git a/src/seq/slice.rs b/src/seq/slice.rs index 1b8a068eae..86291f702b 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, @@ -464,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])