817adda794
Five of the files being skipped here are because rustfmt is buggy (see the error messages below). The others have clearly preferable manual formatting. error[internal]: left behind trailing whitespace --> tests/fail/validity/transmute_through_ptr.rs:18:18:1 | 18 | | ^^^^ | warning: rustfmt has failed to format. See previous 1 errors. error[internal]: left behind trailing whitespace --> tests/fail/stacked_borrows/illegal_read2.rs:10:10:1 | 10 | | ^^^^ | warning: rustfmt has failed to format. See previous 1 errors. error[internal]: left behind trailing whitespace --> tests/fail/stacked_borrows/illegal_read5.rs:15:15:1 | 15 | | ^^^^ | warning: rustfmt has failed to format. See previous 1 errors. error[internal]: left behind trailing whitespace --> tests/fail/stacked_borrows/illegal_read1.rs:10:10:1 | 10 | | ^^^^ | warning: rustfmt has failed to format. See previous 1 errors. error[internal]: left behind trailing whitespace --> tests/fail/erroneous_const2.rs:9:9:1 | 9 | | ^^^^ | warning: rustfmt has failed to format. See previous 1 errors.
19 lines
768 B
Rust
19 lines
768 B
Rust
// We *can* have aliasing &RefCell<T> and &mut T, but we cannot read through the former.
|
|
// Else we couldn't optimize based on the assumption that `xref` below is truly unique.
|
|
// normalize-stderr-test: "0x[0-9a-fA-F]+" -> "$$HEX"
|
|
|
|
use std::cell::RefCell;
|
|
use std::{mem, ptr};
|
|
|
|
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
|
|
fn main() {
|
|
let rc = RefCell::new(0);
|
|
let mut refmut = rc.borrow_mut();
|
|
let xref: &mut i32 = &mut *refmut;
|
|
let xshr = &rc; // creating this is ok
|
|
let _val = *xref; // we can even still use our mutable reference
|
|
mem::forget(unsafe { ptr::read(xshr) }); // but after reading through the shared ref
|
|
let _val = *xref; // the mutable one is dead and gone
|
|
//~^ ERROR borrow stack
|
|
}
|