2013-08-21 15:39:17 +00:00
|
|
|
// Test that assignments to an `&mut` pointer which is found in a
|
|
|
|
// borrowed (but otherwise non-aliasable) location is illegal.
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
struct S<'a> {
|
2015-01-08 10:54:35 +00:00
|
|
|
pointer: &'a mut isize
|
2013-08-21 15:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
|
|
|
|
S { pointer: &mut *p.pointer }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = 1;
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut y = S { pointer: &mut x };
|
|
|
|
let z = copy_borrowed_ptr(&mut y);
|
2019-04-22 07:40:08 +00:00
|
|
|
*y.pointer += 1;
|
|
|
|
//~^ ERROR cannot use `*y.pointer`
|
|
|
|
//~| ERROR cannot assign to `*y.pointer`
|
2013-08-21 15:39:17 +00:00
|
|
|
*z.pointer += 1;
|
|
|
|
}
|
|
|
|
}
|