util: use handle_alloc_error()

This commit is contained in:
Matthias Schiffer 2020-05-01 23:57:16 +02:00
parent a205bbb1d2
commit 4f5b90400e
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -1,5 +1,9 @@
use alloc::alloc;
#[inline] #[inline]
pub fn must_succeed<T>(p: *mut T) -> *mut T { pub fn must_succeed<T>(p: *mut T) -> *mut T {
assert!(!p.is_null(), "allocation failure"); if p.is_null() {
alloc::handle_alloc_error(alloc::Layout::new::<T>())
}
p p
} }