From 8b50585b5f15cb52fdb584af5dd4536b9839a802 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Sun, 1 Sep 2024 12:26:47 -0500 Subject: Fix UB. --- crates/utils/src/pin.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 crates/utils/src/pin.rs (limited to 'crates/utils/src/pin.rs') diff --git a/crates/utils/src/pin.rs b/crates/utils/src/pin.rs deleted file mode 100644 index cdf40fd..0000000 --- a/crates/utils/src/pin.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Utilities having to do with pinning. I sure hope these are sound! - -use contracts::requires; -use core::pin::Pin; -use std::ptr::NonNull; - -/// Iterates over projections of elements out of a pinned slice. -pub fn pin_project_slice_mut_iter( - mut slice: Pin<&mut [T]>, -) -> impl Iterator> { - // SAFETY: We never move out of this pointer. - let base_ptr: NonNull = NonNull::from(unsafe { slice.as_mut().get_unchecked_mut() }).cast(); - (0..slice.len()).map(move |i| { - // SAFETY: This is in-bounds, since the original slice was valid. No other references to - // the data can exist, since we visit each index once and have an exclusive borrow on the - // slice. - let ptr = unsafe { base_ptr.add(i).as_mut() }; - // SAFETY: This is not certainly sound; see https://github.com/rust-lang/rust/issues/104108 - unsafe { Pin::new_unchecked(ptr) } - }) -} - -/// Projects a single element out of a pinned slice. -#[requires(index < slice.len())] -pub fn pin_project_slice_mut(slice: Pin<&mut [T]>, index: usize) -> Pin<&mut T> { - // SAFETY: This is not certainly sound; see https://github.com/rust-lang/rust/issues/104108 - unsafe { slice.map_unchecked_mut(|slice| &mut slice[index]) } -} -- cgit v1.2.3