Skip to content

Commit c3a2e7a

Browse files
committed
avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs
1 parent 2b3f260 commit c3a2e7a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/core/tests/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn test() {
2525
snd: isize,
2626
}
2727
let mut p = Pair { fst: 10, snd: 20 };
28-
let pptr: *mut Pair = &mut p;
28+
let pptr: *mut Pair = addr_of_mut!(p);
2929
let iptr: *mut isize = pptr as *mut isize;
3030
assert_eq!(*iptr, 10);
3131
*iptr = 30;
@@ -1070,8 +1070,8 @@ fn swap_copy_untyped() {
10701070
let mut x = 5u8;
10711071
let mut y = 6u8;
10721072

1073-
let ptr1 = &mut x as *mut u8 as *mut bool;
1074-
let ptr2 = &mut y as *mut u8 as *mut bool;
1073+
let ptr1 = addr_of_mut!(x).cast::<bool>();
1074+
let ptr2 = addr_of_mut!(y).cast::<bool>();
10751075

10761076
unsafe {
10771077
ptr::swap(ptr1, ptr2);

0 commit comments

Comments
 (0)