Skip to content

Commit 1c3841e

Browse files
committed
Edit rustc_arena::DropArena docs
- Add a "Safety" section, edit formatting for clarity - Add missing punctuation in code comments
1 parent 3c10a88 commit 1c3841e

File tree

1 file changed

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

1 file changed

+9
-6
lines changed

compiler/rustc_arena/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,13 @@ impl Drop for DropType {
568568
}
569569

570570
/// An arena which can be used to allocate any type.
571+
///
572+
/// # Safety
573+
///
571574
/// Allocating in this arena is unsafe since the type system
572575
/// doesn't know which types it contains. In order to
573-
/// allocate safely, you must store a PhantomData<T>
574-
/// alongside this arena for each type T you allocate.
576+
/// allocate safely, you must store a `PhantomData<T>`
577+
/// alongside this arena for each type `T` you allocate.
575578
#[derive(Default)]
576579
pub struct DropArena {
577580
/// A list of destructors to run when the arena drops.
@@ -589,7 +592,7 @@ impl DropArena {
589592
ptr::write(mem, object);
590593
let result = &mut *mem;
591594
// Record the destructor after doing the allocation as that may panic
592-
// and would cause `object`'s destructor to run twice if it was recorded before
595+
// and would cause `object`'s destructor to run twice if it was recorded before.
593596
self.destructors
594597
.borrow_mut()
595598
.push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
@@ -607,16 +610,16 @@ impl DropArena {
607610
let start_ptr = self.arena.alloc_raw(Layout::array::<T>(len).unwrap()) as *mut T;
608611

609612
let mut destructors = self.destructors.borrow_mut();
610-
// Reserve space for the destructors so we can't panic while adding them
613+
// Reserve space for the destructors so we can't panic while adding them.
611614
destructors.reserve(len);
612615

613616
// Move the content to the arena by copying it and then forgetting
614-
// the content of the SmallVec
617+
// the content of the SmallVec.
615618
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
616619
mem::forget(vec.drain(..));
617620

618621
// Record the destructors after doing the allocation as that may panic
619-
// and would cause `object`'s destructor to run twice if it was recorded before
622+
// and would cause `object`'s destructor to run twice if it was recorded before.
620623
for i in 0..len {
621624
destructors
622625
.push(DropType { drop_fn: drop_for_type::<T>, obj: start_ptr.add(i) as *mut u8 });

0 commit comments

Comments
 (0)