Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,7 @@ impl<const MIN_ALIGN: usize> Bump<MIN_ALIGN> {
pub fn iter_allocated_chunks(&mut self) -> ChunkIter<'_, MIN_ALIGN> {
// Safety: Ensured by mutable borrow of `self`.
let raw = unsafe { self.iter_allocated_chunks_raw() };
ChunkIter {
raw,
bump: PhantomData,
}
ChunkIter { raw }
Comment on lines 2149 to +2152
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safety comment here (“Ensured by mutable borrow of self.”) becomes incorrect if ChunkIter no longer carries a PhantomData<&'a mut Bump<MIN_ALIGN>>: the iterator only keeps an immutable borrow, and Bump exposes mutation via &self (e.g., alloc, try_alloc_layout, etc.). This means allocations can occur while the safe iterator is alive, violating the safety preconditions for producing &'a [MaybeUninit<u8>].

Copilot uses AI. Check for mistakes.
}

/// Returns an iterator over raw pointers to chunks of allocated memory that
Expand Down Expand Up @@ -2388,7 +2385,6 @@ impl<const MIN_ALIGN: usize> Bump<MIN_ALIGN> {
#[derive(Debug)]
pub struct ChunkIter<'a, const MIN_ALIGN: usize = 1> {
raw: ChunkRawIter<'a, MIN_ALIGN>,
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing bump: PhantomData<&'a mut Bump<MIN_ALIGN>> from ChunkIter weakens the borrow the iterator holds to an immutable borrow via ChunkRawIter (ChunkRawIter currently uses PhantomData<&'a Bump<MIN_ALIGN>>). Since Bump has allocation APIs that take &self (interior mutability), callers can allocate while a safe ChunkIter is alive, which can invalidate the returned chunk slices and lead to UB. Keep the &'a mut Bump phantom in ChunkIter, or otherwise ensure the iterator type enforces exclusive access for the duration of iteration.

Suggested change
raw: ChunkRawIter<'a, MIN_ALIGN>,
raw: ChunkRawIter<'a, MIN_ALIGN>,
bump: PhantomData<&'a mut Bump<MIN_ALIGN>>,

Copilot uses AI. Check for mistakes.
bump: PhantomData<&'a mut Bump>,
}

impl<'a, const MIN_ALIGN: usize> Iterator for ChunkIter<'a, MIN_ALIGN> {
Expand Down
Loading