Skip to content

Commit 82cbd18

Browse files
committed
Let compiler assume, that Layout::align() is always a power of two
1 parent 1d100ba commit 82cbd18

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: library/core/src/alloc/layout.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,15 @@ impl Layout {
107107
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
108108
#[inline]
109109
pub const fn align(&self) -> usize {
110-
self.align_.get()
110+
let align = self.align_.get();
111+
if !align.is_power_of_two() {
112+
debug_assert!(false, "alignment is not a power of two");
113+
// SAFETY: align is guaranteed to be a power of two
114+
unsafe {
115+
crate::hint::unreachable_unchecked();
116+
}
117+
}
118+
align
111119
}
112120

113121
/// Constructs a `Layout` suitable for holding a value of type `T`.

0 commit comments

Comments
 (0)