]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-54499-field-mutation-of-moved-out.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / issue-54499-field-mutation-of-moved-out.rs
1 #![warn(unused)]
2 #[derive(Debug)]
3 struct S(i32);
4
5 type Tuple = (S, i32);
6 struct Tpair(S, i32);
7 struct Spair { x: S, y: i32 }
8
9 fn main() {
10     {
11         let t: Tuple = (S(0), 0);
12         drop(t);
13         t.0 = S(1);
14         //~^ ERROR assign to part of moved value: `t` [E0382]
15         //~| ERROR cannot assign to `t.0`, as `t` is not declared as mutable [E0594]
16         t.1 = 2;
17         //~^ ERROR cannot assign to `t.1`, as `t` is not declared as mutable [E0594]
18         println!("{:?} {:?}", t.0, t.1);
19     }
20
21     {
22         let u: Tpair = Tpair(S(0), 0);
23         drop(u);
24         u.0 = S(1);
25         //~^ ERROR assign to part of moved value: `u` [E0382]
26         //~| ERROR cannot assign to `u.0`, as `u` is not declared as mutable [E0594]
27         u.1 = 2;
28         //~^ ERROR cannot assign to `u.1`, as `u` is not declared as mutable [E0594]
29         println!("{:?} {:?}", u.0, u.1);
30     }
31
32     {
33         let v: Spair = Spair { x: S(0), y: 0 };
34         drop(v);
35         v.x = S(1);
36         //~^ ERROR assign to part of moved value: `v` [E0382]
37         //~| ERROR cannot assign to `v.x`, as `v` is not declared as mutable [E0594]
38         v.y = 2;
39         //~^ ERROR cannot assign to `v.y`, as `v` is not declared as mutable [E0594]
40         println!("{:?} {:?}", v.x, v.y);
41     }
42 }