Skip to content

Commit 07929ca

Browse files
committed
work around dubious const eval error
1 parent 3e245fa commit 07929ca

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

library/core/src/intrinsics.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2538,14 +2538,15 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
25382538
!ptr.is_null() && ptr.is_aligned()
25392539
}
25402540

2541+
const fn max_len<T>() -> usize {
2542+
let size = crate::mem::size_of::<T>();
2543+
if size == 0 { usize::MAX } else { isize::MAX as usize / size }
2544+
}
2545+
25412546
/// Checks whether an allocation of `len` instances of `T` exceeds
25422547
/// the maximum allowed allocation size.
25432548
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
2544-
let max_len = const {
2545-
let size = crate::mem::size_of::<T>();
2546-
if size == 0 { usize::MAX } else { isize::MAX as usize / size }
2547-
};
2548-
len <= max_len
2549+
len <= max_len::<T>()
25492550
}
25502551

25512552
/// Checks whether the regions of memory starting at `src` and `dst` of size

0 commit comments

Comments
 (0)