File tree Expand file tree Collapse file tree
src/tools/miri/tests/pass/tree_borrows/implicit_writes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -596,6 +596,7 @@ impl<T> [T] {
596596 #[ inline]
597597 #[ must_use]
598598 #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
599+ #[ rustc_no_writable]
599600 pub const fn get_mut < I > ( & mut self , index : I ) -> Option < & mut I :: Output >
600601 where
601602 I : [ const ] SliceIndex < Self > ,
@@ -681,6 +682,7 @@ impl<T> [T] {
681682 #[ must_use]
682683 #[ track_caller]
683684 #[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
685+ #[ rustc_no_writable]
684686 pub const unsafe fn get_unchecked_mut < I > ( & mut self , index : I ) -> & mut I :: Output
685687 where
686688 I : [ const ] SliceIndex < Self > ,
Original file line number Diff line number Diff line change 1+ // This test reproduces the pattern used by `BorrowedCursor::as_mut`, which appears in `Socket::recv_with_flags` and `std::fs::read`.
2+ // Many crates depend on similar patterns. Before https://github.com/rust-lang/rust/pull/157202 this failed under Tree
3+ // Borrows with Implicit Writes. With the attribute `#[rustc_no_writable]` added to
4+ // `slice::get_unchecked_mut`, both this test and the affected crates work.
5+ //@compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes
6+
7+ struct BorrowedBuf < ' a > {
8+ buf : & ' a mut [ u8 ] ,
9+ }
10+
11+ impl < ' a > BorrowedBuf < ' a > {
12+ fn capacity ( & self ) -> usize {
13+ self . buf . len ( )
14+ }
15+
16+ unsafe fn as_mut ( & mut self ) -> & mut [ u8 ] {
17+ unsafe { self . buf . get_unchecked_mut ( ..) }
18+ }
19+ }
20+
21+ fn main ( ) {
22+ let mut arr = [ 0u8 ; 4 ] ;
23+ let mut buf = BorrowedBuf { buf : & mut arr } ;
24+
25+ let ptr = unsafe { buf. as_mut ( ) } . as_mut_ptr ( ) ;
26+ let _ = buf. capacity ( ) ;
27+ unsafe { ptr. write ( 42 ) ; }
28+ }
You can’t perform that action at this time.
0 commit comments