]> git.lizzy.rs Git - rust.git/blob - src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.rs
676fde558dfbc684d81a732cef204de7effe072b
[rust.git] / src / test / ui / closures / 2229_closure_analysis / diagnostics / mut_ref.rs
1 // Test that we can't mutate a place if we need to deref an imm-borrow
2 // to reach it.
3
4 #![feature(capture_disjoint_fields)]
5 //~^ WARNING: the feature `capture_disjoint_fields` is incomplete
6
7 fn imm_mut_ref() {
8     let mut x = String::new();
9     let y = String::new();
10     let mref_x = &mut x;
11     let ref_mref_x = &mref_x;
12
13     let c = || {
14     //~^ ERROR: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` reference
15         **ref_mref_x = y;
16     };
17
18     c();
19 }
20
21 fn mut_imm_ref() {
22     let x = String::new();
23     let y = String::new();
24     let mut ref_x = &x;
25     let mref_ref_x = &mut ref_x;
26
27     let c = || {
28     //~^ ERROR: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference
29         **mref_ref_x = y;
30     };
31
32     c();
33 }
34
35 fn main() {
36     imm_mut_ref();
37     mut_imm_ref();
38 }