]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/try_identity_e2e.rs
Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-from-rustfmt
[rust.git] / tests / mir-opt / try_identity_e2e.rs
1 // Track the status of MIR optimizations simplifying `Ok(res?)` for both the old and new desugarings
2 // of that syntax.
3
4 use std::ops::ControlFlow;
5
6 // EMIT_MIR try_identity_e2e.new.PreCodegen.after.mir
7 fn new<T, E>(x: Result<T, E>) -> Result<T, E> {
8     Ok(
9         match {
10             match x {
11                 Ok(v) => ControlFlow::Continue(v),
12                 Err(e) => ControlFlow::Break(e),
13             }
14         } {
15             ControlFlow::Continue(v) => v,
16             ControlFlow::Break(e) => return Err(e),
17         }
18     )
19 }
20
21 // EMIT_MIR try_identity_e2e.old.PreCodegen.after.mir
22 fn old<T, E>(x: Result<T, E>) -> Result<T, E> {
23     Ok(
24         match x {
25             Ok(v) => v,
26             Err(e) => return Err(e),
27         }
28     )
29 }
30
31 fn main() {
32     let _ = new::<(), ()>(Ok(()));
33     let _ = old::<(), ()>(Ok(()));
34 }