summaryrefslogtreecommitdiffstats
path: root/src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs')
-rw-r--r--src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs b/src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
new file mode 100644
index 000000000..18e02b0d2
--- /dev/null
+++ b/src/test/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
@@ -0,0 +1,149 @@
+//! An enum with a primitive repr should have exactly the size of that primitive.
+
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+
+ pub fn is_transmutable<Src, Dst, Context>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ {}
+}
+
+#[repr(C)]
+struct Zst;
+
+#[derive(Clone, Copy)]
+#[repr(i8)] enum V0i8 { V }
+#[repr(u8)] enum V0u8 { V }
+#[repr(i16)] enum V0i16 { V }
+#[repr(u16)] enum V0u16 { V }
+#[repr(i32)] enum V0i32 { V }
+#[repr(u32)] enum V0u32 { V }
+#[repr(i64)] enum V0i64 { V }
+#[repr(u64)] enum V0u64 { V }
+#[repr(isize)] enum V0isize { V }
+#[repr(usize)] enum V0usize { V }
+
+fn n8() {
+ struct Context;
+
+ type Smaller = Zst;
+ type Analog = u8;
+ type Larger = u16;
+
+ fn i_should_have_correct_length() {
+ type Current = V0i8;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn u_should_have_correct_length() {
+ type Current = V0u8;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn n16() {
+ struct Context;
+
+ type Smaller = u8;
+ type Analog = u16;
+ type Larger = u32;
+
+ fn i_should_have_correct_length() {
+ type Current = V0i16;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn u_should_have_correct_length() {
+ type Current = V0u16;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn n32() {
+ struct Context;
+
+ type Smaller = u16;
+ type Analog = u32;
+ type Larger = u64;
+
+ fn i_should_have_correct_length() {
+ type Current = V0i32;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn u_should_have_correct_length() {
+ type Current = V0u32;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn n64() {
+ struct Context;
+
+ type Smaller = u32;
+ type Analog = u64;
+ type Larger = u128;
+
+ fn i_should_have_correct_length() {
+ type Current = V0i64;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn u_should_have_correct_length() {
+ type Current = V0u64;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn nsize() {
+ struct Context;
+
+ type Smaller = u8;
+ type Analog = usize;
+ type Larger = [usize; 2];
+
+ fn i_should_have_correct_length() {
+ type Current = V0isize;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn u_should_have_correct_length() {
+ type Current = V0usize;
+
+ assert::is_transmutable::<Smaller, Current, Context>(); //~ ERROR cannot be safely transmuted
+ assert::is_transmutable::<Current, Analog, Context>();
+ assert::is_transmutable::<Current, Larger, Context>(); //~ ERROR cannot be safely transmuted
+ }
+}