File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -570,16 +570,19 @@ impl<T> RawVec<T, Global> {
570
570
///
571
571
/// # Safety
572
572
///
573
- /// `shrink_to_fit(len)` must be called immediately prior to calling this function. This
574
- /// implies, that `len` must be smaller than or equal to `self.capacity()`.
573
+ /// * `len` must be greater than or equal to the most recently requested capacity, and
574
+ /// * `len` must be less than or equal to `self.capacity()`.
575
+ ///
576
+ /// Note, that the requested capacity and `self.capacity()` could differ, as
577
+ /// an allocator could overallocate and return a greater memory block than requested.
575
578
pub unsafe fn into_box ( self , len : usize ) -> Box < [ MaybeUninit < T > ] > {
579
+ // Sanity-check one half of the safety requirement (we cannot check the other half).
576
580
debug_assert ! (
577
581
len <= self . capacity( ) ,
578
582
"`len` must be smaller than or equal to `self.capacity()`"
579
583
) ;
580
584
581
585
let me = ManuallyDrop :: new ( self ) ;
582
- // NOTE: not calling `capacity()` here; actually using the real `cap` field!
583
586
let slice = slice:: from_raw_parts_mut ( me. ptr ( ) as * mut MaybeUninit < T > , len) ;
584
587
Box :: from_raw ( slice)
585
588
}
You can’t perform that action at this time.
0 commit comments