rust/tests/fail/stacked_borrows/illegal_read1.rs
David Tolnay 817adda794
Add rustfmt::skip to some files
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.
2022-06-19 17:21:57 -07:00

17 lines
499 B
Rust

// A callee may not read the destination of our `&mut` without
// us noticing.
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
fn main() {
let mut x = 15;
let xraw = &mut x as *mut _;
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still ok...
callee(xraw);
let _val = *xref; // ...but any use of raw will invalidate our ref.
//~^ ERROR: borrow stack
}
fn callee(xraw: *mut i32) {
let _val = unsafe { *xraw };
}