]> git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/match_false_edges.rs
Update upstream source from tag 'upstream/1.28.0_beta.14+dfsg1'
[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 // _14 = promoted[1];
58 // _4 = &(*_14);
59 // _9 = discriminant(_2);
60 // switchInt(move _9) -> [0isize: bb5, 1isize: bb3, otherwise: bb7];
61 // }
62 // bb1: {
63 // resume;
64 // }
65 // bb2: { // arm1
66 // _1 = (const 3i32, const 3i32);
67 // goto -> bb13;
68 // }
69 // bb3: { // binding3(empty) and arm3
70 // ReadForMatch(_4);
71 // falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
72 // }
73 // bb4: {
74 // ReadForMatch(_4);
75 // falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding2
76 // }
77 // bb5: {
78 // ReadForMatch(_4);
79 // falseEdges -> [real: bb2, imaginary: bb6]; //pre_binding3
80 // }
81 // bb6: {
82 // unreachable;
83 // }
84 // bb7: {
85 // unreachable;
86 // }
87 // bb8: { // binding1 and guard
88 // StorageLive(_7);
89 // _13 = promoted[0];
90 // _7 = &(((*_13) as Some).0: i32);
91 // StorageLive(_10);
92 // _10 = const guard() -> [return: bb9, unwind: bb1];
93 // }
94 // bb9: {
95 // switchInt(move _10) -> [false: bb10, otherwise: bb11];
96 // }
97 // bb10: { // to pre_binding2
98 // falseEdges -> [real: bb4, imaginary: bb4];
99 // }
100 // bb11: { // bindingNoLandingPads.before.mir2 and arm2
101 // StorageLive(_5);
102 // _5 = ((_2 as Some).0: i32);
103 // StorageLive(_11);
104 // _11 = _5;
105 // _1 = (const 1i32, move _11);
106 // StorageDead(_11);
107 // goto -> bb13;
108 // }
109 // bb12: {
110 // StorageLive(_8);
111 // _8 = ((_2 as Some).0: i32);
112 // StorageLive(_12);
113 // _12 = _8;
114 // _1 = (const 2i32, move_12);
115 // StorageDead(_12);
116 // goto -> bb13;
117 // }
118 // bb13: {
119 // ...
120 // return;
121 // }
122 // END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
123 //
124 // START rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
125 // bb0: {
126 // ...
127 // _2 = std::option::Option<i32>::Some(const 42i32,);
128 // _3 = discriminant(_2);
129 // _4 = &_2;
130 // _9 = discriminant(_2);
131 // switchInt(move _9) -> [0isize: bb4, 1isize: bb3, otherwise: bb7];
132 // }
133 // bb1: {
134 // resume;
135 // }
136 // bb2: { // arm2
137 // _1 = (const 3i32, const 3i32);
138 // goto -> bb13;
139 // }
140 // bb3: {
141 // ReadForMatch(_4);
142 // falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
143 // }
144 // bb4: {
145 // ReadForMatch(_4);
146 // falseEdges -> [real: bb2, imaginary: bb5]; //pre_binding2
147 // }
148 // bb5: {
149 // ReadForMatch(_4);
150 // falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding3
151 // }
152 // bb6: {
153 // unreachable;
154 // }
155 // bb7: {
156 // unreachable;
157 // }
158 // bb8: { // binding1 and guard
159 // StorageLive(_7);
160 // _7 = &((_2 as Some).0: i32);
161 // StorageLive(_10);
162 // _10 = const guard() -> [return: bb9, unwind: bb1];
163 // }
164 // bb9: { // end of guard
165 // switchInt(move _10) -> [false: bb10, otherwise: bb11];
166 // }
167 // bb10: { // to pre_binding3 (can skip 2 since this is `Some`)
168 // falseEdges -> [real: bb5, imaginary: bb4];
169 // }
170 // bb11: { // arm1
171 // StorageLive(_5);
172 // _5 = ((_2 as Some).0: i32);
173 // StorageLive(_11);
174 // _11 = _5;
175 // _1 = (const 1i32, move _11);
176 // StorageDead(_11);
177 // goto -> bb13;
178 // }
179 // bb12: { // binding3 and arm3
180 // StorageLive(_8);
181 // _8 = ((_2 as Some).0: i32);
182 // StorageLive(_12);
183 // _12 = _8;
184 // _1 = (const 2i32, move _12);
185 // StorageDead(_12);
186 // goto -> bb13;
187 // }
188 // bb13: {
189 // ...
190 // return;
191 // }
192 // END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
193 //
194 // START rustc.main.QualifyAndPromoteConstants.before.mir
195 // bb0: {
196 // ...
197 // _2 = std::option::Option<i32>::Some(const 1i32,);
198 // _3 = discriminant(_2);
199 // _4 = &_2;
200 // _13 = discriminant(_2);
201 // switchInt(move _13) -> [1isize: bb2, otherwise: bb3];
202 // }
203 // bb1: {
204 // resume;
205 // }
206 // bb2: {
207 // ReadForMatch(_4);
208 // falseEdges -> [real: bb7, imaginary: bb3]; //pre_binding1
209 // }
210 // bb3: {
211 // ReadForMatch(_4);
212 // falseEdges -> [real: bb11, imaginary: bb4]; //pre_binding2
213 // }
214 // bb4: {
215 // ReadForMatch(_4);
216 // falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding3
217 // }
218 // bb5: {
219 // ReadForMatch(_4);
220 // falseEdges -> [real: bb16, imaginary: bb6]; //pre_binding4
221 // }
222 // bb6: {
223 // unreachable;
224 // }
225 // bb7: { // binding1: Some(w) if guard()
226 // StorageLive(_7);
227 // _7 = &((_2 as Some).0: i32);
228 // StorageLive(_14);
229 // _14 = const guard() -> [return: bb8, unwind: bb1];
230 // }
231 // bb8: { //end of guard
232 // switchInt(move _14) -> [false: bb9, otherwise: bb10];
233 // }
234 // bb9: { // to pre_binding2
235 // falseEdges -> [real: bb3, imaginary: bb3];
236 // }
237 // bb10: { // set up bindings for arm1
238 // StorageLive(_5);
239 // _5 = ((_2 as Some).0: i32);
240 // _1 = const 1i32;
241 // goto -> bb17;
242 // }
243 // bb11: { // binding2 & arm2
244 // StorageLive(_8);
245 // _8 = _2;
246 // _1 = const 2i32;
247 // goto -> bb17;
248 // }
249 // bb12: { // binding3: Some(y) if guard2(y)
250 // StorageLive(_11);
251 // _11 = &((_2 as Some).0: i32);
252 // StorageLive(_16);
253 // StorageLive(_17);
254 // _17 = (*_11);
255 // _16 = const guard2(move _17) -> [return: bb13, unwind: bb1];
256 // }
257 // bb13: { // end of guard2
258 // StorageDead(_17);
259 // switchInt(move _16) -> [false: bb14, otherwise: bb15];
260 // }
261 // bb14: { // to pre_binding4
262 // falseEdges -> [real: bb5, imaginary: bb5];
263 // }
264 // bb15: { // set up bindings for arm3
265 // StorageLive(_9);
266 // _9 = ((_2 as Some).0: i32);
267 // _1 = const 3i32;
268 // goto -> bb17;
269 // }
270 // bb16: { // binding4 & arm4
271 // StorageLive(_12);
272 // _12 = _2;
273 // _1 = const 4i32;
274 // goto -> bb17;
275 // }
276 // bb17: {
277 // ...
278 // return;
279 // }
280 // END rustc.main.QualifyAndPromoteConstants.before.mir