diff options
| author | Ralf Jung <post@ralfj.de> | 2025-08-22 10:15:57 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-08-22 10:15:57 +0200 |
| commit | 5068317842a770371d6fcbca358fdb237bd30865 (patch) | |
| tree | 99964c1c9c8416f62019e4fc24d9cbdbf88a8b2f | |
| parent | ad8b241e011b50ad6451729dee143e2a3acbbe24 (diff) | |
| download | rust-5068317842a770371d6fcbca358fdb237bd30865.tar.gz rust-5068317842a770371d6fcbca358fdb237bd30865.zip | |
add some ZST reborrow tests
| -rw-r--r-- | src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs index 6a625e597df..82976326a8d 100644 --- a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs +++ b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs @@ -23,7 +23,8 @@ fn main() { not_unpin_not_protected(); write_does_not_invalidate_all_aliases(); box_into_raw_allows_interior_mutable_alias(); - cell_inside_struct() + cell_inside_struct(); + zst(); } // Make sure that reading from an `&mut` does, like reborrowing to `&`, @@ -287,3 +288,22 @@ fn cell_inside_struct() { // Writing to `field1`, which is reserved, should also be allowed. (*a).field1 = 88; } + +/// ZST reborrows on various kinds of dangling pointers are valid. +fn zst() { + unsafe { + // Integer pointer. + let ptr = ptr::without_provenance_mut::<()>(15); + let _ref = &mut *ptr; + + // Out-of-bounds pointer. + let mut b = Box::new(0u8); + let ptr = (&raw mut *b).wrapping_add(15) as *mut (); + let _ref = &mut *ptr; + + // Deallocated pointer. + let ptr = &raw mut *b as *mut (); + drop(b); + let _ref = &mut *ptr; + } +} |
