]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.rs
Rollup merge of #107313 - calebcartwright:style-guide-triagebot, r=joshtriplett
[rust.git] / tests / ui / closures / 2229_closure_analysis / diagnostics / cant-mutate-imm-borrow.rs
1 // edition:2021
2
3 // Test that if we deref an immutable borrow to access a Place,
4 // then we can't mutate the final place.
5
6 fn main() {
7     let mut x = (format!(""), format!("X2"));
8     let mut y = (&x, "Y");
9     let z = (&mut y, "Z");
10
11     // `x.0` is mutable but we access `x` via `*z.0.0`, which is an immutable reference and
12     // therefore can't be mutated.
13     let mut c = || {
14     //~^ ERROR: cannot borrow `*z.0.0` as mutable, as it is behind a `&` reference
15         z.0.0.0 = format!("X1");
16     };
17
18     c();
19 }