Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 51edc21

Browse files
committed
Remove unsafe from TypedArena::alloc_raw_slice.
There's no good reason for it.
1 parent 55de23e commit 51edc21

File tree

1 file changed

+4
-4
lines changed
  • compiler/rustc_arena/src

1 file changed

+4
-4
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ impl<T, const N: usize> IterExt<T> for std::array::IntoIter<T, N> {
172172
return &mut [];
173173
}
174174
// Move the content to the arena by copying and then forgetting it.
175+
let start_ptr = arena.alloc_raw_slice(len);
175176
unsafe {
176-
let start_ptr = arena.alloc_raw_slice(len);
177177
self.as_slice().as_ptr().copy_to_nonoverlapping(start_ptr, len);
178178
mem::forget(self);
179179
slice::from_raw_parts_mut(start_ptr, len)
@@ -189,8 +189,8 @@ impl<T> IterExt<T> for Vec<T> {
189189
return &mut [];
190190
}
191191
// Move the content to the arena by copying and then forgetting it.
192+
let start_ptr = arena.alloc_raw_slice(len);
192193
unsafe {
193-
let start_ptr = arena.alloc_raw_slice(len);
194194
self.as_ptr().copy_to_nonoverlapping(start_ptr, len);
195195
self.set_len(0);
196196
slice::from_raw_parts_mut(start_ptr, len)
@@ -206,8 +206,8 @@ impl<A: smallvec::Array> IterExt<A::Item> for SmallVec<A> {
206206
return &mut [];
207207
}
208208
// Move the content to the arena by copying and then forgetting it.
209+
let start_ptr = arena.alloc_raw_slice(len);
209210
unsafe {
210-
let start_ptr = arena.alloc_raw_slice(len);
211211
self.as_ptr().copy_to_nonoverlapping(start_ptr, len);
212212
self.set_len(0);
213213
slice::from_raw_parts_mut(start_ptr, len)
@@ -251,7 +251,7 @@ impl<T> TypedArena<T> {
251251
}
252252

253253
#[inline]
254-
unsafe fn alloc_raw_slice(&self, len: usize) -> *mut T {
254+
fn alloc_raw_slice(&self, len: usize) -> *mut T {
255255
assert!(mem::size_of::<T>() != 0);
256256
assert!(len != 0);
257257

0 commit comments

Comments
 (0)