]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/match_false_edges.rs
Rollup merge of #47846 - roblabla:bugfix-ocaml, r=kennytm
[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 //      _3 = discriminant(_2);
57 //      _6 = discriminant(_2);
58 //      switchInt(move _6) -> [0isize: bb6, 1isize: bb4, otherwise: bb8];
59 //  }
60 //  bb1: {
61 //      resume;
62 //  }
63 //  bb2: {  // arm1
64 //      StorageLive(_8);
65 //      _8 = _4;
66 //      _1 = (const 1i32, move _8);
67 //      StorageDead(_8);
68 //      goto -> bb13;
69 //  }
70 //  bb3: { // binding3(empty) and arm3
71 //      _1 = (const 3i32, const 3i32);
72 //      goto -> bb13;
73 //  }
74 //  bb4: {
75 //      falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1
76 //  }
77 //  bb5: {
78 //      falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding2
79 //  }
80 //  bb6: {
81 //      falseEdges -> [real: bb3, imaginary: bb7]; //pre_binding3
82 //  }
83 //  bb7: {
84 //      unreachable;
85 //  }
86 //  bb8: {
87 //      unreachable;
88 //  }
89 //  bb9: { // binding1 and guard
90 //      StorageLive(_4);
91 //      _4 = ((_2 as Some).0: i32);
92 //      StorageLive(_7);
93 //      _7 = const guard() -> [return: bb10, unwind: bb1];
94 //  }
95 //  bb10: { // end of guard
96 //      switchInt(move _7) -> [0u8: bb11, otherwise: bb2];
97 //  }
98 //  bb11: { // to pre_binding2
99 //      falseEdges -> [real: bb5, imaginary: bb5];
100 //  }
101 //  bb12: { // bindingNoLandingPads.before.mir2 and arm2
102 //      StorageLive(_5);
103 //      _5 = ((_2 as Some).0: i32);
104 //      StorageLive(_9);
105 //      _9 = _5;
106 //      _1 = (const 2i32, move _9);
107 //      StorageDead(_9);
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 //      _3 = discriminant(_2);
121 //      _6 = discriminant(_2);
122 //      switchInt(move _6) -> [0isize: bb5, 1isize: bb4, otherwise: bb8];
123 //  }
124 //  bb1: {
125 //      resume;
126 //  }
127 //  bb2: { // arm1
128 //      StorageLive(_8);
129 //      _8 = _4;
130 //      _1 = (const 1i32, move _8);
131 //      StorageDead(_8);
132 //      goto -> bb13;
133 //  }
134 //  bb3: { // binding3(empty) and arm3
135 //      _1 = (const 3i32, const 3i32);
136 //      goto -> bb13;
137 //  }
138 //  bb4: {
139 //      falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1
140 //  }
141 //  bb5: {
142 //      falseEdges -> [real: bb3, imaginary: bb6]; //pre_binding2
143 //  }
144 //  bb6: {
145 //      falseEdges -> [real: bb12, imaginary: bb7]; //pre_binding3
146 //  }
147 //  bb7: {
148 //      unreachable;
149 //  }
150 //  bb8: {
151 //      unreachable;
152 //  }
153 //  bb9: { // binding1 and guard
154 //      StorageLive(_4);
155 //      _4 = ((_2 as Some).0: i32);
156 //      StorageLive(_7);
157 //      _7 = const guard() -> [return: bb10, unwind: bb1];
158 //  }
159 //  bb10: { // end of guard
160 //      switchInt(move _7) -> [0u8: bb11, otherwise: bb2];
161 //  }
162 //  bb11: { // to pre_binding2
163 //      falseEdges -> [real: bb6, imaginary: bb5];
164 //  }
165 //  bb12: { // binding2 and arm2
166 //      StorageLive(_5);
167 //      _5 = ((_2 as Some).0: i32);
168 //      StorageLive(_9);
169 //      _9 = _5;
170 //      _1 = (const 2i32, move _9);
171 //      StorageDead(_9);
172 //      goto -> bb13;
173 //  }
174 //  bb13: {
175 //      ...
176 //      return;
177 //  }
178 // END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
179 //
180 // START rustc.main.QualifyAndPromoteConstants.before.mir
181 // bb0: {
182 //     ...
183 //     _2 = std::option::Option<i32>::Some(const 1i32,);
184 //     _3 = discriminant(_2);
185 //     _8 = discriminant(_2);
186 //     switchInt(move _8) -> [1isize: bb4, otherwise: bb5];
187 // }
188 // bb1: {
189 //     resume;
190 // }
191 // bb2: { // arm1
192 //     _1 = const 1i32;
193 //     goto -> bb17;
194 // }
195 // bb3: { // arm3
196 //     _1 = const 3i32;
197 //     goto -> bb17;
198 // }
199 //
200 // bb4: {
201 //     falseEdges -> [real: bb9, imaginary: bb5]; //pre_binding1
202 // }
203 // bb5: {
204 //     falseEdges -> [real: bb12, imaginary: bb6]; //pre_binding2
205 // }
206 // bb6: {
207 //     falseEdges -> [real: bb13, imaginary: bb7]; //pre_binding3
208 // }
209 // bb7: {
210 //     falseEdges -> [real: bb16, imaginary: bb8]; //pre_binding4
211 // }
212 // bb8: {
213 //     unreachable;
214 // }
215 // bb9: { // binding1: Some(w) if guard()
216 //     StorageLive(_4);
217 //     _4 = ((_2 as Some).0: i32);
218 //     StorageLive(_9);
219 //     _9 = const guard() -> [return: bb10, unwind: bb1];
220 // }
221 // bb10: { //end of guard
222 //    switchInt(move _9) -> [0u8: bb11, otherwise: bb2];
223 // }
224 // bb11: { // to pre_binding2
225 //     falseEdges -> [real: bb5, imaginary: bb5];
226 // }
227 // bb12: { // binding2 & arm2
228 //     StorageLive(_5);
229 //     _5 = _2;
230 //     _1 = const 2i32;
231 //     goto -> bb17;
232 // }
233 // bb13: { // binding3: Some(y) if guard2(y)
234 //     StorageLive(_6);
235 //     _6 = ((_2 as Some).0: i32);
236 //     StorageLive(_11);
237 //     StorageLive(_12);
238 //     _12 = _6;
239 //     _11 = const guard2(move _12) -> [return: bb14, unwind: bb1];
240 // }
241 // bb14: { // end of guard2
242 //     StorageDead(_12);
243 //     switchInt(move _11) -> [0u8: bb15, otherwise: bb3];
244 // }
245 // bb15: { // to pre_binding4
246 //     falseEdges -> [real: bb7, imaginary: bb7];
247 // }
248 // bb16: { // binding4 & arm4
249 //     StorageLive(_7);
250 //     _7 = _2;
251 //     _1 = const 4i32;
252 //     goto -> bb17;
253 // }
254 // bb17: {
255 //     ...
256 //     return;
257 // }
258 // END rustc.main.QualifyAndPromoteConstants.before.mir