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.
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.
11 // compile-flags: -Z borrowck=mir
17 fn guard2(_:i32) -> bool {
21 // no_mangle to make sure this gets instantiated even in an executable.
23 pub fn full_tested_match() {
24 let _ = match Some(42) {
25 Some(x) if guard() => (1, x),
31 // no_mangle to make sure this gets instantiated even in an executable.
33 pub fn full_tested_match2() {
34 let _ = match Some(42) {
35 Some(x) if guard() => (1, x),
42 let _ = match Some(1) {
43 Some(_w) if guard() => 1,
45 Some(y) if guard2(y) => 3,
52 // START rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
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];
66 // _1 = (const 3i32, const 3i32);
69 // bb3: { // binding3(empty) and arm3
70 // FakeRead(ForMatchGuard, _9);
71 // FakeRead(ForMatchGuard, _10);
72 // falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
75 // FakeRead(ForMatchGuard, _9);
76 // FakeRead(ForMatchGuard, _10);
77 // falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding2
80 // FakeRead(ForMatchGuard, _9);
81 // FakeRead(ForMatchGuard, _10);
82 // falseEdges -> [real: bb2, imaginary: bb6]; //pre_binding3
90 // bb8: { // binding1 and guard
92 // _5 = &(((promoted[0]: std::option::Option<i32>) as Some).0: i32);
94 // _8 = const guard() -> [return: bb9, unwind: bb1];
97 // switchInt(move _8) -> [false: bb10, otherwise: bb11];
99 // bb10: { // to pre_binding2
100 // falseEdges -> [real: bb4, imaginary: bb4];
102 // bb11: { // bindingNoLandingPads.before.mir2 and arm2
104 // _3 = ((_2 as Some).0: i32);
107 // _1 = (const 1i32, move _11);
113 // _6 = ((_2 as Some).0: i32);
116 // _1 = (const 2i32, move_12);
124 // END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
126 // START rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
129 // _2 = std::option::Option<i32>::Some(const 42i32,);
130 // FakeRead(ForMatchedPlace, _2);
131 // _7 = discriminant(_2);
133 // _10 = &((_2 as Some).0: i32);
134 // switchInt(move _7) -> [0isize: bb4, 1isize: bb3, otherwise: bb7];
140 // _1 = (const 3i32, const 3i32);
144 // FakeRead(ForMatchGuard, _9);
145 // FakeRead(ForMatchGuard, _10);
146 // falseEdges -> [real: bb8, imaginary: bb4]; //pre_binding1
149 // FakeRead(ForMatchGuard, _9);
150 // FakeRead(ForMatchGuard, _10);
151 // falseEdges -> [real: bb2, imaginary: bb5]; //pre_binding2
154 // FakeRead(ForMatchGuard, _9);
155 // FakeRead(ForMatchGuard, _10);
156 // falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding3
164 // bb8: { // binding1 and guard
166 // _5 = &((_2 as Some).0: i32);
168 // _8 = const guard() -> [return: bb9, unwind: bb1];
170 // bb9: { // end of guard
171 // switchInt(move _8) -> [false: bb10, otherwise: bb11];
173 // bb10: { // to pre_binding3 (can skip 2 since this is `Some`)
174 // falseEdges -> [real: bb5, imaginary: bb4];
178 // _3 = ((_2 as Some).0: i32);
181 // _1 = (const 1i32, move _11);
185 // bb12: { // binding3 and arm3
187 // _6 = ((_2 as Some).0: i32);
190 // _1 = (const 2i32, move _12);
198 // END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
200 // START rustc.main.QualifyAndPromoteConstants.before.mir
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];
214 // FakeRead(ForMatchGuard, _16);
215 // FakeRead(ForMatchGuard, _17);
216 // falseEdges -> [real: bb7, imaginary: bb3]; //pre_binding1
219 // FakeRead(ForMatchGuard, _16);
220 // FakeRead(ForMatchGuard, _17);
221 // falseEdges -> [real: bb11, imaginary: bb4]; //pre_binding2
224 // FakeRead(ForMatchGuard, _16);
225 // FakeRead(ForMatchGuard, _17);
226 // falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding3
229 // FakeRead(ForMatchGuard, _16);
230 // FakeRead(ForMatchGuard, _17);
231 // falseEdges -> [real: bb16, imaginary: bb6]; //pre_binding4
236 // bb7: { // binding1: Some(w) if guard()
238 // _5 = &((_2 as Some).0: i32);
240 // _12 = const guard() -> [return: bb8, unwind: bb1];
242 // bb8: { //end of guard
243 // switchInt(move _12) -> [false: bb9, otherwise: bb10];
245 // bb9: { // to pre_binding2
246 // falseEdges -> [real: bb3, imaginary: bb3];
248 // bb10: { // set up bindings for arm1
250 // _3 = ((_2 as Some).0: i32);
254 // bb11: { // binding2 & arm2
260 // bb12: { // binding3: Some(y) if guard2(y)
262 // _9 = &((_2 as Some).0: i32);
266 // _14 = const guard2(move _15) -> [return: bb13, unwind: bb1];
268 // bb13: { // end of guard2
270 // switchInt(move _14) -> [false: bb14, otherwise: bb15];
272 // bb14: { // to pre_binding4
273 // falseEdges -> [real: bb5, imaginary: bb5];
275 // bb15: { // set up bindings for arm3
277 // _7 = ((_2 as Some).0: i32);
281 // bb16: { // binding4 & arm4
291 // END rustc.main.QualifyAndPromoteConstants.before.mir