From 51edc219906f0973dd66b4b6ff5ff0ac857a4cc6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 20 Sep 2023 07:36:19 +1000 Subject: [PATCH] Remove `unsafe` from `TypedArena::alloc_raw_slice`. There's no good reason for it. --- compiler/rustc_arena/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index a8a4ad89c4f..5c183afc087 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -172,8 +172,8 @@ impl IterExt for std::array::IntoIter { return &mut []; } // Move the content to the arena by copying and then forgetting it. + let start_ptr = arena.alloc_raw_slice(len); unsafe { - let start_ptr = arena.alloc_raw_slice(len); self.as_slice().as_ptr().copy_to_nonoverlapping(start_ptr, len); mem::forget(self); slice::from_raw_parts_mut(start_ptr, len) @@ -189,8 +189,8 @@ impl IterExt for Vec { return &mut []; } // Move the content to the arena by copying and then forgetting it. + let start_ptr = arena.alloc_raw_slice(len); unsafe { - let start_ptr = arena.alloc_raw_slice(len); self.as_ptr().copy_to_nonoverlapping(start_ptr, len); self.set_len(0); slice::from_raw_parts_mut(start_ptr, len) @@ -206,8 +206,8 @@ impl IterExt for SmallVec { return &mut []; } // Move the content to the arena by copying and then forgetting it. + let start_ptr = arena.alloc_raw_slice(len); unsafe { - let start_ptr = arena.alloc_raw_slice(len); self.as_ptr().copy_to_nonoverlapping(start_ptr, len); self.set_len(0); slice::from_raw_parts_mut(start_ptr, len) @@ -251,7 +251,7 @@ impl TypedArena { } #[inline] - unsafe fn alloc_raw_slice(&self, len: usize) -> *mut T { + fn alloc_raw_slice(&self, len: usize) -> *mut T { assert!(mem::size_of::() != 0); assert!(len != 0);