diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
commit | cec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch) | |
tree | 47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /tests/mir-opt/uninhabited_enum_branching.rs | |
parent | Adding debian version 1.74.1+dfsg1-1. (diff) | |
download | rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/mir-opt/uninhabited_enum_branching.rs')
-rw-r--r-- | tests/mir-opt/uninhabited_enum_branching.rs | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/tests/mir-opt/uninhabited_enum_branching.rs b/tests/mir-opt/uninhabited_enum_branching.rs index 0ef604c30..60389117b 100644 --- a/tests/mir-opt/uninhabited_enum_branching.rs +++ b/tests/mir-opt/uninhabited_enum_branching.rs @@ -1,10 +1,11 @@ -enum Empty { } +// unit-test: UninhabitedEnumBranching +enum Empty {} // test matching an enum with uninhabited variants enum Test1 { A(Empty), B(Empty), - C + C, } // test an enum where the discriminants don't match the variant indexes @@ -14,17 +15,75 @@ enum Test2 { E = 5, } -// EMIT_MIR uninhabited_enum_branching.main.UninhabitedEnumBranching.diff -// EMIT_MIR uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir -fn main() { +// test matching an enum with uninhabited variants and multiple inhabited +enum Test3 { + A(Empty), + B(Empty), + C, + D, +} + +struct Plop { + xx: u32, + test3: Test3, +} + +// EMIT_MIR uninhabited_enum_branching.simple.UninhabitedEnumBranching.diff +fn simple() { + // CHECK-LABEL: fn simple( + // CHECK: [[discr:_.*]] = discriminant( + // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb1, otherwise: [[unreachable]]]; + // CHECK: [[unreachable]]: { + // CHECK-NEXT: unreachable; match Test1::C { Test1::A(_) => "A(Empty)", Test1::B(_) => "B(Empty)", Test1::C => "C", }; +} +// EMIT_MIR uninhabited_enum_branching.custom_discriminant.UninhabitedEnumBranching.diff +fn custom_discriminant() { + // CHECK-LABEL: fn custom_discriminant( + // CHECK: [[discr:_.*]] = discriminant( + // CHECK: switchInt(move [[discr]]) -> [4: bb3, 5: bb1, otherwise: bb5]; + // CHECK: bb5: { + // CHECK-NEXT: unreachable; match Test2::D { Test2::D => "D", Test2::E => "E", }; } + +// EMIT_MIR uninhabited_enum_branching.byref.UninhabitedEnumBranching.diff +fn byref() { + // CHECK-LABEL: fn byref( + let plop = Plop { xx: 51, test3: Test3::C }; + + // CHECK: [[ref_discr:_.*]] = discriminant((* + // CHECK: switchInt(move [[ref_discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb5, 3: bb1, otherwise: [[unreachable]]]; + match &plop.test3 { + Test3::A(_) => "A(Empty)", + Test3::B(_) => "B(Empty)", + Test3::C => "C", + Test3::D => "D", + }; + + // CHECK: [[discr:_.*]] = discriminant( + // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable]], 1: [[unreachable]], 2: bb10, 3: bb7, otherwise: [[unreachable]]]; + match plop.test3 { + Test3::A(_) => "A(Empty)", + Test3::B(_) => "B(Empty)", + Test3::C => "C", + Test3::D => "D", + }; + + // CHECK: [[unreachable]]: { + // CHECK-NEXT: unreachable; +} + +fn main() { + simple(); + custom_discriminant(); + byref(); +} |