Make grow_impl unsafe

This commit is contained in:
Tim Diekmann 2020-08-18 15:22:10 +02:00
parent 66a651244e
commit 63d241a7b7
2 changed files with 12 additions and 6 deletions

View file

@ -175,8 +175,9 @@ impl Global {
}
}
// Safety: Same as `AllocRef::grow`
#[inline]
fn grow_impl(
unsafe fn grow_impl(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
@ -241,7 +242,8 @@ unsafe impl AllocRef for Global {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, false)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, false) }
}
#[inline]
@ -251,7 +253,8 @@ unsafe impl AllocRef for Global {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, true)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, true) }
}
#[inline]

View file

@ -149,8 +149,9 @@ impl System {
}
}
// Safety: Same as `AllocRef::grow`
#[inline]
fn grow_impl(
unsafe fn grow_impl(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
@ -217,7 +218,8 @@ unsafe impl AllocRef for System {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, false)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, false) }
}
#[inline]
@ -227,7 +229,8 @@ unsafe impl AllocRef for System {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, true)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, true) }
}
#[inline]