Skip to content

Commit

Permalink
avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 12, 2023
1 parent ec46918 commit 844993d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test() {
snd: isize,
}
let mut p = Pair { fst: 10, snd: 20 };
let pptr: *mut Pair = &mut p;
let pptr: *mut Pair = addr_of_mut!(p);
let iptr: *mut isize = pptr as *mut isize;
assert_eq!(*iptr, 10);
*iptr = 30;
Expand Down Expand Up @@ -1070,8 +1070,8 @@ fn swap_copy_untyped() {
let mut x = 5u8;
let mut y = 6u8;

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

unsafe {
ptr::swap(ptr1, ptr2);
Expand Down

0 comments on commit 844993d

Please sign in to comment.