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 {
31 assert_eq!(complicated_match(cond, (items_1, items_2, String::new())), result,);
36 // START rustc.complicated_match.SimplifyCfg-initial.after.mir
38 // let mut _3: &bool; // Temp for fake borrow of `items.0`
39 // let mut _4: &bool; // Temp for fake borrow of `items.1`
40 // let _5: bool; // `a` in arm
41 // let _6: &bool; // `a` in guard
42 // let _7: std::string::String; // `s` in arm
43 // let _8: &std::string::String; // `s` in guard
44 // let mut _9: bool; // `if cond { return 3 } else { a }`
45 // let mut _10: bool; // `cond`
46 // let mut _11: !; // `return 3`
47 // let mut _12: bool; // `if cond { return 3 } else { a }`
48 // let mut _13: bool; // `cond`
49 // let mut _14: !; // `return 3`
50 // let _15: bool; // `b`
51 // let _16: std::string::String; // `t`
63 // FakeRead(ForMatchedPlace, _2);
64 // switchInt((_2.0: bool)) -> [false: bb2, otherwise: bb3];
69 // bb2: { // pre-binding for arm 1 first pattern
70 // falseEdges -> [real: bb9, imaginary: bb4];
73 // switchInt((_2.1: bool)) -> [false: bb4, otherwise: bb5];
75 // bb4: { // pre-binding for arm 1 second pattern
76 // falseEdges -> [real: bb18, imaginary: bb6];
79 // switchInt((_2.0: bool)) -> [false: bb7, otherwise: bb6];
81 // bb6: { // pre-binding for arm 2 first pattern
82 // falseEdges -> [real: bb26, imaginary: bb7];
84 // bb7: { // bindings for arm 2 - second pattern
86 // _15 = (_2.1: bool);
88 // _16 = move (_2.2: std::string::String);
93 // drop(_7) -> [return: bb24, unwind: bb14];
95 // bb9: { // guard - first time
97 // _6 = &(_2.1: bool);
99 // _8 = &(_2.2: std::string::String);
100 // _3 = &shallow (_2.0: bool);
101 // _4 = &shallow (_2.1: bool);
105 // FakeRead(ForMatchedPlace, _10);
106 // switchInt(_10) -> [false: bb11, otherwise: bb10];
109 // falseEdges -> [real: bb12, imaginary: bb11];
111 // bb11: { // `else` block - first time
114 // switchInt(move _9) -> [false: bb17, otherwise: bb16];
116 // bb12: { // `return 3` - first time
131 // drop(_2) -> [return: bb13, unwind: bb1];
135 // FakeRead(ForMatchGuard, _3);
136 // FakeRead(ForMatchGuard, _4);
137 // FakeRead(ForGuardBinding, _6);
138 // FakeRead(ForGuardBinding, _8);
140 // _5 = (_2.1: bool);
142 // _7 = move (_2.2: std::string::String);
145 // bb17: { // guard otherwise case - first time
149 // falseEdges -> [real: bb3, imaginary: bb4];
151 // bb18: { // guard - second time
153 // _6 = &(_2.0: bool);
155 // _8 = &(_2.2: std::string::String);
156 // _3 = &shallow (_2.0: bool);
157 // _4 = &shallow (_2.1: bool);
161 // FakeRead(ForMatchedPlace, _13);
162 // switchInt(_13) -> [false: bb20, otherwise: bb19];
165 // falseEdges -> [real: bb21, imaginary: bb20];
167 // bb20: { // `else` block - second time
170 // switchInt(move _12) -> [false: bb23, otherwise: bb22];
180 // bb22: { // bindings for arm 1
182 // FakeRead(ForMatchGuard, _3);
183 // FakeRead(ForMatchGuard, _4);
184 // FakeRead(ForGuardBinding, _6);
185 // FakeRead(ForGuardBinding, _8);
187 // _5 = (_2.0: bool);
189 // _7 = move (_2.2: std::string::String);
192 // bb23: { // Guard otherwise case - second time
196 // falseEdges -> [real: bb5, imaginary: bb6];
198 // bb24: { // rest of arm 1
207 // drop(_16) -> [return: bb27, unwind: bb14];
209 // bb26: { // bindings for arm 2 - first pattern
211 // _15 = (_2.1: bool);
213 // _16 = move (_2.2: std::string::String);
217 // bb27: { // rest of arm 2
223 // drop(_2) -> [return: bb13, unwind: bb1];
225 // END rustc.complicated_match.SimplifyCfg-initial.after.mir
226 // START rustc.complicated_match.ElaborateDrops.after.mir
227 // let _16: std::string::String; // No drop flags, which would come after this.
229 // END rustc.complicated_match.ElaborateDrops.after.mir