about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-08 11:51:20 +0100
committerGitHub <noreply@github.com>2020-03-08 11:51:20 +0100
commit49c82d117084ad0362fee6fb9a524400c1140ce7 (patch)
tree3405a2f3f23004a2e1df12fdc22b589b5731b816
parent17b77913f9fe4dbf99a6ba74e179a7c68a8b1392 (diff)
parent2e88bec61916cdb5d24ee9c79af3f70f2d52cb5c (diff)
downloadrust-49c82d117084ad0362fee6fb9a524400c1140ce7.tar.gz
rust-49c82d117084ad0362fee6fb9a524400c1140ce7.zip
Rollup merge of #69810 - thekuom:test/67523-dynamic-semantics-bindings-after-at, r=Centril
test(bindings_after_at): add dynamic drop tests for bindings_after_at

Fixes https://github.com/rust-lang/rust/issues/67523.
Working towards https://github.com/rust-lang/rust/issues/65490.
-rw-r--r--src/test/ui/drop/dynamic-drop.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/ui/drop/dynamic-drop.rs b/src/test/ui/drop/dynamic-drop.rs
index 451686d9ae2..d31736f142c 100644
--- a/src/test/ui/drop/dynamic-drop.rs
+++ b/src/test/ui/drop/dynamic-drop.rs
@@ -3,6 +3,7 @@
 
 #![feature(generators, generator_trait, untagged_unions)]
 #![feature(move_ref_pattern)]
+#![feature(bindings_after_at)]
 
 #![allow(unused_assignments)]
 #![allow(unused_variables)]
@@ -291,6 +292,44 @@ fn subslice_mixed_min_lengths(a: &Allocator, c: i32) {
     }
 }
 
+fn bindings_after_at_dynamic_init_move(a: &Allocator, c: bool) {
+    let foo = if c { Some(a.alloc()) } else { None };
+    let _x;
+
+    if let bar @ Some(_) = foo {
+        _x = bar;
+    }
+}
+
+fn bindings_after_at_dynamic_init_ref(a: &Allocator, c: bool) {
+    let foo = if c { Some(a.alloc()) } else { None };
+    let _x;
+
+    if let bar @ Some(_baz) = &foo {
+        _x = bar;
+    }
+}
+
+fn bindings_after_at_dynamic_drop_move(a: &Allocator, c: bool) {
+    let foo = if c { Some(a.alloc()) } else { None };
+
+    if let bar @ Some(_) = foo {
+        bar
+    } else {
+        None
+    };
+}
+
+fn bindings_after_at_dynamic_drop_ref(a: &Allocator, c: bool) {
+    let foo = if c { Some(a.alloc()) } else { None };
+
+    if let bar @ Some(_baz) = &foo {
+        bar
+    } else {
+        &None
+    };
+}
+
 fn move_ref_pattern(a: &Allocator) {
     let mut tup = (a.alloc(), a.alloc(), a.alloc(), a.alloc());
     let (ref _a, ref mut _b, _c, mut _d) = tup;
@@ -471,5 +510,14 @@ fn main() {
     run_test(|a| panic_after_init_temp(a));
     run_test(|a| panic_after_init_by_loop(a));
 
+    run_test(|a| bindings_after_at_dynamic_init_move(a, true));
+    run_test(|a| bindings_after_at_dynamic_init_move(a, false));
+    run_test(|a| bindings_after_at_dynamic_init_ref(a, true));
+    run_test(|a| bindings_after_at_dynamic_init_ref(a, false));
+    run_test(|a| bindings_after_at_dynamic_drop_move(a, true));
+    run_test(|a| bindings_after_at_dynamic_drop_move(a, false));
+    run_test(|a| bindings_after_at_dynamic_drop_ref(a, true));
+    run_test(|a| bindings_after_at_dynamic_drop_ref(a, false));
+
     run_test_nopanic(|a| union1(a));
 }