File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2379,6 +2379,8 @@ unsafe impl<#[may_dangle] T> Drop for Vec<T> {
2379
2379
fn drop ( & mut self ) {
2380
2380
unsafe {
2381
2381
// use drop for [T]
2382
+ // use a raw slice to refer to the elements of the vector as weakest necessary type;
2383
+ // could avoid questions of validity in certain cases
2382
2384
ptr:: drop_in_place ( ptr:: slice_from_raw_parts_mut ( self . as_mut_ptr ( ) , self . len ) )
2383
2385
}
2384
2386
// RawVec handles deallocation
@@ -2596,7 +2598,11 @@ impl<T> IntoIter<T> {
2596
2598
/// ```
2597
2599
#[ stable( feature = "vec_into_iter_as_slice" , since = "1.15.0" ) ]
2598
2600
pub fn as_mut_slice ( & mut self ) -> & mut [ T ] {
2599
- unsafe { slice:: from_raw_parts_mut ( self . ptr as * mut T , self . len ( ) ) }
2601
+ unsafe { & mut * self . as_raw_mut_slice ( ) }
2602
+ }
2603
+
2604
+ fn as_raw_mut_slice ( & mut self ) -> * mut [ T ] {
2605
+ ptr:: slice_from_raw_parts_mut ( self . ptr as * mut T , self . len ( ) )
2600
2606
}
2601
2607
}
2602
2608
@@ -2708,7 +2714,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
2708
2714
let guard = DropGuard ( self ) ;
2709
2715
// destroy the remaining elements
2710
2716
unsafe {
2711
- ptr:: drop_in_place ( guard. 0 . as_mut_slice ( ) ) ;
2717
+ ptr:: drop_in_place ( guard. 0 . as_raw_mut_slice ( ) ) ;
2712
2718
}
2713
2719
// now `guard` will be dropped and do the rest
2714
2720
}
You can’t perform that action at this time.
0 commit comments