diff options
| -rw-r--r-- | library/alloc/src/alloc.rs | 9 | ||||
| -rw-r--r-- | library/std/src/alloc.rs | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 4f25b713d75..fa5eb1823f1 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -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] diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index bc895640fd2..b4009c86419 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -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] |
