Fix tidy errors · model-checking/verify-rust-std@a44e7b3 (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -92,7 +92,10 @@ fn partition_at_index_loop<'a, T, F>(
92 92 // slice. Partition the slice into elements equal to and elements greater than the pivot.
93 93 // This case is usually hit when the slice contains many duplicate elements.
94 94 if let Some(p) = ancestor_pivot {
95 -if !is_less(p, unsafe { v.get_unchecked(pivot_pos) }) {
95 +// SAFETY: choose_pivot promises to return a valid pivot position.
96 +let pivot = unsafe { v.get_unchecked(pivot_pos) };
97 +
98 +if !is_less(p, pivot) {
96 99 let num_lt = partition(v, pivot_pos, &mut |a, b
97 100
98 101 // Continue sorting elements greater than the pivot. We know that `mid` contains
Original file line number Diff line number Diff line change
@@ -177,6 +177,8 @@ fn small_sort_fallback<T, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F
177 177 fn small_sort_general<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F) {
178 178 let mut stack_array = MaybeUninit::<[T; SMALL_SORT_GENERAL_SCRATCH_LEN]>::uninit();
179 179
180 +// SAFETY: The memory is backed by `stack_array`, and the operation is safe as long as the len
181 +// is the same.
180 182 let scratch = unsafe {
181 183 slice::from_raw_parts_mut(
182 184 stack_array.as_mut_ptr() as *mut MaybeUninit<T>,
@@ -327,8 +329,9 @@ where
327 329 }
328 330
329 331 // SAFETY: The right side of `v` based on `len_div_2` is guaranteed in-bounds.
330 - region =
331 -unsafe { &mut *ptr::slice_from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2) };
332 +unsafe {
333 + region = &mut *ptr::slice_from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2)
334 +};
332 335 }
333 336
334 337 // SAFETY: We checked that T is Freeze and thus observation safe.
@@ -812,14 +815,6 @@ pub(crate) const fn has_efficient_in_place_swap() -> bool {
812 815 mem::size_of::<T>() <= 8 // mem::size_of::()
813 816 }
814 817
815 -#[test]
816 -fn type_info() {
817 -assert!(has_efficient_in_place_swap::<i32>());
818 -assert!(has_efficient_in_place_swap::<u64>());
819 -assert!(!has_efficient_in_place_swap::<u128>());
820 -assert!(!has_efficient_in_place_swap::<String>());
821 -}
822 -
823 818 /// SAFETY: Only used for run-time optimization heuristic.
824 819 #[rustc_unsafe_specialization_marker]
825 820 trait CopyMarker {}
Original file line number Diff line number Diff line change
@@ -256,12 +256,3 @@ const fn has_direct_interior_mutability() -> bool {
256 256 // Otherwise a type like Mutex<Option<Box>> could lead to double free.
257 257 !T::is_freeze()
258 258 }
259 -
260 -#[test]
261 -fn freeze_check() {
262 -assert!(!has_direct_interior_mutability::<u32>());
263 -assert!(!has_direct_interior_mutability::<[u128; 2]>());
264 -
265 -assert!(has_direct_interior_mutability::<crate::cell::Cell<u32>>());
266 -assert!(has_direct_interior_mutability::<crate::sync::Mutex<u32>>());
267 -}
Original file line number Diff line number Diff line change
@@ -325,6 +325,8 @@ struct GapGuard {
325 325
326 326 impl<T> Drop for GapGuard<T> {
327 327 fn drop(&mut self) {
328 +// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into
329 +// `self.pos` sound.
328 330 unsafe {
329 331 ptr::copy_nonoverlapping(&*self.value, self.pos, 1);
330 332 }
@@ -340,6 +342,8 @@ struct GapGuardRaw {
340 342
341 343 impl<T> Drop for GapGuardRaw<T> {
342 344 fn drop(&mut self) {
345 +// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into
346 +// `self.pos` sound.
343 347 unsafe {
344 348 ptr::copy_nonoverlapping(self.value, self.pos, 1);
345 349 }
Original file line number Diff line number Diff line change
@@ -1803,7 +1803,6 @@ fn brute_force_rotate_test_1() {
1803 1803 #[test]
1804 1804 #[cfg(not(target_arch = "wasm32"))]
1805 1805 fn sort_unstable() {
1806 -// use core::cmp::Ordering::{Equal, Greater, Less};
1807 1806 use rand::Rng;
1808 1807
1809 1808 // Miri is too slow (but still need to `chain` to make the types match)