]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/separate_const_switch.rs
Rollup merge of #106446 - bzEq:fix-unwind-lsda, r=Amanieu
[rust.git] / tests / mir-opt / separate_const_switch.rs
1 #![feature(control_flow_enum)]
2 #![feature(try_trait_v2)]
3
4 use std::ops::ControlFlow;
5
6 // EMIT_MIR separate_const_switch.too_complex.SeparateConstSwitch.diff
7 fn too_complex(x: Result<i32, usize>) -> Option<i32> {
8     // The pass should break the outer match into
9     // two blocks that only have one parent each.
10     // Parents are one of the two branches of the first
11     // match, so a later pass can propagate constants.
12     match {
13         match x {
14             Ok(v) => ControlFlow::Continue(v),
15             Err(r) => ControlFlow::Break(r),
16         }
17     } {
18         ControlFlow::Continue(v) => Some(v),
19         ControlFlow::Break(r) => None,
20     }
21 }
22
23 // EMIT_MIR separate_const_switch.identity.SeparateConstSwitch.diff
24 fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
25     Ok(x?)
26 }
27
28 fn main() {
29     too_complex(Ok(0));
30     identity(Ok(0));
31 }