From 3842c0ac70b515f480a19812edd6ee8dea53bf58 Mon Sep 17 00:00:00 2001 From: Divyansh Patel Date: Mon, 2 Nov 2026 13:28:12 +0530 Subject: [PATCH 1/3] rename in lib.rs & files using DropGuard --- src/iterators/intoiter.rs | 22 ++++---- src/lib.rs | 110 +++++++++++++++++++------------------- src/specialization.rs | 16 +++--- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/iterators/intoiter.rs b/src/iterators/intoiter.rs index b02baa91..f77729aa 100644 --- a/src/iterators/intoiter.rs +++ b/src/iterators/intoiter.rs @@ -74,8 +74,8 @@ impl AsRef<[Item]> for IntoIter AsMut<[Item]> for IntoIter Iterator for IntoIter DoubleEndedIterator } else { // SAFETY: see above unsafe { - let ptr = self.raw.as_mut_ptr(on_heap); + let pointer = self.raw.as_mut_ptr(on_heap); self.end.sub(1); - let value = ptr.add(end - 1).read(); + let value = pointer.add(end - 1).read(); Some(value) } } @@ -175,11 +175,11 @@ impl Drop for IntoIter(), align: align_of::(), allocator: &self.allocator @@ -187,7 +187,7 @@ impl Drop for IntoIter SmallVec { // SAFETY: `length < capacity` after the reserve, // so the offset stays in bounds of the allocation. - let ptr = unsafe { self.as_mut_ptr().add(length) }; + let pointer = unsafe { self.as_mut_ptr().add(length) }; // SAFETY: we allocated enough space in case it wasn't enough, so the // address is valid for writes. - unsafe { ptr.write(value) }; + unsafe { pointer.write(value) }; // LEGAL: all elements in `0..length + 1` are initialized. { @@ -574,10 +574,10 @@ impl SmallVec { } } - // SAFETY: `ptr` is aligned, non-null and points to the element + // SAFETY: `pointer` is aligned, non-null and points to the element // initialized above; the borrow is tied to `&mut self`, // so it is exclusive. - unsafe { &mut *ptr } + unsafe { &mut *pointer } } #[inline] @@ -616,11 +616,11 @@ impl SmallVec { } // SAFETY: see `Self::push` - let ptr = unsafe { self.as_mut_ptr().add(length) }; + let pointer = unsafe { self.as_mut_ptr().add(length) }; unsafe { other.set_len(0) } // SAFETY: we have a mutable reference to each vector and each uniquely // owns its memory. so the ranges can't overlap - unsafe { copy_nonoverlapping(other.as_ptr(), ptr, other_len) }; + unsafe { copy_nonoverlapping(other.as_ptr(), pointer, other_len) }; unsafe { self.length.add(other_len) } } @@ -660,14 +660,14 @@ impl SmallVec { if on_heap { unsafe { // SAFETY: heap member is active - let (ptr, old_cap) = self.raw.heap; + let (pointer, old_cap) = self.raw.heap; // inline member is now active // SAFETY: length <= new_capacity <= Self::inline_size() // so the copy is within bounds of the inline member - copy_nonoverlapping(ptr.as_ptr(), self.raw.as_mut_ptr_inline(), length); + copy_nonoverlapping(pointer.as_ptr(), self.raw.as_mut_ptr_inline(), length); drop(DropDealloc { - ptr: ptr.cast(), + pointer: pointer.cast(), size_bytes: old_cap * size_of::(), align: align_of::(), allocator: &self.allocator @@ -738,12 +738,12 @@ impl SmallVec { if length <= Self::inline_size() { // SAFETY: on_heap is true, so we're on the heap unsafe { - let (ptr, capacity) = self.raw.heap; - copy_nonoverlapping(ptr.as_ptr(), self.raw.as_mut_ptr_inline(), length); + let (pointer, capacity) = self.raw.heap; + copy_nonoverlapping(pointer.as_ptr(), self.raw.as_mut_ptr_inline(), length); self.length.set_location::(); Allocator::deallocate( &self.allocator, - ptr.cast(), + pointer.cast(), Layout::from_size_align_unchecked( capacity * size_of::(), align_of::() @@ -776,12 +776,12 @@ impl SmallVec { if target <= Self::inline_size() { // SAFETY: on_heap is true, so we're on the heap unsafe { - let (ptr, capacity) = self.raw.heap; - copy_nonoverlapping(ptr.as_ptr(), self.raw.as_mut_ptr_inline(), length); + let (pointer, capacity) = self.raw.heap; + copy_nonoverlapping(pointer.as_ptr(), self.raw.as_mut_ptr_inline(), length); self.length.set_location::(); Allocator::deallocate( &self.allocator, - ptr.cast(), + pointer.cast(), Layout::from_size_align_unchecked( capacity * size_of::(), align_of::() @@ -873,8 +873,8 @@ impl SmallVec { unsafe { // SAFETY: new_len < length self.length.sub(1); - let ptr = self.as_mut_ptr(); - let ith = ptr.add(index); + let pointer = self.as_mut_ptr(); + let ith = pointer.add(index); // This item is initialized since index < length let ith_item = ith.read(); copy(ith.add(1), ith, new_len - index); @@ -908,7 +908,7 @@ impl SmallVec { // SAFETY: `index <= length <= capacity`, // so the offset stays in bounds of the allocation. - let ptr = unsafe { self.as_mut_ptr().add(index) }; + let pointer = unsafe { self.as_mut_ptr().add(index) }; if index < length { // SAFETY: `reserve(1)` guarantees capacity for `length + 1` @@ -916,11 +916,11 @@ impl SmallVec { // elements one slot up stays in bounds. Source // and destination overlap, hence `copy` instead of // `copy_nonoverlapping`. - unsafe { copy(ptr, ptr.add(1), length - index) }; + unsafe { copy(pointer, pointer.add(1), length - index) }; } // SAFETY: the slot at `index` is free and properly aligned for `Item`. - unsafe { ptr.write(value) }; + unsafe { pointer.write(value) }; // LEGAL: all elements in `0..length + 1` are initialized. { @@ -934,10 +934,10 @@ impl SmallVec { } } - // SAFETY: `ptr` is aligned, non-null and points to the element + // SAFETY: `pointer` is aligned, non-null and points to the element // initialized above; the borrow is tied to `&mut self`, // so it is exclusive. - unsafe { &mut *ptr } + unsafe { &mut *pointer } } #[deprecated( @@ -998,10 +998,10 @@ impl SmallVec { unsafe { this.set_len(0); } - let ptr = this.as_ptr() as *const [Item; INLINE]; + let pointer = this.as_ptr() as *const [Item; INLINE]; // SAFETY: these elements are initialized since the length was // `INLINE` - unsafe { Ok(ptr.read()) } + unsafe { Ok(pointer.read()) } } } @@ -1045,8 +1045,8 @@ impl SmallVec { // SAFETY: Trailing unchecked items must be valid since we never // touch them. unsafe { - let ptr = self.v.as_mut_ptr(); - copy(ptr.add(self.read), ptr.add(self.write), remaining); + let pointer = self.v.as_mut_ptr(); + copy(pointer.add(self.read), pointer.add(self.write), remaining); } // SAFETY: After filling holes, all items are in contiguous // memory. @@ -1082,10 +1082,10 @@ impl SmallVec { // SAFETY: previous `read` is always less than original_len. unsafe { drop_in_place(g.v.as_mut_ptr().add(read)) } - let ptr = g.v.as_mut_ptr(); + let pointer = g.v.as_mut_ptr(); while g.read < g.original_len { // SAFETY: `read` is always less than original_len. - let cur = unsafe { &mut *ptr.add(g.read) }; + let cur = unsafe { &mut *pointer.add(g.read) }; if !f(cur) { // Advance `read` early to avoid double drop if `drop_in_place` // panicked. @@ -1097,7 +1097,7 @@ impl SmallVec { // We use copy for move, and never touch the source element // again. unsafe { - let hole = ptr.add(g.write); + let hole = pointer.add(g.write); copy_nonoverlapping(cur, hole, 1); } g.write += 1; @@ -1137,13 +1137,13 @@ impl SmallVec { return; } - let ptr = self.as_mut_ptr(); + let pointer = self.as_mut_ptr(); let mut w: usize = 1; unsafe { for r in 1..length { - let p_r = ptr.add(r); - let p_wm1 = ptr.add(w - 1); + let p_r = pointer.add(r); + let p_wm1 = pointer.add(w - 1); if !same_bucket(&mut *p_r, &mut *p_wm1) { if r != w { let p_w = p_wm1.add(1); @@ -1235,8 +1235,8 @@ impl SmallVec { // `core::slice::range`. unsafe { let l = self.len(); - let ptr = self.as_mut_ptr(); - copy_nonoverlapping(ptr.add(start), ptr.add(l), length); + let pointer = self.as_mut_ptr(); + copy_nonoverlapping(pointer.add(start), pointer.add(l), length); self.length.add(length); } } @@ -1427,20 +1427,20 @@ impl SmallVec { - ptr: *mut Item, + pointer: *mut Item, length: usize } impl Drop for DropGuard { #[inline] fn drop(&mut self) { unsafe { - slice_from_raw_parts_mut(self.ptr, self.length).drop_in_place(); + slice_from_raw_parts_mut(self.pointer, self.length).drop_in_place(); } } } struct DropDealloc<'valid, Heap: Allocator> { - ptr: NonNull, + pointer: NonNull, size_bytes: usize, align: usize, allocator: &'valid Heap @@ -1453,7 +1453,7 @@ impl Drop for DropDealloc<'_, Heap> { if self.size_bytes > 0 { Allocator::deallocate( self.allocator, - self.ptr, + self.pointer, Layout::from_size_align_unchecked(self.size_bytes, self.align) ); } @@ -1468,13 +1468,13 @@ impl<#[cfg_attr(feature = "may-dangle", may_dangle)] Item, const INLINE: usize, fn drop(&mut self) { let (length, on_heap) = self.length.parts(); // SAFETY: the tag tells which member is active - let ptr = unsafe { self.raw.as_mut_ptr(on_heap) }; + let pointer = unsafe { self.raw.as_mut_ptr(on_heap) }; // SAFETY: see above unsafe { let _drop_dealloc = if on_heap { let capacity = self.raw.heap.1; Some(DropDealloc { - ptr: NonNull::new_unchecked(ptr as *mut u8), + pointer: NonNull::new_unchecked(pointer as *mut u8), size_bytes: capacity * size_of::(), align: align_of::(), allocator: &self.allocator @@ -1482,7 +1482,7 @@ impl<#[cfg_attr(feature = "may-dangle", may_dangle)] Item, const INLINE: usize, } else { None }; - slice_from_raw_parts_mut(ptr, length).drop_in_place(); + slice_from_raw_parts_mut(pointer, length).drop_in_place(); } } } @@ -1532,9 +1532,9 @@ impl SmallVec { let mut result = Self::new(); if n > 0 { - let ptr = result.raw.as_mut_ptr_inline(); + let pointer = result.raw.as_mut_ptr_inline(); let mut guard = DropGuard { - ptr, + pointer, length: 0 }; @@ -1542,11 +1542,11 @@ impl SmallVec { // is smaller than the inline size. unsafe { for i in 0..(n - 1) { - ptr.add(i).write(elem.clone()); + pointer.add(i).write(elem.clone()); guard.length += 1; } forget(guard); - ptr.add(n - 1).write(elem); + pointer.add(n - 1).write(elem); } } @@ -1585,7 +1585,7 @@ impl SmallVec { // than or equal to the inline length. unsafe { let mut guard = DropGuard { - ptr: destination, + pointer: destination, length: 0 }; for i in 0..length { @@ -1646,12 +1646,12 @@ impl SmallVec { // for at least `source.len()` elements. This implies that the loop // operates on valid memory. unsafe { - let ptr = self.as_mut_ptr(); - let destination = ptr.add(old_len); - let source = ptr.add(start); + let pointer = self.as_mut_ptr(); + let destination = pointer.add(old_len); + let source = pointer.add(start); let mut guard = DropGuard { - ptr: destination, + pointer: destination, length: 0 }; for i in 0..length { @@ -1895,11 +1895,11 @@ unsafe impl BufMut for SmallVec SpecFromElem for SmallVec 0 { - let ptr = result.raw.as_mut_ptr_inline(); + let pointer = result.raw.as_mut_ptr_inline(); // SAFETY: The caller ensures that the first `n` // is smaller than the inline size. unsafe { for i in 0..n { - ptr.add(i).write(elem); + pointer.add(i).write(elem); } } } @@ -95,14 +95,14 @@ where I: TrustedLen // operate on valid memory. unsafe { let length = self.len(); - let ptr = self.as_mut_ptr().add(length); + let pointer = self.as_mut_ptr().add(length); let mut guard = DropGuard { - ptr, + pointer, length: 0 }; for x in iter { - ptr.add(guard.length).write(x); + pointer.add(guard.length).write(x); guard.length += 1; } @@ -219,9 +219,9 @@ impl SpecExtendFromWithin Date: Mon, 2 Nov 2026 13:30:12 +0530 Subject: [PATCH 2/3] rename in conversions , rawsmallvec , drain & extractif --- src/conversions.rs | 19 ++++++++++--------- src/iterators/drain.rs | 12 ++++++------ src/iterators/extractif.rs | 4 ++-- src/rawsmallvec.rs | 12 ++++++------ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/conversions.rs b/src/conversions.rs index fd6a41f2..05ffb046 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -108,9 +108,9 @@ impl unsafe { this.set_len(0); } - let ptr = this.as_ptr() as *const [Item; M]; + let pointer = this.as_ptr() as *const [Item; M]; // SAFETY: these elements are initialized since the length was `M` - unsafe { Ok(ptr.read()) } + unsafe { Ok(pointer.read()) } } } } @@ -153,11 +153,11 @@ impl From< as Like>::Type> let cap = vec.capacity(); // SAFETY: vec.capacity is not `0` (checked above), so the pointer // can not dangle and thus specifically cannot be null. - let ptr = unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) }; + let pointer = unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) }; Self { length: LocatedLength::new(length, true), - raw: RawSmallVec::heap(ptr, cap), + raw: RawSmallVec::heap(pointer, cap), allocator: Global } } @@ -184,15 +184,16 @@ impl From as Like>::Type::from_raw_parts(ptr.as_ptr(), length, cap) + let (pointer, cap) = this.raw.heap; + as Like>::Type::from_raw_parts(pointer.as_ptr(), length, cap) } } } diff --git a/src/iterators/drain.rs b/src/iterators/drain.rs index 7fef4aaa..f4bf7f9b 100644 --- a/src/iterators/drain.rs +++ b/src/iterators/drain.rs @@ -113,9 +113,9 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Drop let start = source_vec.len(); let tail = self.0.tail_start; if tail != start { - let ptr = source_vec.as_mut_ptr(); - let source = ptr.add(tail); - let destination = ptr.add(start); + let pointer = source_vec.as_mut_ptr(); + let source = pointer.add(tail); + let destination = pointer.add(start); copy(source, destination, self.0.tail_len); } source_vec.length.add(self.0.tail_len); @@ -236,10 +236,10 @@ impl Drain<'_, Item, INLINE, Heap> { let new_tail_start = self.tail_start + additional; unsafe { - let ptr = vec.as_mut_ptr(); + let pointer = vec.as_mut_ptr(); copy( - ptr.add(self.tail_start), - ptr.add(new_tail_start), + pointer.add(self.tail_start), + pointer.add(new_tail_start), self.tail_len ); } diff --git a/src/iterators/extractif.rs b/src/iterators/extractif.rs index 38066b51..6131554f 100644 --- a/src/iterators/extractif.rs +++ b/src/iterators/extractif.rs @@ -117,8 +117,8 @@ where F: FnMut(&mut Item) -> bool // backshift is required to prevent a // double-drop of the last successfully // drained item prior to a panic in the predicate. - let ptr = self.vec.as_mut_ptr(); - let source = ptr.add(self.idx); + let pointer = self.vec.as_mut_ptr(); + let source = pointer.add(self.idx); let destination = source.sub(self.del); let tail_len = self.old_len - self.idx; source.copy_to(destination, tail_len); diff --git a/src/rawsmallvec.rs b/src/rawsmallvec.rs index 9b0d39b6..871d39a2 100644 --- a/src/rawsmallvec.rs +++ b/src/rawsmallvec.rs @@ -66,9 +66,9 @@ impl RawSmallVec { } #[inline] - pub const fn heap(ptr: NonNull, capacity: usize) -> Self { + pub const fn heap(pointer: NonNull, capacity: usize) -> Self { Self { - heap: (ptr, capacity) + heap: (pointer, capacity) } } @@ -141,7 +141,7 @@ impl RawSmallVec { debug_assert!(new_capacity > 0 && new_capacity >= length); // SAFETY: the tag tells which member is active - let ptr = unsafe { self.as_mut_ptr(was_on_heap) }; + let pointer = unsafe { self.as_mut_ptr(was_on_heap) }; let new_layout = Layout::array::(new_capacity).map_err(|_| SmallVecError::CapacityOverflow)?; @@ -155,7 +155,7 @@ impl RawSmallVec { let new_ptr = Allocator::allocate(allocator, new_layout) .ok_or(SmallVecError::AllocationError(new_layout))? .cast(); - unsafe { copy_nonoverlapping(ptr, new_ptr.as_ptr(), length) }; + unsafe { copy_nonoverlapping(pointer, new_ptr.as_ptr(), length) }; new_ptr } else { // use grow @@ -169,7 +169,7 @@ impl RawSmallVec { ) }; - // SAFETY: ptr was allocated with this allocator + // SAFETY: pointer was allocated with this allocator // old_layout is the same as the layout used to allocate the // previous memory block new_layout.size() is greater // than zero does not overflow when rounded up to @@ -182,7 +182,7 @@ impl RawSmallVec { ::shrink })( allocator, - NonNull::new(ptr as *mut u8).unwrap(), + NonNull::new(pointer as *mut u8).unwrap(), old_layout, new_layout ) From 24d8f42c9972f6ae7a9d0517ec775044fdcb3e1a Mon Sep 17 00:00:00 2001 From: Divyansh Patel Date: Mon, 2 Nov 2026 13:30:43 +0530 Subject: [PATCH 3/3] rename in part.rs --- tests/parts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/parts.rs b/tests/parts.rs index 24e50784..bf77ea48 100644 --- a/tests/parts.rs +++ b/tests/parts.rs @@ -13,13 +13,13 @@ fn into_from_parts_spilled() { assert_eq!(length.len(), 3); // SAFETY: `length` says on heap, so `heap` is the active member. - let (ptr, cap) = unsafe { raw.heap }; + let (pointer, cap) = unsafe { raw.heap }; assert!(cap > 1); // SAFETY: parts come straight from `into_parts`. let rebuilt = unsafe { SmallVec::::from_parts(raw, length) }; assert_eq!(rebuilt, [-1, 0, 1]); - assert_eq!(rebuilt.as_ptr(), ptr.as_ptr() as *const i32); + assert_eq!(rebuilt.as_ptr(), pointer.as_ptr() as *const i32); } #[test]