]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/simplify-arm-identity.rs
Rollup merge of #68978 - ecstatic-morse:const-int-pow, r=oli-obk
[rust.git] / src / test / mir-opt / simplify-arm-identity.rs
1 // Checks that `SimplifyArmIdentity` is not applied if enums have incompatible layouts.
2 // Regression test for issue #66856.
3 //
4 // compile-flags: -Zmir-opt-level=2
5
6 enum Src {
7     Foo(u8),
8     Bar,
9 }
10
11 enum Dst {
12     Foo(u8),
13 }
14
15 fn main() {
16     let e: Src = Src::Foo(0);
17     let _: Dst = match e {
18         Src::Foo(x) => Dst::Foo(x),
19         Src::Bar => Dst::Foo(0),
20     };
21 }
22
23 // END RUST SOURCE
24 // START rustc.main.SimplifyArmIdentity.before.mir
25 // fn main() -> () {
26 //     ...
27 //     bb0: {
28 //         StorageLive(_1);
29 //         ((_1 as Foo).0: u8) = const 0u8;
30 //         discriminant(_1) = 0;
31 //         StorageLive(_2);
32 //         _3 = discriminant(_1);
33 //         switchInt(move _3) -> [0isize: bb3, 1isize: bb1, otherwise: bb2];
34 //     }
35 //     bb1: {
36 //         ((_2 as Foo).0: u8) = const 0u8;
37 //         discriminant(_2) = 0;
38 //         goto -> bb4;
39 //     }
40 //     ...
41 //     bb3: {
42 //         _4 = ((_1 as Foo).0: u8);
43 //         ((_2 as Foo).0: u8) = move _4;
44 //         discriminant(_2) = 0;
45 //         goto -> bb4;
46 //     }
47 //     ...
48 // }
49 // END rustc.main.SimplifyArmIdentity.before.mir
50 // START rustc.main.SimplifyArmIdentity.after.mir
51 // fn main() -> () {
52 //     ...
53 //     bb0: {
54 //         StorageLive(_1);
55 //         ((_1 as Foo).0: u8) = const 0u8;
56 //         discriminant(_1) = 0;
57 //         StorageLive(_2);
58 //         _3 = discriminant(_1);
59 //         switchInt(move _3) -> [0isize: bb3, 1isize: bb1, otherwise: bb2];
60 //     }
61 //     bb1: {
62 //         ((_2 as Foo).0: u8) = const 0u8;
63 //         discriminant(_2) = 0;
64 //         goto -> bb4;
65 //     }
66 //     ...
67 //     bb3: {
68 //         _4 = ((_1 as Foo).0: u8);
69 //         ((_2 as Foo).0: u8) = move _4;
70 //         discriminant(_2) = 0;
71 //         goto -> bb4;
72 //     }
73 //     ...
74 // }
75 // END rustc.main.SimplifyArmIdentity.after.mir