@@ -568,10 +568,13 @@ impl Drop for DropType {
568
568
}
569
569
570
570
/// An arena which can be used to allocate any type.
571
+ ///
572
+ /// # Safety
573
+ ///
571
574
/// Allocating in this arena is unsafe since the type system
572
575
/// 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.
575
578
#[ derive( Default ) ]
576
579
pub struct DropArena {
577
580
/// A list of destructors to run when the arena drops.
@@ -589,7 +592,7 @@ impl DropArena {
589
592
ptr:: write ( mem, object) ;
590
593
let result = & mut * mem;
591
594
// 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.
593
596
self . destructors
594
597
. borrow_mut ( )
595
598
. push ( DropType { drop_fn : drop_for_type :: < T > , obj : result as * mut T as * mut u8 } ) ;
@@ -607,16 +610,16 @@ impl DropArena {
607
610
let start_ptr = self . arena . alloc_raw ( Layout :: array :: < T > ( len) . unwrap ( ) ) as * mut T ;
608
611
609
612
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.
611
614
destructors. reserve ( len) ;
612
615
613
616
// Move the content to the arena by copying it and then forgetting
614
- // the content of the SmallVec
617
+ // the content of the SmallVec.
615
618
vec. as_ptr ( ) . copy_to_nonoverlapping ( start_ptr, len) ;
616
619
mem:: forget ( vec. drain ( ..) ) ;
617
620
618
621
// 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.
620
623
for i in 0 ..len {
621
624
destructors
622
625
. push ( DropType { drop_fn : drop_for_type :: < T > , obj : start_ptr. add ( i) as * mut u8 } ) ;
0 commit comments