File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 44// collections, resulting in having to optimize down excess IR multiple times.
55// Your performance intuition is useless. Run perf.
66
7+ use crate :: assert_unsafe_precondition;
78use crate :: cmp;
89use crate :: error:: Error ;
910use crate :: fmt;
@@ -118,6 +119,15 @@ impl Layout {
118119 #[ inline]
119120 #[ rustc_allow_const_fn_unstable( ptr_alignment_type) ]
120121 pub const unsafe fn from_size_align_unchecked ( size : usize , align : usize ) -> Self {
122+ assert_unsafe_precondition ! (
123+ check_library_ub,
124+ "Layout::from_size_align_unchecked requires that align is a power of 2 \
125+ and the rounded-up allocation size does not exceed isize::MAX",
126+ (
127+ size: usize = size,
128+ align: usize = align,
129+ ) => Layout :: from_size_align( size, align) . is_ok( )
130+ ) ;
121131 // SAFETY: the caller is required to uphold the preconditions.
122132 unsafe { Layout { size, align : Alignment :: new_unchecked ( align) } }
123133 }
You can’t perform that action at this time.
0 commit comments