2014-12-05 17:56:25 -06:00
|
|
|
fn main() {
|
2015-01-31 10:23:42 -06:00
|
|
|
let foo = &mut 1;
|
2014-12-05 17:56:25 -06:00
|
|
|
|
|
|
|
let &mut x = foo;
|
2019-04-22 02:40:08 -05:00
|
|
|
x += 1; //~ ERROR cannot assign twice to immutable variable `x`
|
2014-12-05 17:56:25 -06:00
|
|
|
|
|
|
|
// explicitly mut-ify internals
|
|
|
|
let &mut mut x = foo;
|
|
|
|
x += 1;
|
|
|
|
|
|
|
|
// check borrowing is detected successfully
|
|
|
|
let &mut ref x = foo;
|
2019-04-22 02:40:08 -05:00
|
|
|
*foo += 1; //~ ERROR cannot assign to `*foo` because it is borrowed
|
2018-04-09 04:28:00 -05:00
|
|
|
drop(x);
|
2014-12-05 17:56:25 -06:00
|
|
|
}
|