about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Holk <ericholk@microsoft.com>2021-11-03 16:28:07 -0700
committerEric Holk <ericholk@microsoft.com>2022-01-18 14:25:25 -0800
commit96117701f94a2c08235a87fce9d362ca26997017 (patch)
tree4bea4f71f30961e09084835d3025ee80141f440b /src
parentaa029d4bbe78fafbffdebb398a767941459d9d4e (diff)
downloadrust-96117701f94a2c08235a87fce9d362ca26997017.tar.gz
rust-96117701f94a2c08235a87fce9d362ca26997017.zip
Support reinitialization of variables
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/generator/drop-control-flow.rs81
-rw-r--r--src/test/ui/generator/drop-if.rs22
2 files changed, 81 insertions, 22 deletions
diff --git a/src/test/ui/generator/drop-control-flow.rs b/src/test/ui/generator/drop-control-flow.rs
new file mode 100644
index 00000000000..b180a61b104
--- /dev/null
+++ b/src/test/ui/generator/drop-control-flow.rs
@@ -0,0 +1,81 @@
+// build-pass
+
+// A test to ensure generators capture values that were conditionally dropped,
+// and also that values that are dropped along all paths to a yield do not get
+// included in the generator type.
+
+#![feature(generators, negative_impls)]
+
+#![allow(unused_assignments, dead_code)]
+
+struct Ptr;
+impl<'a> Drop for Ptr {
+    fn drop(&mut self) {}
+}
+
+struct NonSend {}
+impl !Send for NonSend {}
+
+fn assert_send<T: Send>(_: T) {}
+
+// This test case is reduced from src/test/ui/drop/dynamic-drop-async.rs
+fn one_armed_if(arg: bool) {
+    let _ = || {
+        let arr = [Ptr];
+        if arg {
+            drop(arr);
+        }
+        yield;
+    };
+}
+
+fn two_armed_if(arg: bool) {
+    assert_send(|| {
+        let arr = [Ptr];
+        if arg {
+            drop(arr);
+        } else {
+            drop(arr);
+        }
+        yield;
+    })
+}
+
+fn if_let(arg: Option<i32>) {
+    let _ = || {
+        let arr = [Ptr];
+        if let Some(_) = arg {
+            drop(arr);
+        }
+        yield;
+    };
+}
+
+fn reinit() {
+    let _ = || {
+        let mut arr = [Ptr];
+        drop(arr);
+        arr = [Ptr];
+        yield;
+    };
+}
+
+fn loop_uninit() {
+    let _ = || {
+        let mut arr = [Ptr];
+        let mut count = 0;
+        drop(arr);
+        while count < 3 {
+            yield;
+            arr = [Ptr];
+            count += 1;
+        }
+    };
+}
+
+fn main() {
+    one_armed_if(true);
+    if_let(Some(41));
+    reinit();
+    // loop_uninit();
+}
diff --git a/src/test/ui/generator/drop-if.rs b/src/test/ui/generator/drop-if.rs
deleted file mode 100644
index 40f01f78662..00000000000
--- a/src/test/ui/generator/drop-if.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-// build-pass
-
-// This test case is reduced from src/test/ui/drop/dynamic-drop-async.rs
-
-#![feature(generators)]
-
-struct Ptr;
-impl<'a> Drop for Ptr {
-    fn drop(&mut self) {
-    }
-}
-
-fn main() {
-    let arg = true;
-    let _ = || {
-        let arr = [Ptr];
-        if arg {
-            drop(arr);
-        }
-        yield
-    };
-}