]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-7784.rs
43785edc2eb03782097add8a8c1c1ed79f64aaa3
[rust.git] / src / test / run-pass / issue-7784.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(advanced_slice_patterns)]
12
13 use std::ops::Add;
14
15 fn foo<T: Add<T, T> + Clone>([x, y, z]: [T; 3]) -> (T, T, T) {
16     (x.clone(), x.clone() + y.clone(), x + y + z)
17 }
18 fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] {
19     [a, b, b, a]
20 }
21
22 fn main() {
23     assert_eq!(foo([1i, 2i, 3i]), (1i, 3i, 6i));
24
25     let [a, b, c, d] = bar("foo", "bar");
26     assert_eq!(a, "foo");
27     assert_eq!(b, "bar");
28     assert_eq!(c, "bar");
29     assert_eq!(d, "foo");
30
31     let [a, _, _, d] = bar("baz", "foo");
32     assert_eq!(a, "baz");
33     assert_eq!(d, "baz");
34
35     let out = bar("baz", "foo");
36     let [a, xs.., d] = out;
37     assert_eq!(a, "baz");
38     assert!(xs == ["foo", "foo"]);
39     assert_eq!(d, "baz");
40 }