This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 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> {
570570 ///
571571 /// # Safety
572572 ///
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.
575578 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).
576580 debug_assert ! (
577581 len <= self . capacity( ) ,
578582 "`len` must be smaller than or equal to `self.capacity()`"
579583 ) ;
580584
581585 let me = ManuallyDrop :: new ( self ) ;
582- // NOTE: not calling `capacity()` here; actually using the real `cap` field!
583586 let slice = slice:: from_raw_parts_mut ( me. ptr ( ) as * mut MaybeUninit < T > , len) ;
584587 Box :: from_raw ( slice)
585588 }
You can’t perform that action at this time.
0 commit comments