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