]> git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/match-arm-scopes.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / mir-opt / match-arm-scopes.rs
1 // ignore-wasm32-bare compiled with panic=abort by default
2 // Test that StorageDead and Drops are generated properly for bindings in
3 // matches:
4 // * The MIR should only contain a single drop of `s` and `t`: at the end
5 // of their respective arms.
6 // * StorageDead and StorageLive statements are correctly matched up on
7 // non-unwind paths.
8 // * The visibility scopes of the match arms should be disjoint, and contain.
9 // all of the bindings for that scope.
10 // * No drop flags are used.
11
12 // EMIT_MIR match_arm_scopes.complicated_match SimplifyCfg-initial.after ElaborateDrops.after
13 fn complicated_match(cond: bool, items: (bool, bool, String)) -> i32 {
14 match items {
15 (false, a, s) | (a, false, s) if if cond { return 3 } else { a } => 1,
16 (true, b, t) | (false, b, t) => 2,
17 }
18 }
19
20 const CASES: &[(bool, bool, bool, i32)] = &[
21 (false, false, false, 2),
22 (false, false, true, 1),
23 (false, true, false, 1),
24 (false, true, true, 2),
25 (true, false, false, 3),
26 (true, false, true, 3),
27 (true, true, false, 3),
28 (true, true, true, 2),
29 ];
30
31 fn main() {
32 for &(cond, items_1, items_2, result) in CASES {
33 assert_eq!(complicated_match(cond, (items_1, items_2, String::new())), result,);
34 }
35 }