Skip to content

Commit ad218f9

Browse files
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Don't update `entries` in `TypedArena` if T does not need drop As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value. You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`. r? @oli-obk
2 parents a8a424f + 2705cae commit ad218f9

File tree

1 file changed

+6
-2
lines changed
  • compiler/rustc_arena/src

1 file changed

+6
-2
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ impl<T> TypedArena<T> {
217217
let mut chunks = self.chunks.borrow_mut();
218218
let mut new_cap;
219219
if let Some(last_chunk) = chunks.last_mut() {
220-
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
221-
last_chunk.entries = used_bytes / mem::size_of::<T>();
220+
// If a type is `!needs_drop`, we don't need to keep track of how many elements
221+
// the chunk stores - the field will be ignored anyway.
222+
if mem::needs_drop::<T>() {
223+
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
224+
last_chunk.entries = used_bytes / mem::size_of::<T>();
225+
}
222226

223227
// If the previous chunk's len is less than HUGE_PAGE
224228
// bytes, then this chunk will be least double the previous

0 commit comments

Comments
 (0)