2014-12-05 15:56:25 -08:00
|
|
|
fn main() {
|
2015-01-31 17:23:42 +01:00
|
|
|
let foo = &mut 1;
|
2014-12-05 15:56:25 -08:00
|
|
|
|
|
|
|
|
let &mut x = foo;
|
2019-04-22 08:40:08 +01:00
|
|
|
x += 1; //~ ERROR cannot assign twice to immutable variable `x`
|
2014-12-05 15:56:25 -08: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 08:40:08 +01:00
|
|
|
*foo += 1; //~ ERROR cannot assign to `*foo` because it is borrowed
|
2018-04-09 05:28:00 -04:00
|
|
|
drop(x);
|
2014-12-05 15:56:25 -08:00
|
|
|
}
|