]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-uninit-field-access.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-uninit-field-access.rs
1 // Check that do not allow access to fields of uninitialized or moved
2 // structs.
3
4 #[derive(Default)]
5 struct Point {
6     x: isize,
7     y: isize,
8 }
9
10 #[derive(Default)]
11 struct Line {
12     origin: Point,
13     middle: Point,
14     target: Point,
15 }
16
17 impl Line { fn consume(self) { } }
18
19 fn main() {
20     let mut a: Point;
21     let _ = a.x + 1; //~ ERROR [E0381]
22
23     let mut line1 = Line::default();
24     let _moved = line1.origin;
25     let _ = line1.origin.x + 1; //~ ERROR [E0382]
26
27     let mut line2 = Line::default();
28     let _moved = (line2.origin, line2.middle);
29     line2.consume(); //~ ERROR [E0382]
30 }