File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 4
4
// collections, resulting in having to optimize down excess IR multiple times.
5
5
// Your performance intuition is useless. Run perf.
6
6
7
+ use crate :: assert_unsafe_precondition;
7
8
use crate :: cmp;
8
9
use crate :: error:: Error ;
9
10
use crate :: fmt;
@@ -118,6 +119,15 @@ impl Layout {
118
119
#[ inline]
119
120
#[ rustc_allow_const_fn_unstable( ptr_alignment_type) ]
120
121
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
+ ) ;
121
131
// SAFETY: the caller is required to uphold the preconditions.
122
132
unsafe { Layout { size, align : Alignment :: new_unchecked ( align) } }
123
133
}
You can’t perform that action at this time.
0 commit comments