File tree 1 file changed +5
-8
lines changed 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -26,19 +26,16 @@ pub fn id<T>(x: T) -> T { x }
26
26
pub fn swap < T > ( x : & mut T , y : & mut T ) {
27
27
unsafe {
28
28
// Give ourselves some scratch space to work with
29
- let mut tmp: T = mem:: uninit ( ) ;
30
- let t: * mut T = & mut tmp;
29
+ let mut t: T = mem:: uninit ( ) ;
31
30
32
31
// Perform the swap, `&mut` pointers never alias
33
- let x_raw: * mut T = x;
34
- let y_raw: * mut T = y;
35
- ptr:: copy_nonoverlapping_memory ( t, & * x_raw, 1 ) ;
36
- ptr:: copy_nonoverlapping_memory ( x, & * y_raw, 1 ) ;
37
- ptr:: copy_nonoverlapping_memory ( y, & * t, 1 ) ;
32
+ ptr:: copy_nonoverlapping_memory ( & mut t, & * x, 1 ) ;
33
+ ptr:: copy_nonoverlapping_memory ( x, & * y, 1 ) ;
34
+ ptr:: copy_nonoverlapping_memory ( y, & t, 1 ) ;
38
35
39
36
// y and t now point to the same thing, but we need to completely forget `tmp`
40
37
// because it's no longer relevant.
41
- cast:: forget ( tmp ) ;
38
+ cast:: forget ( t ) ;
42
39
}
43
40
}
44
41
You can’t perform that action at this time.
0 commit comments