We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
slice::sort
1 parent 94a0cd1 commit ce03e7bCopy full SHA for ce03e7b
2 files changed
library/alloctests/tests/sort/tests.rs
@@ -362,6 +362,13 @@ fn sort_vs_sort_by_impl<S: Sort>() {
362
assert_eq!(input_sort_by, expected);
363
}
364
365
+pub fn box_value_impl<S: Sort>() {
366
+ for len in [3, 9, 35, 56, 132] {
367
+ test_is_sorted::<Box<i32>, S>(len, Box::new, patterns::random);
368
+ test_is_sorted::<Box<i32>, S>(len, Box::new, |len| patterns::random_sorted(len, 80.0));
369
+ }
370
+}
371
+
372
gen_sort_test_fns_with_default_patterns!(
373
correct_i32,
374
|len, pattern_fn| test_is_sorted::<i32, S>(len, |val| val, pattern_fn),
@@ -967,6 +974,7 @@ define_instantiate_sort_tests!(
967
974
[miri_yes, fixed_seed_rand_vec_prefix],
968
975
[miri_yes, int_edge],
969
976
[miri_yes, sort_vs_sort_by],
977
+ [miri_yes, box_value],
970
978
[miri_yes, correct_i32_random],
971
979
[miri_yes, correct_i32_random_z1],
972
980
[miri_yes, correct_i32_random_d2],
library/core/src/slice/sort/stable/quicksort.rs
@@ -1,6 +1,6 @@
1
//! This module contains a stable quicksort and partition implementation.
2
3
-use crate::mem::{ManuallyDrop, MaybeUninit};
+use crate::mem::MaybeUninit;
4
use crate::slice::sort::shared::FreezeMarker;
5
use crate::slice::sort::shared::pivot::choose_pivot;
6
use crate::slice::sort::shared::smallsort::StableSmallSortTypeImpl;
@@ -41,8 +41,11 @@ pub fn quicksort<T, F: FnMut(&T, &T) -> bool>(
41
// SAFETY: We only access the temporary copy for Freeze types, otherwise
42
// self-modifications via `is_less` would not be observed and this would
43
// be unsound. Our temporary copy does not escape this scope.
44
- let pivot_copy = unsafe { ManuallyDrop::new(ptr::read(&v[pivot_pos])) };
45
- let pivot_ref = (!has_direct_interior_mutability::<T>()).then_some(&*pivot_copy);
+ // We use `MaybeUninit` to avoid re-tag issues. FIXME: use `MaybeDangling`.
+ let pivot_copy = unsafe { ptr::read((&raw const v[pivot_pos]).cast::<MaybeUninit<T>>()) };
46
+ let pivot_ref =
47
+ // SAFETY: We created the value in an init state.
48
+ (!has_direct_interior_mutability::<T>()).then_some(unsafe { &*pivot_copy.as_ptr() });
49
50
// We choose a pivot, and check if this pivot is equal to our left
51
// ancestor. If true, we do a partition putting equal elements on the
0 commit comments