File tree Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -295,17 +295,14 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
295295#[ inline]
296296#[ stable( feature = "rust1" , since = "1.0.0" ) ]
297297pub unsafe fn swap < T > ( x : * mut T , y : * mut T ) {
298- // Give ourselves some scratch space to work with
299- let mut tmp: T = mem:: uninitialized ( ) ;
298+ // Give ourselves some scratch space to work with.
299+ // We do not have to worry about drops: `MaybeUninit` does nothing when dropped.
300+ let mut tmp = MaybeUninit :: < T > :: uninitialized ( ) ;
300301
301302 // Perform the swap
302- copy_nonoverlapping ( x, & mut tmp, 1 ) ;
303+ copy_nonoverlapping ( x, tmp. as_mut_ptr ( ) , 1 ) ;
303304 copy ( y, x, 1 ) ; // `x` and `y` may overlap
304- copy_nonoverlapping ( & tmp, y, 1 ) ;
305-
306- // y and t now point to the same thing, but we need to completely forget `tmp`
307- // because it's no longer relevant.
308- mem:: forget ( tmp) ;
305+ copy_nonoverlapping ( tmp. get_ref ( ) , y, 1 ) ;
309306}
310307
311308/// Swaps `count * size_of::<T>()` bytes between the two regions of memory
You can’t perform that action at this time.
0 commit comments