Skip to content

Commit 1c4af67

Browse files
Rollup merge of #158634 - nnethercote:add-missing-needs_drop, r=Nadrieril
Add missing `needs_drop` check to `DroplessArena`. Three of the four public allocation functions in `DroplessArena` check that the allocated type doesn't implement `Drop`: `alloc`, `alloc_slice`, `alloc_from_iter`. This commit adds the missing check to `try_alloc_from_iter`. It also moves and reorders some lines in `alloc_from_iter` for consistency with the other methods. r? @Nadrieril
2 parents ca693dc + c6f92dc commit 1c4af67

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • compiler/rustc_arena/src

compiler/rustc_arena/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,12 @@ impl DroplessArena {
542542

543543
#[inline]
544544
pub fn alloc_from_iter<T, I: IntoIterator<Item = T>>(&self, iter: I) -> &mut [T] {
545+
assert!(!mem::needs_drop::<T>());
546+
assert!(size_of::<T>() != 0);
547+
545548
// Warning: this function is reentrant: `iter` could hold a reference to `&self` and
546549
// allocate additional elements while we're iterating.
547550
let iter = iter.into_iter();
548-
assert!(size_of::<T>() != 0);
549-
assert!(!mem::needs_drop::<T>());
550551

551552
let size_hint = iter.size_hint();
552553

@@ -577,6 +578,7 @@ impl DroplessArena {
577578
) -> Result<&mut [T], E> {
578579
// Despite the similarity with `alloc_from_iter`, we cannot reuse their fast case, as we
579580
// cannot know the minimum length of the iterator in this case.
581+
assert!(!mem::needs_drop::<T>());
580582
assert!(size_of::<T>() != 0);
581583

582584
// Takes care of reentrancy.

0 commit comments

Comments
 (0)