1 // Test that StorageDead and Drops are generated properly for bindings in
3 // * The MIR should only contain a single drop of `s` and `t`: at the end
4 // of their respective arms.
5 // * StorageDead and StorageLive statements are correctly matched up on
7 // * The visibility scopes of the match arms should be disjoint, and contain.
8 // all of the bindings for that scope.
9 // * No drop flags are used.
11 fn complicated_match(cond: bool, items: (bool, bool, String)) -> i32 {
13 (false, a, s) | (a, false, s) if if cond { return 3 } else { a } => 1,
14 (true, b, t) | (false, b, t) => 2,
18 const CASES: &[(bool, bool, bool, i32)] = &[
19 (false, false, false, 2),
20 (false, false, true, 1),
21 (false, true, false, 1),
22 (false, true, true, 2),
23 (true, false, false, 3),
24 (true, false, true, 3),
25 (true, true, false, 3),
26 (true, true, true, 2),
30 for &(cond, items_1, items_2, result) in CASES {
32 complicated_match(cond, (items_1, items_2, String::new())),
39 // START rustc.complicated_match.SimplifyCfg-initial.after.mir
41 // let mut _3: &bool; // Temp for fake borrow of `items.0`
42 // let mut _4: &bool; // Temp for fake borrow of `items.1`
43 // let _5: bool; // `a` in arm
44 // let _6: &bool; // `a` in guard
45 // let _7: std::string::String; // `s` in arm
46 // let _8: &std::string::String; // `s` in guard
47 // let mut _9: bool; // `if cond { return 3 } else { a }`
48 // let mut _10: bool; // `cond`
49 // let mut _11: !; // `return 3`
50 // let mut _12: bool; // `if cond { return 3 } else { a }`
51 // let mut _13: bool; // `cond`
52 // let mut _14: !; // `return 3`
53 // let _15: bool; // `b`
54 // let _16: std::string::String; // `t`
60 // FakeRead(ForMatchedPlace, _2);
61 // switchInt((_2.0: bool)) -> [false: bb2, otherwise: bb5];
67 // falseEdges -> [real: bb8, imaginary: bb3];
70 // falseEdges -> [real: bb17, imaginary: bb4];
73 // falseEdges -> [real: bb25, imaginary: bb26];
76 // switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb6];
79 // switchInt((_2.0: bool)) -> [false: bb26, otherwise: bb4];
83 // drop(_7) -> [return: bb23, unwind: bb13];
85 // bb8: { // guard - first time
87 // _6 = &(_2.1: bool);
89 // _8 = &(_2.2: std::string::String);
90 // _3 = &shallow (_2.0: bool);
91 // _4 = &shallow (_2.1: bool);
95 // FakeRead(ForMatchedPlace, _10);
96 // switchInt(_10) -> [false: bb10, otherwise: bb9];
99 // falseEdges -> [real: bb11, imaginary: bb10];
101 // bb10: { // `else` block - first time
104 // switchInt(move _9) -> [false: bb16, otherwise: bb15];
106 // bb11: { // `return 3` - first time
121 // drop(_2) -> [return: bb12, unwind: bb1];
125 // FakeRead(ForMatchGuard, _3);
126 // FakeRead(ForMatchGuard, _4);
127 // FakeRead(ForGuardBinding, _6);
128 // FakeRead(ForGuardBinding, _8);
130 // _5 = (_2.1: bool);
132 // _7 = move (_2.2: std::string::String);
135 // bb16: { // guard otherwise case - first time
139 // falseEdges -> [real: bb5, imaginary: bb3];
141 // bb17: { // guard - second time
143 // _6 = &(_2.0: bool);
145 // _8 = &(_2.2: std::string::String);
146 // _3 = &shallow (_2.0: bool);
147 // _4 = &shallow (_2.1: bool);
151 // FakeRead(ForMatchedPlace, _13);
152 // switchInt(_13) -> [false: bb19, otherwise: bb18];
155 // falseEdges -> [real: bb20, imaginary: bb19];
157 // bb19: { // `else` block - second time
160 // switchInt(move _12) -> [false: bb22, otherwise: bb21];
170 // bb21: { // bindings for arm 1
172 // FakeRead(ForMatchGuard, _3);
173 // FakeRead(ForMatchGuard, _4);
174 // FakeRead(ForGuardBinding, _6);
175 // FakeRead(ForGuardBinding, _8);
177 // _5 = (_2.0: bool);
179 // _7 = move (_2.2: std::string::String);
182 // bb22: { // Guard otherwise case - second time
186 // falseEdges -> [real: bb6, imaginary: bb4];
188 // bb23: { // rest of arm 1
197 // drop(_16) -> [return: bb27, unwind: bb13];
199 // bb25: { // bindings for arm 2 - first pattern
201 // _15 = (_2.1: bool);
203 // _16 = move (_2.2: std::string::String);
206 // bb26: { // bindings for arm 2 - second pattern
208 // _15 = (_2.1: bool);
210 // _16 = move (_2.2: std::string::String);
213 // bb27: { // rest of arm 2
219 // drop(_2) -> [return: bb12, unwind: bb1];
221 // END rustc.complicated_match.SimplifyCfg-initial.after.mir
222 // START rustc.complicated_match.ElaborateDrops.after.mir
223 // let _16: std::string::String; // No drop flags, which would come after this.
225 // END rustc.complicated_match.ElaborateDrops.after.mir