Fix tidy errors · model-checking/verify-rust-std@a44e7b3

5 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -92,7 +92,10 @@ fn partition_at_index_loop<'a, T, F>(

9292

// slice. Partition the slice into elements equal to and elements greater than the pivot.

9393

// This case is usually hit when the slice contains many duplicate elements.

9494

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) {

9699

let num_lt = partition(v, pivot_pos, &mut |a, b| !is_less(b, a));

97100
98101

// Continue sorting elements greater than the pivot. We know that `mid` contains

Original file line numberDiff line numberDiff line change

@@ -177,6 +177,8 @@ fn small_sort_fallback<T, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F

177177

fn small_sort_general<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F) {

178178

let mut stack_array = MaybeUninit::<[T; SMALL_SORT_GENERAL_SCRATCH_LEN]>::uninit();

179179
180+

// SAFETY: The memory is backed by `stack_array`, and the operation is safe as long as the len

181+

// is the same.

180182

let scratch = unsafe {

181183

slice::from_raw_parts_mut(

182184

stack_array.as_mut_ptr() as *mut MaybeUninit<T>,

@@ -327,8 +329,9 @@ where

327329

}

328330
329331

// 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+

};

332335

}

333336
334337

// 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 {

812815

mem::size_of::<T>() <= 8 // mem::size_of::<u64>()

813816

}

814817
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-
823818

/// SAFETY: Only used for run-time optimization heuristic.

824819

#[rustc_unsafe_specialization_marker]

825820

trait CopyMarker {}

Original file line numberDiff line numberDiff line change

@@ -256,12 +256,3 @@ const fn has_direct_interior_mutability<T>() -> bool {

256256

// Otherwise a type like Mutex<Option<Box<str>>> could lead to double free.

257257

!T::is_freeze()

258258

}

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 numberDiff line numberDiff line change

@@ -325,6 +325,8 @@ struct GapGuard<T> {

325325
326326

impl<T> Drop for GapGuard<T> {

327327

fn drop(&mut self) {

328+

// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into

329+

// `self.pos` sound.

328330

unsafe {

329331

ptr::copy_nonoverlapping(&*self.value, self.pos, 1);

330332

}

@@ -340,6 +342,8 @@ struct GapGuardRaw<T> {

340342
341343

impl<T> Drop for GapGuardRaw<T> {

342344

fn drop(&mut self) {

345+

// SAFETY: `self` MUST be constructed in a way that makes copying the gap value into

346+

// `self.pos` sound.

343347

unsafe {

344348

ptr::copy_nonoverlapping(self.value, self.pos, 1);

345349

}

Original file line numberDiff line numberDiff line change

@@ -1803,7 +1803,6 @@ fn brute_force_rotate_test_1() {

18031803

#[test]

18041804

#[cfg(not(target_arch = "wasm32"))]

18051805

fn sort_unstable() {

1806-

// use core::cmp::Ordering::{Equal, Greater, Less};

18071806

use rand::Rng;

18081807
18091808

// Miri is too slow (but still need to `chain` to make the types match)