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