1
Fork 0

libs: use assert_unchecked instead of intrinsic

This commit is contained in:
joboet 2024-01-13 20:10:00 +01:00
parent 174e73a3f6
commit fa9a911a57
No known key found for this signature in database
GPG key ID: 704E0149B0194B3C
15 changed files with 28 additions and 22 deletions

View file

@ -3,7 +3,7 @@
#![stable(feature = "alloc_module", since = "1.28.0")]
#[cfg(not(test))]
use core::intrinsics;
use core::hint;
#[cfg(not(test))]
use core::ptr::{self, NonNull};
@ -208,7 +208,7 @@ impl Global {
let new_size = new_layout.size();
// `realloc` probably checks for `new_size >= old_layout.size()` or something similar.
intrinsics::assume(new_size >= old_layout.size());
hint::assert_unchecked(new_size >= old_layout.size());
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
@ -299,7 +299,7 @@ unsafe impl Allocator for Global {
// SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller
new_size if old_layout.align() == new_layout.align() => unsafe {
// `realloc` probably checks for `new_size <= old_layout.size()` or something similar.
intrinsics::assume(new_size <= old_layout.size());
hint::assert_unchecked(new_size <= old_layout.size());
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;