]> git.proxmox.com Git - rustc.git/blame - src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / diagnostics / cant-mutate-imm.rs
CommitLineData
136023e0 1// edition:2021
5869c6ff
XL
2
3// Ensure that diagnostics for mutability error (because the root variable
4// isn't mutable) work with `capture_disjoint_fields` enabled.
5
6fn 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;
17df50a5 13 //~^ ERROR: cannot assign to `z.0.0.0`, as it is not declared as mutable
5869c6ff
XL
14 };
15
16 c();
17}
18
19fn mut_error_box() {
20 let x = (10, 10);
21 let bx = Box::new(x);
22
23 let mut c = || {
24 bx.0 = 20;
17df50a5 25 //~^ ERROR: cannot assign to `*bx.0`, as it is not declared as mutable
5869c6ff
XL
26 };
27
28 c();
29}
30
31fn main() {
32 mut_error_struct();
33 mut_error_box();
34}