]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut/mut-pattern-internal-mutability.rs
Rollup merge of #106707 - ehuss:remove-dupe-sha-1, r=Mark-Simulacrum
[rust.git] / tests / ui / mut / mut-pattern-internal-mutability.rs
1 fn main() {
2     let foo = &mut 1;
3
4     let &mut x = foo;
5     x += 1; //~ ERROR cannot assign twice to immutable variable `x`
6
7     // explicitly mut-ify internals
8     let &mut mut x = foo;
9     x += 1;
10
11     // check borrowing is detected successfully
12     let &mut ref x = foo;
13     *foo += 1; //~ ERROR cannot assign to `*foo` because it is borrowed
14     drop(x);
15 }