]> git.lizzy.rs Git - rust.git/blob - tests/ui/binding/match-vec-alternatives.rs
Rollup merge of #106692 - eggyal:mv-binary_heap.rs-binary_heap/mod.rs, r=Mark-Simulacrum
[rust.git] / tests / ui / binding / match-vec-alternatives.rs
1 // run-pass
2
3 fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
4     match (l1, l2) {
5         (&[], &[]) => "both empty",
6         (&[], &[..]) | (&[..], &[]) => "one empty",
7         (&[..], &[..]) => "both non-empty"
8     }
9 }
10
11 fn match_vecs_cons<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
12     match (l1, l2) {
13         (&[], &[]) => "both empty",
14         (&[], &[_, ..]) | (&[_, ..], &[]) => "one empty",
15         (&[_, ..], &[_, ..]) => "both non-empty"
16     }
17 }
18
19 fn match_vecs_snoc<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
20     match (l1, l2) {
21         (&[], &[]) => "both empty",
22         (&[], &[.., _]) | (&[.., _], &[]) => "one empty",
23         (&[.., _], &[.., _]) => "both non-empty"
24     }
25 }
26
27 fn match_nested_vecs_cons<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
28     match (l1, l2) {
29         (Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)",
30         (Some(&[_, ..]), Ok(_)) | (Some(&[_, ..]), Err(())) => "Some(non-empty), any",
31         (None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)",
32         (None, Ok(&[_, _, ..])) => "None, Ok(at least two elements)",
33         _ => "other"
34     }
35 }
36
37 fn match_nested_vecs_snoc<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) -> &'static str {
38     match (l1, l2) {
39         (Some(&[]), Ok(&[])) => "Some(empty), Ok(empty)",
40         (Some(&[.., _]), Ok(_)) | (Some(&[.., _]), Err(())) => "Some(non-empty), any",
41         (None, Ok(&[])) | (None, Err(())) | (None, Ok(&[_])) => "None, Ok(less than one element)",
42         (None, Ok(&[.., _, _])) => "None, Ok(at least two elements)",
43         _ => "other"
44     }
45 }
46
47 fn main() {
48     assert_eq!(match_vecs(&[1, 2], &[2, 3]), "both non-empty");
49     assert_eq!(match_vecs(&[], &[1, 2, 3, 4]), "one empty");
50     assert_eq!(match_vecs::<usize>(&[], &[]), "both empty");
51     assert_eq!(match_vecs(&[1, 2, 3], &[]), "one empty");
52
53     assert_eq!(match_vecs_cons(&[1, 2], &[2, 3]), "both non-empty");
54     assert_eq!(match_vecs_cons(&[], &[1, 2, 3, 4]), "one empty");
55     assert_eq!(match_vecs_cons::<usize>(&[], &[]), "both empty");
56     assert_eq!(match_vecs_cons(&[1, 2, 3], &[]), "one empty");
57
58     assert_eq!(match_vecs_snoc(&[1, 2], &[2, 3]), "both non-empty");
59     assert_eq!(match_vecs_snoc(&[], &[1, 2, 3, 4]), "one empty");
60     assert_eq!(match_vecs_snoc::<usize>(&[], &[]), "both empty");
61     assert_eq!(match_vecs_snoc(&[1, 2, 3], &[]), "one empty");
62
63     assert_eq!(match_nested_vecs_cons(None, Ok::<&[_], ()>(&[4_usize, 2_usize])),
64                "None, Ok(at least two elements)");
65     assert_eq!(match_nested_vecs_cons::<usize>(None, Err(())), "None, Ok(less than one element)");
66     assert_eq!(match_nested_vecs_cons::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])),
67                "Some(empty), Ok(empty)");
68     assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any");
69     assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])),
70                "Some(non-empty), any");
71
72     assert_eq!(match_nested_vecs_snoc(None, Ok::<&[_], ()>(&[4_usize, 2_usize])),
73                "None, Ok(at least two elements)");
74     assert_eq!(match_nested_vecs_snoc::<usize>(None, Err(())), "None, Ok(less than one element)");
75     assert_eq!(match_nested_vecs_snoc::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])),
76                "Some(empty), Ok(empty)");
77     assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any");
78     assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])),
79                "Some(non-empty), any");
80 }