]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/separate_const_switch.rs
Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors
[rust.git] / src / test / 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 // EMIT_MIR separate_const_switch.too_complex.ConstProp.diff
8 // EMIT_MIR separate_const_switch.too_complex.PreCodegen.after.mir
9 fn too_complex(x: Result<i32, usize>) -> Option<i32> {
10     // The pass should break the outer match into
11     // two blocks that only have one parent each.
12     // Parents are one of the two branches of the first
13     // match, so a later pass can propagate constants.
14     match {
15         match x {
16             Ok(v) => ControlFlow::Continue(v),
17             Err(r) => ControlFlow::Break(r),
18         }
19     } {
20         ControlFlow::Continue(v) => Some(v),
21         ControlFlow::Break(r) => None,
22     }
23 }
24
25 // EMIT_MIR separate_const_switch.identity.SeparateConstSwitch.diff
26 // EMIT_MIR separate_const_switch.identity.ConstProp.diff
27 // EMIT_MIR separate_const_switch.identity.PreCodegen.after.mir
28 fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
29     Ok(x?)
30 }
31
32 fn main() {
33     too_complex(Ok(0));
34     identity(Ok(0));
35 }