File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
src/tools/miri/tests/pass/both_borrows Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ fn main() {
23
23
not_unpin_not_protected ( ) ;
24
24
write_does_not_invalidate_all_aliases ( ) ;
25
25
box_into_raw_allows_interior_mutable_alias ( ) ;
26
- cell_inside_struct ( )
26
+ cell_inside_struct ( ) ;
27
+ zst ( ) ;
27
28
}
28
29
29
30
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -287,3 +288,22 @@ fn cell_inside_struct() {
287
288
// Writing to `field1`, which is reserved, should also be allowed.
288
289
( * a) . field1 = 88 ;
289
290
}
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
+ }
You can’t perform that action at this time.
0 commit comments