2013-08-21 10:39:17 -05:00
|
|
|
// Test that assignments to an `&mut` pointer which is found in a
|
|
|
|
// borrowed (but otherwise non-aliasable) location is illegal.
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
struct S<'a> {
|
2015-01-08 04:54:35 -06:00
|
|
|
pointer: &'a mut isize
|
2013-08-21 10:39:17 -05: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 02:40:08 -05:00
|
|
|
*y.pointer += 1;
|
|
|
|
//~^ ERROR cannot use `*y.pointer`
|
|
|
|
//~| ERROR cannot assign to `*y.pointer`
|
2013-08-21 10:39:17 -05:00
|
|
|
*z.pointer += 1;
|
|
|
|
}
|
|
|
|
}
|