summaryrefslogtreecommitdiffstats
path: root/tests/ui/mir/mir_codegen_switch.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/mir/mir_codegen_switch.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/mir/mir_codegen_switch.rs')
-rw-r--r--tests/ui/mir/mir_codegen_switch.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/mir/mir_codegen_switch.rs b/tests/ui/mir/mir_codegen_switch.rs
new file mode 100644
index 000000000..9c93499d9
--- /dev/null
+++ b/tests/ui/mir/mir_codegen_switch.rs
@@ -0,0 +1,35 @@
+// run-pass
+enum Abc {
+ A(#[allow(unused_tuple_struct_fields)] u8),
+ B(#[allow(unused_tuple_struct_fields)] i8),
+ C,
+ D,
+}
+
+fn foo(x: Abc) -> i32 {
+ match x {
+ Abc::C => 3,
+ Abc::D => 4,
+ Abc::B(_) => 2,
+ Abc::A(_) => 1,
+ }
+}
+
+fn foo2(x: Abc) -> bool {
+ match x {
+ Abc::D => true,
+ _ => false
+ }
+}
+
+fn main() {
+ assert_eq!(1, foo(Abc::A(42)));
+ assert_eq!(2, foo(Abc::B(-100)));
+ assert_eq!(3, foo(Abc::C));
+ assert_eq!(4, foo(Abc::D));
+
+ assert_eq!(false, foo2(Abc::A(1)));
+ assert_eq!(false, foo2(Abc::B(2)));
+ assert_eq!(false, foo2(Abc::C));
+ assert_eq!(true, foo2(Abc::D));
+}