]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/search-via-bindings.rs
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini
[rust.git] / src / test / ui / or-patterns / search-via-bindings.rs
1 // Check that we expand multiple or-patterns from left to right.
2
3 // run-pass
4
5 fn search(target: (bool, bool, bool)) -> u32 {
6     let x = ((false, true), (false, true), (false, true));
7     let mut guard_count = 0;
8     match x {
9         ((a, _) | (_, a), (b @ _, _) | (_, b @ _), (c @ false, _) | (_, c @ true))
10             if {
11                 guard_count += 1;
12                 (a, b, c) == target
13             } =>
14         {
15             guard_count
16         }
17         _ => unreachable!(),
18     }
19 }
20
21 // Equivalent to the above code, but hopefully easier to understand.
22 fn search_old_style(target: (bool, bool, bool)) -> u32 {
23     let x = ((false, true), (false, true), (false, true));
24     let mut guard_count = 0;
25     match x {
26         ((a, _), (b @ _, _), (c @ false, _))
27         | ((a, _), (b @ _, _), (_, c @ true))
28         | ((a, _), (_, b @ _), (c @ false, _))
29         | ((a, _), (_, b @ _), (_, c @ true))
30         | ((_, a), (b @ _, _), (c @ false, _))
31         | ((_, a), (b @ _, _), (_, c @ true))
32         | ((_, a), (_, b @ _), (c @ false, _))
33         | ((_, a), (_, b @ _), (_, c @ true))
34             if {
35                 guard_count += 1;
36                 (a, b, c) == target
37             } =>
38         {
39             guard_count
40         }
41         _ => unreachable!(),
42     }
43 }
44
45 fn main() {
46     assert_eq!(search((false, false, false)), 1);
47     assert_eq!(search((false, false, true)), 2);
48     assert_eq!(search((false, true, false)), 3);
49     assert_eq!(search((false, true, true)), 4);
50     assert_eq!(search((true, false, false)), 5);
51     assert_eq!(search((true, false, true)), 6);
52     assert_eq!(search((true, true, false)), 7);
53     assert_eq!(search((true, true, true)), 8);
54
55     assert_eq!(search_old_style((false, false, false)), 1);
56     assert_eq!(search_old_style((false, false, true)), 2);
57     assert_eq!(search_old_style((false, true, false)), 3);
58     assert_eq!(search_old_style((false, true, true)), 4);
59     assert_eq!(search_old_style((true, false, false)), 5);
60     assert_eq!(search_old_style((true, false, true)), 6);
61     assert_eq!(search_old_style((true, true, false)), 7);
62     assert_eq!(search_old_style((true, true, true)), 8);
63 }