]>
git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/match-arm-scopes.rs
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`
66 // FakeRead(ForMatchedPlace, _2);
67 // switchInt((_2.0: bool)) -> [false: bb2, otherwise: bb5];
73 // falseEdges -> [real: bb8, imaginary: bb3];
76 // falseEdges -> [real: bb17, imaginary: bb4];
79 // falseEdges -> [real: bb25, imaginary: bb26];
82 // switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb6];
85 // switchInt((_2.0: bool)) -> [false: bb26, otherwise: bb4];
89 // drop(_7) -> [return: bb23, unwind: bb13];
91 // bb8: { // guard - first time
93 // _6 = &(_2.1: bool);
95 // _8 = &(_2.2: std::string::String);
96 // _3 = &shallow (_2.0: bool);
97 // _4 = &shallow (_2.1: bool);
101 // FakeRead(ForMatchedPlace, _10);
102 // switchInt(_10) -> [false: bb10, otherwise: bb9];
105 // falseEdges -> [real: bb11, imaginary: bb10];
107 // bb10: { // `else` block - first time
110 // switchInt(move _9) -> [false: bb16, otherwise: bb15];
112 // bb11: { // `return 3` - first time
127 // drop(_2) -> [return: bb12, unwind: bb1];
131 // FakeRead(ForMatchGuard, _3);
132 // FakeRead(ForMatchGuard, _4);
133 // FakeRead(ForGuardBinding, _6);
134 // FakeRead(ForGuardBinding, _8);
136 // _5 = (_2.1: bool);
138 // _7 = move (_2.2: std::string::String);
141 // bb16: { // guard otherwise case - first time
145 // falseEdges -> [real: bb5, imaginary: bb3];
147 // bb17: { // guard - second time
149 // _6 = &(_2.0: bool);
151 // _8 = &(_2.2: std::string::String);
152 // _3 = &shallow (_2.0: bool);
153 // _4 = &shallow (_2.1: bool);
157 // FakeRead(ForMatchedPlace, _13);
158 // switchInt(_13) -> [false: bb19, otherwise: bb18];
161 // falseEdges -> [real: bb20, imaginary: bb19];
163 // bb19: { // `else` block - second time
166 // switchInt(move _12) -> [false: bb22, otherwise: bb21];
176 // bb21: { // bindings for arm 1
178 // FakeRead(ForMatchGuard, _3);
179 // FakeRead(ForMatchGuard, _4);
180 // FakeRead(ForGuardBinding, _6);
181 // FakeRead(ForGuardBinding, _8);
183 // _5 = (_2.0: bool);
185 // _7 = move (_2.2: std::string::String);
188 // bb22: { // Guard otherwise case - second time
192 // falseEdges -> [real: bb6, imaginary: bb4];
194 // bb23: { // rest of arm 1
203 // drop(_16) -> [return: bb27, unwind: bb13];
205 // bb25: { // bindings for arm 2 - first pattern
207 // _15 = (_2.1: bool);
209 // _16 = move (_2.2: std::string::String);
212 // bb26: { // bindings for arm 2 - second pattern
214 // _15 = (_2.1: bool);
216 // _16 = move (_2.2: std::string::String);
219 // bb27: { // rest of arm 2
225 // drop(_2) -> [return: bb12, unwind: bb1];
227 // END rustc.complicated_match.SimplifyCfg-initial.after.mir
228 // START rustc.complicated_match.ElaborateDrops.after.mir
229 // let _16: std::string::String; // No drop flags, which would come after this.
231 // END rustc.complicated_match.ElaborateDrops.after.mir