Auto merge of #1789 - RalfJung:array-to-elem, r=RalfJung
stacked borrows: ensure array-to-elem casts behave correctly When "as"-casting an entire array, that should create a raw ptr usable for all elements in the array, even if we immediately cast to the element type.
This commit is contained in:
commit
ee8dbbc40f
2 changed files with 13 additions and 1 deletions
|
|
@ -1 +1 @@
|
|||
0309953232d9957aef4c7c5a24fcb30735b2066b
|
||||
1773f14a24c49356b384e45ebb45643bc9bef2c4
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ fn main() {
|
|||
shr_and_raw();
|
||||
disjoint_mutable_subborrows();
|
||||
raw_ref_to_part();
|
||||
array_casts();
|
||||
}
|
||||
|
||||
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
|
||||
|
|
@ -174,3 +175,14 @@ fn raw_ref_to_part() {
|
|||
assert!(typed.extra == 42);
|
||||
drop(unsafe { Box::from_raw(whole) });
|
||||
}
|
||||
|
||||
/// When casting an array reference to a raw element ptr, that should cover the whole array.
|
||||
fn array_casts() {
|
||||
let mut x: [usize; 2] = [0, 0];
|
||||
let p = &mut x as *mut usize;
|
||||
unsafe { *p.add(1) = 1; }
|
||||
|
||||
let x: [usize; 2] = [0, 1];
|
||||
let p = &x as *const usize;
|
||||
assert_eq!(unsafe { *p.add(1) }, 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue