Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub struct Bump<const MIN_ALIGN: usize = 1> {
}

#[repr(C)]
#[repr(align(16))]
#[derive(Debug)]
struct ChunkFooter {
// Pointer to the start of this chunk allocation. This footer is always at
Expand Down Expand Up @@ -475,10 +476,10 @@ const SUPPORTED_ITER_ALIGNMENT: usize = 16;
const CHUNK_ALIGN: usize = SUPPORTED_ITER_ALIGNMENT;
const FOOTER_SIZE: usize = mem::size_of::<ChunkFooter>();

// Assert that `ChunkFooter` is at most the supported alignment. This will give a
// Assert that `ChunkFooter` is at the supported alignment. This will give a
// compile time error if it is not the case
const _FOOTER_ALIGN_ASSERTION: () = {
assert!(mem::align_of::<ChunkFooter>() <= CHUNK_ALIGN);
assert!(mem::align_of::<ChunkFooter>() == CHUNK_ALIGN);
};

// Maximum typical overhead per allocation imposed by allocators.
Expand Down Expand Up @@ -908,7 +909,7 @@ impl<const MIN_ALIGN: usize> Bump<MIN_ALIGN> {
let ptr = round_mut_ptr_down_to(footer_ptr.cast::<u8>(), MIN_ALIGN);
debug_assert_eq!(ptr as usize % MIN_ALIGN, 0);
debug_assert!(
data.as_ptr() < ptr,
data.as_ptr() <= ptr,
"bump pointer {ptr:#p} should still be greater than or equal to the \
start of the bump chunk {data:#p}"
);
Expand Down Expand Up @@ -1908,7 +1909,6 @@ impl<const MIN_ALIGN: usize> Bump<MIN_ALIGN> {
is_pointer_aligned_to(ptr, MIN_ALIGN),
"bump pointer {ptr:#p} should be aligned to the minimum alignment of {MIN_ALIGN:#x}"
);

// This `match` should be boiled away by LLVM: `MIN_ALIGN` is a
// constant and the layout's alignment is also constant in practice
// after inlining.
Expand Down
13 changes: 13 additions & 0 deletions tests/all/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,16 @@ fn bump_is_send() {
fn assert_send(_: impl Send) {}
assert_send(Bump::new());
}

#[test]
fn test_debug_assert_data_le_bump_ptr_pr_313() {
let bump = Bump::new();
bump.set_allocation_limit(Some(1));
bump.alloc_layout(Layout::from_size_align(0, 16).unwrap());
}

#[test]
fn test_debug_assert_ptr_align_pr_313() {
let bump = Bump::<16>::with_min_align();
bump.alloc(0u8);
}