]> git.lizzy.rs Git - rust.git/blob - src/test/ui/destructuring-assignment/tuple_destructure.rs
Rollup merge of #89945 - JohnTitor:we-now-specialize-clone-from-slice, r=the8472
[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     (a, _) = (8, 9);
20     assert_eq!(a, 8);
21
22     // Test for a non-Copy type (String):
23     let (mut c, mut d);
24     (c, d) = ("c".to_owned(), "d".to_owned());
25     assert_eq!(c, "c");
26     assert_eq!(d, "d");
27     (d, c) = (c, d);
28     assert_eq!(c, "d");
29     assert_eq!(d, "c");
30
31     // Test nesting/parentheses:
32     ((a, b)) = (0, 1);
33     assert_eq!((a, b), (0, 1));
34     (((a, b)), (c)) = ((2, 3), d);
35     assert_eq!((a, b), (2, 3));
36     assert_eq!(c, "c");
37     ((a, .., b), .., (..)) = ((4, 5), ());
38     assert_eq!((a, b), (4, 5));
39 }