]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.rs
Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomcc
[rust.git] / tests / ui / closures / 2229_closure_analysis / diagnostics / cant-mutate-imm.rs
1 // edition:2021
2
3 // Ensure that diagnostics for mutability error (because the root variable
4 // isn't mutable) work with `capture_disjoint_fields` enabled.
5
6 fn mut_error_struct() {
7     let x = (10, 10);
8     let y = (x, 10);
9     let z = (y, 10);
10
11     let mut c = || {
12         z.0.0.0 = 20;
13         //~^ ERROR: cannot assign to `z.0.0.0`, as it is not declared as mutable
14     };
15
16     c();
17 }
18
19 fn mut_error_box() {
20     let x = (10, 10);
21     let bx = Box::new(x);
22
23     let mut c = || {
24         bx.0 = 20;
25         //~^ ERROR: cannot assign to `*bx.0`, as it is not declared as mutable
26     };
27
28     c();
29 }
30
31 fn main() {
32     mut_error_struct();
33     mut_error_box();
34 }