]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-54499-field-mutation-of-never-init.rs
Some new tests I added.
[rust.git] / src / test / ui / borrowck / issue-54499-field-mutation-of-never-init.rs
1 // revisions: ast nll
2
3 // Since we are testing nll migration explicitly as a separate
4 // revision, don't worry about the --compare-mode=nll on this test.
5
6 // ignore-compare-mode-nll
7
8 //[ast]compile-flags: -Z borrowck=ast
9 //[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
10
11 #![warn(unused)]
12 #[derive(Debug)]
13 struct S(i32);
14
15 type Tuple = (S, i32);
16 struct Tpair(S, i32);
17 struct Spair { x: S, y: i32 }
18
19 fn main() {
20     {
21         let t: Tuple;
22         t.0 = S(1);
23         //[ast]~^ ERROR cannot assign to field `t.0` of immutable binding [E0594]
24         //[nll]~^^ ERROR assign to part of possibly uninitialized variable: `t` [E0381]
25         t.1 = 2;
26         //[ast]~^ ERROR cannot assign to field `t.1` of immutable binding [E0594]
27         println!("{:?} {:?}", t.0, t.1);
28         //[ast]~^ ERROR use of possibly uninitialized variable: `t.0` [E0381]
29         //[ast]~| ERROR use of possibly uninitialized variable: `t.1` [E0381]
30     }
31
32     {
33         let u: Tpair;
34         u.0 = S(1);
35         //[ast]~^ ERROR cannot assign to field `u.0` of immutable binding [E0594]
36         //[nll]~^^ ERROR assign to part of possibly uninitialized variable: `u` [E0381]
37         u.1 = 2;
38         //[ast]~^ ERROR cannot assign to field `u.1` of immutable binding [E0594]
39         println!("{:?} {:?}", u.0, u.1);
40         //[ast]~^ ERROR use of possibly uninitialized variable: `u.0` [E0381]
41         //[ast]~| ERROR use of possibly uninitialized variable: `u.1` [E0381]
42     }
43
44     {
45         let v: Spair;
46         v.x = S(1);
47         //[ast]~^ ERROR cannot assign to field `v.x` of immutable binding [E0594]
48         //[nll]~^^ ERROR assign to part of possibly uninitialized variable: `v` [E0381]
49         v.y = 2;
50         //[ast]~^ ERROR cannot assign to field `v.y` of immutable binding [E0594]
51         println!("{:?} {:?}", v.x, v.y);
52         //[ast]~^ ERROR use of possibly uninitialized variable: `v.x` [E0381]
53         //[ast]~| ERROR use of possibly uninitialized variable: `v.y` [E0381]
54     }
55 }