Skip to content

Commit

Permalink
pointer::wrapping_byte_sub is now stable
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed May 4, 2024
1 parent 9fec66c commit 85ed4e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions crates/rune-alloc/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ pub const fn invalid_mut<T>(addr: usize) -> *mut T {
unsafe { mem::transmute(addr) }
}

cfg_if! {
if #[cfg(rune_nightly)] {
#[inline(always)]
pub(crate) const fn wrapping_byte_sub<T>(ptr: *const T, count: usize) -> *const T {
ptr.cast::<u8>().wrapping_sub(count).with_metadata_of(ptr)
}
} else {
#[inline(always)]
pub(crate) const fn wrapping_byte_sub<T>(ptr: *const T, count: usize) -> *const T {
// TODO: We need to use metadata.
ptr.cast::<u8>().wrapping_sub(count) as *const T
}
}
}

cfg_if! {
if #[cfg(rune_nightly)] {
#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions crates/rune-alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
} else if T::IS_ZST {
// `ptr` has to stay where it is to remain aligned, so we reduce the length by 1 by
// reducing the `end`.
self.end = ptr::wrapping_byte_sub(self.end, 1);
self.end = self.end.wrapping_byte_sub(1);

// Make up a value of this ZST.
Some(unsafe { mem::zeroed() })
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
None
} else if T::IS_ZST {
// See above for why 'ptr.offset' isn't used
self.end = ptr::wrapping_byte_sub(self.end, 1);
self.end = self.end.wrapping_byte_sub(1);

// Make up a value of this ZST.
Some(unsafe { mem::zeroed() })
Expand Down

0 comments on commit 85ed4e1

Please sign in to comment.