2013-05-26 05:48:04 -04:00
|
|
|
// Test that attempt to reborrow an `&mut` pointer in an aliasable
|
|
|
|
// location yields an error.
|
|
|
|
//
|
2020-08-27 22:58:48 -05:00
|
|
|
// Example from compiler/rustc_borrowck/borrowck/README.md
|
2013-05-26 05:48:04 -04:00
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
fn foo(t0: & &mut isize) {
|
2013-05-26 05:48:04 -04:00
|
|
|
let t1 = t0;
|
2015-01-08 21:54:35 +11:00
|
|
|
let p: &isize = &**t0;
|
2013-05-26 05:48:04 -04:00
|
|
|
**t1 = 22; //~ ERROR cannot assign
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
fn foo3(t0: &mut &mut isize) {
|
2013-05-26 05:48:04 -04:00
|
|
|
let t1 = &mut *t0;
|
2015-01-08 21:54:35 +11:00
|
|
|
let p: &isize = &**t0; //~ ERROR cannot borrow
|
2013-05-26 05:48:04 -04:00
|
|
|
**t1 = 22;
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
fn foo4(t0: & &mut isize) {
|
|
|
|
let x: &mut isize = &mut **t0; //~ ERROR cannot borrow
|
2014-02-07 17:28:56 -05:00
|
|
|
*x += 1;
|
|
|
|
}
|
|
|
|
|
2013-05-26 05:48:04 -04:00
|
|
|
fn main() {
|
2013-08-02 21:41:06 -07:00
|
|
|
}
|