We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Layout::align()
1 parent 1d100ba commit 82cbd18Copy full SHA for 82cbd18
library/core/src/alloc/layout.rs
@@ -107,7 +107,15 @@ impl Layout {
107
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
108
#[inline]
109
pub const fn align(&self) -> usize {
110
- self.align_.get()
+ 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
119
}
120
121
/// Constructs a `Layout` suitable for holding a value of type `T`.
0 commit comments