Skip to content

Commit 069074e

Browse files
authored
Merge pull request rust-lang#4538 from RalfJung/zst-rebor
add some ZST reborrow tests
2 parents dd91d77 + 5068317 commit 069074e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ fn main() {
2323
not_unpin_not_protected();
2424
write_does_not_invalidate_all_aliases();
2525
box_into_raw_allows_interior_mutable_alias();
26-
cell_inside_struct()
26+
cell_inside_struct();
27+
zst();
2728
}
2829

2930
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -287,3 +288,22 @@ fn cell_inside_struct() {
287288
// Writing to `field1`, which is reserved, should also be allowed.
288289
(*a).field1 = 88;
289290
}
291+
292+
/// ZST reborrows on various kinds of dangling pointers are valid.
293+
fn zst() {
294+
unsafe {
295+
// Integer pointer.
296+
let ptr = ptr::without_provenance_mut::<()>(15);
297+
let _ref = &mut *ptr;
298+
299+
// Out-of-bounds pointer.
300+
let mut b = Box::new(0u8);
301+
let ptr = (&raw mut *b).wrapping_add(15) as *mut ();
302+
let _ref = &mut *ptr;
303+
304+
// Deallocated pointer.
305+
let ptr = &raw mut *b as *mut ();
306+
drop(b);
307+
let _ref = &mut *ptr;
308+
}
309+
}

0 commit comments

Comments
 (0)