Fix tidy errors
This commit is contained in:
parent
e49be415cd
commit
1a6b0e410e
6 changed files with 13 additions and 26 deletions
|
@ -92,7 +92,10 @@ fn partition_at_index_loop<'a, T, F>(
|
|||
// slice. Partition the slice into elements equal to and elements greater than the pivot.
|
||||
// This case is usually hit when the slice contains many duplicate elements.
|
||||
if let Some(p) = ancestor_pivot {
|
||||
if !is_less(p, unsafe { v.get_unchecked(pivot_pos) }) {
|
||||
// SAFETY: choose_pivot promises to return a valid pivot position.
|
||||
let pivot = unsafe { v.get_unchecked(pivot_pos) };
|
||||
|
||||
if !is_less(p, pivot) {
|
||||
let num_lt = partition(v, pivot_pos, &mut |a, b| !is_less(b, a));
|
||||
|
||||
// Continue sorting elements greater than the pivot. We know that `mid` contains
|
||||
|
|
|
@ -177,6 +177,8 @@ fn small_sort_fallback<T, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F
|
|||
fn small_sort_general<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F) {
|
||||
let mut stack_array = MaybeUninit::<[T; SMALL_SORT_GENERAL_SCRATCH_LEN]>::uninit();
|
||||
|
||||
// SAFETY: The memory is backed by `stack_array`, and the operation is safe as long as the len
|
||||
// is the same.
|
||||
let scratch = unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
stack_array.as_mut_ptr() as *mut MaybeUninit<T>,
|
||||
|
@ -327,8 +329,9 @@ where
|
|||
}
|
||||
|
||||
// SAFETY: The right side of `v` based on `len_div_2` is guaranteed in-bounds.
|
||||
region =
|
||||
unsafe { &mut *ptr::slice_from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2) };
|
||||
unsafe {
|
||||
region = &mut *ptr::slice_from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2)
|
||||
};
|
||||
}
|
||||
|
||||
// SAFETY: We checked that T is Freeze and thus observation safe.
|
||||
|
@ -812,14 +815,6 @@ pub(crate) const fn has_efficient_in_place_swap<T>() -> bool {
|
|||
mem::size_of::<T>() <= 8 // mem::size_of::<u64>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_info() {
|
||||
assert!(has_efficient_in_place_swap::<i32>());
|
||||
assert!(has_efficient_in_place_swap::<u64>());
|
||||
assert!(!has_efficient_in_place_swap::<u128>());
|
||||
assert!(!has_efficient_in_place_swap::<String>());
|
||||
}
|
||||
|
||||
/// SAFETY: Only used for run-time optimization heuristic.
|
||||
#[rustc_unsafe_specialization_marker]
|
||||
trait CopyMarker {}
|
||||
|
|
|
@ -256,12 +256,3 @@ const fn has_direct_interior_mutability<T>() -> bool {
|
|||
// Otherwise a type like Mutex<Option<Box<str>>> could lead to double free.
|
||||
!T::is_freeze()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn freeze_check() {
|
||||
assert!(!has_direct_interior_mutability::<u32>());
|
||||
assert!(!has_direct_interior_mutability::<[u128; 2]>());
|
||||
|
||||
assert!(has_direct_interior_mutability::<crate::cell::Cell<u32>>());
|
||||
assert!(has_direct_interior_mutability::<crate::sync::Mutex<u32>>());
|
||||
}
|
||||
|
|
|
@ -325,6 +325,8 @@ struct GapGuard<T> {
|
|||
|
||||
impl<T> Drop for GapGuard<T> {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into
|
||||
// `self.pos` sound.
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(&*self.value, self.pos, 1);
|
||||
}
|
||||
|
@ -340,6 +342,8 @@ struct GapGuardRaw<T> {
|
|||
|
||||
impl<T> Drop for GapGuardRaw<T> {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into
|
||||
// `self.pos` sound.
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(self.value, self.pos, 1);
|
||||
}
|
||||
|
|
|
@ -1803,7 +1803,6 @@ fn brute_force_rotate_test_1() {
|
|||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn sort_unstable() {
|
||||
// use core::cmp::Ordering::{Equal, Greater, Less};
|
||||
use rand::Rng;
|
||||
|
||||
// Miri is too slow (but still need to `chain` to make the types match)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# `sort_internals`
|
||||
|
||||
This feature is internal to the Rust compiler and is not intended for general use.
|
||||
|
||||
------------------------
|
Loading…
Add table
Add a link
Reference in a new issue