]> git.lizzy.rs Git - rust.git/blob - tests/run-make/coverage/match_or_pattern.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / run-make / coverage / match_or_pattern.rs
1 #![feature(or_patterns)]
2
3 fn main() {
4     // Initialize test constants in a way that cannot be determined at compile time, to ensure
5     // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
6     // dependent conditions.
7     let is_true = std::env::args().len() == 1;
8
9     let mut a: u8 = 0;
10     let mut b: u8 = 0;
11     if is_true {
12         a = 2;
13         b = 0;
14     }
15     match (a, b) {
16         // Or patterns generate MIR `SwitchInt` with multiple targets to the same `BasicBlock`.
17         // This test confirms a fix for Issue #79569.
18         (0 | 1, 2 | 3) => {}
19         _ => {}
20     }
21     if is_true {
22         a = 0;
23         b = 0;
24     }
25     match (a, b) {
26         (0 | 1, 2 | 3) => {}
27         _ => {}
28     }
29     if is_true {
30         a = 2;
31         b = 2;
32     }
33     match (a, b) {
34         (0 | 1, 2 | 3) => {}
35         _ => {}
36     }
37     if is_true {
38         a = 0;
39         b = 2;
40     }
41     match (a, b) {
42         (0 | 1, 2 | 3) => {}
43         _ => {}
44     }
45 }