about summary refs log tree commit diff
path: root/src/test/ui/array-slice-vec/destructure-array-1.rs
diff options
context:
space:
mode:
authorphosphorus <steepout@qq.com>2019-08-19 00:34:02 -0500
committerGitHub <noreply@github.com>2019-08-19 00:34:02 -0500
commit92f08b78a12ff119af853cb2bf58468208ea6a90 (patch)
treeb4636f43c056de11dd69130ce47039343a9f52c5 /src/test/ui/array-slice-vec/destructure-array-1.rs
parent963184bbb670c1ffa97fc28a98cd5e8473118859 (diff)
parenta807902dd6b4222179776c3f3c33da8dafdd4da1 (diff)
downloadrust-92f08b78a12ff119af853cb2bf58468208ea6a90.tar.gz
rust-92f08b78a12ff119af853cb2bf58468208ea6a90.zip
Merge pull request #1 from rust-lang/master
Pull from newest repo
Diffstat (limited to 'src/test/ui/array-slice-vec/destructure-array-1.rs')
-rw-r--r--src/test/ui/array-slice-vec/destructure-array-1.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/array-slice-vec/destructure-array-1.rs b/src/test/ui/array-slice-vec/destructure-array-1.rs
new file mode 100644
index 00000000000..74d893ee5b2
--- /dev/null
+++ b/src/test/ui/array-slice-vec/destructure-array-1.rs
@@ -0,0 +1,27 @@
+// run-pass
+
+// Ensure that we can do a destructuring bind of a fixed-size array,
+// even when the element type has a destructor.
+
+struct D { x: u8 }
+
+impl Drop for D { fn drop(&mut self) { } }
+
+fn main() {
+    fn d(x: u8) -> D { D { x: x } }
+
+    let d1 = foo([d(1), d(2), d(3), d(4)], 1);
+    let d3 = foo([d(5), d(6), d(7), d(8)], 3);
+    assert_eq!(d1.x, 2);
+    assert_eq!(d3.x, 8);
+}
+
+fn foo([a, b, c, d]: [D; 4], i: usize) -> D {
+    match i {
+        0 => a,
+        1 => b,
+        2 => c,
+        3 => d,
+        _ => panic!("unmatched"),
+    }
+}