summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs')
-rw-r--r--tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs b/tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
new file mode 100644
index 000000000..46a156d2a
--- /dev/null
+++ b/tests/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
@@ -0,0 +1,60 @@
+// This test enumerates various cases of interest where an ADT or tuple is
+// partially initialized and then used in some way that is wrong *even*
+// after rust-lang/rust#54987 is implemented.
+//
+// See rust-lang/rust#21232, rust-lang/rust#54986, and rust-lang/rust#54987.
+//
+// See issue-21232-partial-init-and-use.rs for cases of tests that are
+// meant to compile and run successfully once rust-lang/rust#54987 is
+// implemented.
+
+struct D {
+ x: u32,
+ s: S,
+}
+
+struct S {
+ y: u32,
+ z: u32,
+}
+
+
+impl Drop for D {
+ fn drop(&mut self) { }
+}
+
+fn cannot_partially_init_adt_with_drop() {
+ let d: D;
+ d.x = 10; //~ ERROR E0381
+}
+
+fn cannot_partially_init_mutable_adt_with_drop() {
+ let mut d: D;
+ d.x = 10; //~ ERROR E0381
+}
+
+fn cannot_partially_reinit_adt_with_drop() {
+ let mut d = D { x: 0, s: S{ y: 0, z: 0 } };
+ drop(d);
+ d.x = 10;
+ //~^ ERROR assign of moved value: `d` [E0382]
+}
+
+fn cannot_partially_init_inner_adt_via_outer_with_drop() {
+ let d: D;
+ d.s.y = 20; //~ ERROR E0381
+}
+
+fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() {
+ let mut d: D;
+ d.s.y = 20; //~ ERROR E0381
+}
+
+fn cannot_partially_reinit_inner_adt_via_outer_with_drop() {
+ let mut d = D { x: 0, s: S{ y: 0, z: 0} };
+ drop(d);
+ d.s.y = 20;
+ //~^ ERROR assign to part of moved value: `d` [E0382]
+}
+
+fn main() { }