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