about summary refs log tree commit diff
path: root/tests/ui/borrowck/borrowck-uninit-field-access.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/borrowck/borrowck-uninit-field-access.rs')
-rw-r--r--tests/ui/borrowck/borrowck-uninit-field-access.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/borrowck/borrowck-uninit-field-access.rs b/tests/ui/borrowck/borrowck-uninit-field-access.rs
new file mode 100644
index 00000000000..bc931eef93a
--- /dev/null
+++ b/tests/ui/borrowck/borrowck-uninit-field-access.rs
@@ -0,0 +1,30 @@
+// Check that do not allow access to fields of uninitialized or moved
+// structs.
+
+#[derive(Default)]
+struct Point {
+    x: isize,
+    y: isize,
+}
+
+#[derive(Default)]
+struct Line {
+    origin: Point,
+    middle: Point,
+    target: Point,
+}
+
+impl Line { fn consume(self) { } }
+
+fn main() {
+    let mut a: Point;
+    let _ = a.x + 1; //~ ERROR [E0381]
+
+    let mut line1 = Line::default();
+    let _moved = line1.origin;
+    let _ = line1.origin.x + 1; //~ ERROR [E0382]
+
+    let mut line2 = Line::default();
+    let _moved = (line2.origin, line2.middle);
+    line2.consume(); //~ ERROR [E0382]
+}