summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/uninhabited_enum_branching.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/mir-opt/uninhabited_enum_branching.rs69
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();
+}