]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/match_false_edges.rs
Rollup merge of #56425 - scottmcm:redo-vec-set_len-docs, r=Centril
[rust.git] / src / test / mir-opt / match_false_edges.rs
1 // compile-flags: -Z borrowck=mir
2
3 fn guard() -> bool {
4     false
5 }
6
7 fn guard2(_:i32) -> bool {
8     true
9 }
10
11 // no_mangle to make sure this gets instantiated even in an executable.
12 #[no_mangle]
13 pub fn full_tested_match() {
14     let _ = match Some(42) {
15         Some(x) if guard() => (1, x),
16         Some(y) => (2, y),
17         None => (3, 3),
18     };
19 }
20
21 // no_mangle to make sure this gets instantiated even in an executable.
22 #[no_mangle]
23 pub fn full_tested_match2() {
24     let _ = match Some(42) {
25         Some(x) if guard() => (1, x),
26         None => (3, 3),
27         Some(y) => (2, y),
28     };
29 }
30
31 fn main() {
32     let _ = match Some(1) {
33         Some(_w) if guard() => 1,
34         _x => 2,
35         Some(y) if guard2(y) => 3,
36         _z => 4,
37     };
38 }
39
40 // END RUST SOURCE
41 //
42 // START rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
43 //  bb0: {
44 //      ...
45 //      _2 = std::option::Option<i32>::Some(const 42i32,);
46 //      FakeRead(ForMatchedPlace, _2);
47 //      _7 = discriminant(_2);
48 //      _9 = &shallow (promoted[2]: std::option::Option<i32>);
49 //      _10 = &(((promoted[1]: std::option::Option<i32>) as Some).0: i32);
50 //      switchInt(move _7) -> [0isize: bb5, 1isize: bb3, otherwise: bb7];
51 //  }
52 //  bb1: {
53 //      resume;
54 //  }
55 //  bb2: {  // arm1
56 //      _1 = (const 3i32, const 3i32);
57 //      goto -> bb13;
58 //  }
59 //  bb3: { // binding3(empty) and arm3
60 //      FakeRead(ForMatchGuard, _9);
61 //      FakeRead(ForMatchGuard, _10);
62 //      falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
63 //  }
64 //  bb4: {
65 //      FakeRead(ForMatchGuard, _9);
66 //      FakeRead(ForMatchGuard, _10);
67 //      falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding2
68 //  }
69 //  bb5: {
70 //      FakeRead(ForMatchGuard, _9);
71 //      FakeRead(ForMatchGuard, _10);
72 //      falseEdges -> [real: bb2, imaginary: bb6]; //pre_binding3
73 //  }
74 //  bb6: {
75 //      unreachable;
76 //  }
77 //  bb7: {
78 //      unreachable;
79 //  }
80 //  bb8: { // binding1 and guard
81 //      StorageLive(_5);
82 //      _5 = &(((promoted[0]: std::option::Option<i32>) as Some).0: i32);
83 //      StorageLive(_8);
84 //      _8 = const guard() -> [return: bb9, unwind: bb1];
85 //  }
86 //  bb9: {
87 //      switchInt(move _8) -> [false: bb10, otherwise: bb11];
88 //  }
89 //  bb10: { // to pre_binding2
90 //      falseEdges -> [real: bb4, imaginary: bb4];
91 //  }
92 //  bb11: { // bindingNoLandingPads.before.mir2 and arm2
93 //      StorageLive(_3);
94 //      _3 = ((_2 as Some).0: i32);
95 //      StorageLive(_11);
96 //      _11 = _3;
97 //      _1 = (const 1i32, move _11);
98 //      StorageDead(_11);
99 //      goto -> bb13;
100 //  }
101 //  bb12: {
102 //      StorageLive(_6);
103 //      _6 = ((_2 as Some).0: i32);
104 //      StorageLive(_12);
105 //      _12 = _6;
106 //      _1 = (const 2i32, move_12);
107 //      StorageDead(_12);
108 //      goto -> bb13;
109 //  }
110 //  bb13: {
111 //      ...
112 //      return;
113 //  }
114 // END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
115 //
116 // START rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
117 //  bb0: {
118 //      ...
119 //      _2 = std::option::Option<i32>::Some(const 42i32,);
120 //      FakeRead(ForMatchedPlace, _2);
121 //      _7 = discriminant(_2);
122 //      _9 = &shallow _2;
123 //      _10 = &((_2 as Some).0: i32);
124 //      switchInt(move _7) -> [0isize: bb4, 1isize: bb3, otherwise: bb7];
125 //  }
126 //  bb1: {
127 //      resume;
128 //  }
129 //  bb2: { // arm2
130 //      _1 = (const 3i32, const 3i32);
131 //      goto -> bb13;
132 //  }
133 //  bb3: {
134 //      FakeRead(ForMatchGuard, _9);
135 //      FakeRead(ForMatchGuard, _10);
136 //      falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
137 //  }
138 //  bb4: {
139 //      FakeRead(ForMatchGuard, _9);
140 //      FakeRead(ForMatchGuard, _10);
141 //      falseEdges -> [real: bb2, imaginary: bb5]; //pre_binding2
142 //  }
143 //  bb5: {
144 //      FakeRead(ForMatchGuard, _9);
145 //      FakeRead(ForMatchGuard, _10);
146 //      falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding3
147 //  }
148 //  bb6: {
149 //      unreachable;
150 //  }
151 //  bb7: {
152 //      unreachable;
153 //  }
154 //  bb8: { // binding1 and guard
155 //      StorageLive(_5);
156 //      _5 = &((_2 as Some).0: i32);
157 //      StorageLive(_8);
158 //      _8 = const guard() -> [return: bb9, unwind: bb1];
159 //  }
160 //  bb9: { // end of guard
161 //      switchInt(move _8) -> [false: bb10, otherwise: bb11];
162 //  }
163 //  bb10: { // to pre_binding3 (can skip 2 since this is `Some`)
164 //      falseEdges -> [real: bb5, imaginary: bb4];
165 //  }
166 //  bb11: { // arm1
167 //      StorageLive(_3);
168 //      _3 = ((_2 as Some).0: i32);
169 //      StorageLive(_11);
170 //      _11 = _3;
171 //      _1 = (const 1i32, move _11);
172 //      StorageDead(_11);
173 //      goto -> bb13;
174 //  }
175 //  bb12: { // binding3 and arm3
176 //      StorageLive(_6);
177 //      _6 = ((_2 as Some).0: i32);
178 //      StorageLive(_12);
179 //      _12 = _6;
180 //      _1 = (const 2i32, move _12);
181 //      StorageDead(_12);
182 //      goto -> bb13;
183 //  }
184 //  bb13: {
185 //      ...
186 //      return;
187 //  }
188 // END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
189 //
190 // START rustc.main.QualifyAndPromoteConstants.before.mir
191 // bb0: {
192 //     ...
193 //     _2 = std::option::Option<i32>::Some(const 1i32,);
194 //     FakeRead(ForMatchedPlace, _2);
195 //     _11 = discriminant(_2);
196 //    _16 = &shallow _2;
197 //    _17 = &((_2 as Some).0: i32);
198 //     switchInt(move _11) -> [1isize: bb2, otherwise: bb3];
199 // }
200 // bb1: {
201 //     resume;
202 // }
203 // bb2: {
204 //      FakeRead(ForMatchGuard, _16);
205 //      FakeRead(ForMatchGuard, _17);
206 //     falseEdges -> [real: bb7, imaginary: bb3]; //pre_binding1
207 // }
208 // bb3: {
209 //      FakeRead(ForMatchGuard, _16);
210 //      FakeRead(ForMatchGuard, _17);
211 //     falseEdges -> [real: bb11, imaginary: bb4]; //pre_binding2
212 // }
213 // bb4: {
214 //      FakeRead(ForMatchGuard, _16);
215 //      FakeRead(ForMatchGuard, _17);
216 //     falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding3
217 // }
218 // bb5: {
219 //      FakeRead(ForMatchGuard, _16);
220 //      FakeRead(ForMatchGuard, _17);
221 //     falseEdges -> [real: bb16, imaginary: bb6]; //pre_binding4
222 // }
223 // bb6: {
224 //     unreachable;
225 // }
226 // bb7: { // binding1: Some(w) if guard()
227 //     StorageLive(_5);
228 //     _5 = &((_2 as Some).0: i32);
229 //     StorageLive(_12);
230 //     _12 = const guard() -> [return: bb8, unwind: bb1];
231 // }
232 // bb8: { //end of guard
233 //     switchInt(move _12) -> [false: bb9, otherwise: bb10];
234 // }
235 // bb9: { // to pre_binding2
236 //     falseEdges -> [real: bb3, imaginary: bb3];
237 // }
238 // bb10: { // set up bindings for arm1
239 //     StorageLive(_3);
240 //     _3 = ((_2 as Some).0: i32);
241 //     _1 = const 1i32;
242 //     goto -> bb17;
243 // }
244 // bb11: { // binding2 & arm2
245 //     StorageLive(_6);
246 //     _6 = _2;
247 //     _1 = const 2i32;
248 //     goto -> bb17;
249 // }
250 // bb12: { // binding3: Some(y) if guard2(y)
251 //     StorageLive(_9);
252 //     _9 = &((_2 as Some).0: i32);
253 //     StorageLive(_14);
254 //     StorageLive(_15);
255 //     _15 = (*_9);
256 //     _14 = const guard2(move _15) -> [return: bb13, unwind: bb1];
257 // }
258 // bb13: { // end of guard2
259 //     StorageDead(_15);
260 //     switchInt(move _14) -> [false: bb14, otherwise: bb15];
261 // }
262 // bb14: { // to pre_binding4
263 //     falseEdges -> [real: bb5, imaginary: bb5];
264 // }
265 // bb15: { // set up bindings for arm3
266 //     StorageLive(_7);
267 //     _7 = ((_2 as Some).0: i32);
268 //     _1 = const 3i32;
269 //     goto -> bb17;
270 // }
271 // bb16: { // binding4 & arm4
272 //     StorageLive(_10);
273 //     _10 = _2;
274 //     _1 = const 4i32;
275 //     goto -> bb17;
276 // }
277 // bb17: {
278 //     ...
279 //     return;
280 // }
281 // END rustc.main.QualifyAndPromoteConstants.before.mir