summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const-variant-count.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/consts/const-variant-count.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/consts/const-variant-count.rs')
-rw-r--r--tests/ui/consts/const-variant-count.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/ui/consts/const-variant-count.rs b/tests/ui/consts/const-variant-count.rs
new file mode 100644
index 000000000..50eaeeb46
--- /dev/null
+++ b/tests/ui/consts/const-variant-count.rs
@@ -0,0 +1,47 @@
+// run-pass
+#![allow(dead_code, enum_intrinsics_non_enums)]
+#![feature(variant_count)]
+#![feature(never_type)]
+
+use std::mem::variant_count;
+
+enum Void {}
+
+enum Foo {
+ A,
+ B,
+ C,
+}
+
+enum Bar {
+ A,
+ B,
+ C,
+ D(usize),
+ E { field_1: usize, field_2: Foo },
+}
+
+struct Baz {
+ a: u32,
+ b: *const u8,
+}
+
+const TEST_VOID: usize = variant_count::<Void>();
+const TEST_FOO: usize = variant_count::<Foo>();
+const TEST_BAR: usize = variant_count::<Bar>();
+
+const NO_ICE_STRUCT: usize = variant_count::<Baz>();
+const NO_ICE_BOOL: usize = variant_count::<bool>();
+const NO_ICE_PRIM: usize = variant_count::<*const u8>();
+
+fn main() {
+ assert_eq!(TEST_VOID, 0);
+ assert_eq!(TEST_FOO, 3);
+ assert_eq!(TEST_BAR, 5);
+ assert_eq!(variant_count::<Void>(), 0);
+ assert_eq!(variant_count::<Foo>(), 3);
+ assert_eq!(variant_count::<Bar>(), 5);
+ assert_eq!(variant_count::<Option<char>>(), 2);
+ assert_eq!(variant_count::<Option<!>>(), 2);
+ assert_eq!(variant_count::<Result<!, !>>(), 2);
+}