Skip to content

Commit 46b547c

Browse files
committed
Assume same alignment in RawVec
1 parent 303ee3f commit 46b547c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/alloc/src/raw_vec.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use core::alloc::LayoutErr;
55
use core::cmp;
6+
use core::intrinsics;
67
use core::mem::{self, ManuallyDrop, MaybeUninit};
78
use core::ops::Drop;
89
use core::ptr::{NonNull, Unique};
@@ -495,7 +496,11 @@ where
495496

496497
let memory = if let Some((ptr, old_layout)) = current_memory {
497498
debug_assert_eq!(old_layout.align(), new_layout.align());
498-
unsafe { alloc.grow(ptr, old_layout, new_layout) }
499+
unsafe {
500+
// The allocator checks for alignment equality
501+
intrinsics::assume(old_layout.align() == new_layout.align());
502+
alloc.grow(ptr, old_layout, new_layout)
503+
}
499504
} else {
500505
alloc.alloc(new_layout)
501506
};

0 commit comments

Comments
 (0)