]> git.lizzy.rs Git - rust.git/blob - src/test/ui/destructuring-assignment/tuple_destructure.rs
16aafc4693f3fba324a5fcd7c02ac136834cfaee
[rust.git] / src / test / ui / destructuring-assignment / tuple_destructure.rs
1 // run-pass
2
3 #![feature(destructuring_assignment)]
4
5 fn main() {
6     let (mut a, mut b);
7     (a, b) = (0, 1);
8     assert_eq!((a, b), (0, 1));
9     (b, a) = (a, b);
10     assert_eq!((a, b), (1, 0));
11     (a, .., b) = (1, 2);
12     assert_eq!((a, b), (1, 2));
13     (.., a) = (1, 2);
14     assert_eq!((a, b), (2, 2));
15     (..) = (3, 4);
16     assert_eq!((a, b), (2, 2));
17     (b, ..) = (5, 6, 7);
18     assert_eq!(b, 5);
19
20     // Test for a non-Copy type (String):
21     let (mut c, mut d);
22     (c, d) = ("c".to_owned(), "d".to_owned());
23     assert_eq!(c, "c");
24     assert_eq!(d, "d");
25     (d, c) = (c, d);
26     assert_eq!(c, "d");
27     assert_eq!(d, "c");
28
29     // Test nesting/parentheses:
30     ((a, b)) = (0, 1);
31     assert_eq!((a, b), (0, 1));
32     (((a, b)), (c)) = ((2, 3), d);
33     assert_eq!((a, b), (2, 3));
34     assert_eq!(c, "c");
35     ((a, .., b), .., (..)) = ((4, 5), ());
36     assert_eq!((a, b), (4, 5));
37 }