summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/control-flow/drop-fail.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/consts/control-flow/drop-fail.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/consts/control-flow/drop-fail.rs')
-rw-r--r--tests/ui/consts/control-flow/drop-fail.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/ui/consts/control-flow/drop-fail.rs b/tests/ui/consts/control-flow/drop-fail.rs
new file mode 100644
index 000000000..41341f312
--- /dev/null
+++ b/tests/ui/consts/control-flow/drop-fail.rs
@@ -0,0 +1,62 @@
+// revisions: stock precise
+
+#![cfg_attr(precise, feature(const_precise_live_drops))]
+
+// `x` is *not* always moved into the final value and may be dropped inside the initializer.
+const _: Option<Vec<i32>> = {
+ let y: Option<Vec<i32>> = None;
+ let x = Some(Vec::new());
+ //[stock,precise]~^ ERROR destructor of
+
+ if true {
+ x
+ } else {
+ y
+ }
+};
+
+// We only clear `NeedsDrop` if a local is moved from in entirely. This is a shortcoming of the
+// existing analysis.
+const _: Vec<i32> = {
+ let vec_tuple = (Vec::new(),);
+ //[stock]~^ ERROR destructor of
+
+ vec_tuple.0
+};
+
+// This applies to single-field enum variants as well.
+const _: Vec<i32> = {
+ let x: Result<_, Vec<i32>> = Ok(Vec::new());
+ //[stock]~^ ERROR destructor of
+
+ match x {
+ Ok(x) | Err(x) => x,
+ }
+};
+
+const _: Option<Vec<i32>> = {
+ let mut some = Some(Vec::new());
+ let mut tmp = None;
+ //[stock,precise]~^ ERROR destructor of
+
+ let mut i = 0;
+ while i < 10 {
+ tmp = some;
+ some = None;
+
+ // We can escape the loop with `Some` still in `tmp`,
+ // which would require that it be dropped at the end of the block.
+ if i > 100 {
+ break;
+ }
+
+ some = tmp;
+ tmp = None;
+
+ i += 1;
+ }
+
+ some
+};
+
+fn main() {}