summaryrefslogtreecommitdiffstats
path: root/tests/ui/transmutability/enums/repr
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/transmutability/enums/repr
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/transmutability/enums/repr')
-rw-r--r--tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs156
-rw-r--r--tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr463
-rw-r--r--tests/ui/transmutability/enums/repr/should_require_well_defined_layout.rs124
-rw-r--r--tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr141
4 files changed, 884 insertions, 0 deletions
diff --git a/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
new file mode 100644
index 000000000..940f070e7
--- /dev/null
+++ b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.rs
@@ -0,0 +1,156 @@
+//! 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::{Assume, BikeshedIntrinsicFrom};
+
+ pub fn is_transmutable<Src, Dst, Context>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, {
+ Assume {
+ alignment: true,
+ lifetimes: true,
+ safety: true,
+ validity: 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
+ }
+}
diff --git a/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr
new file mode 100644
index 000000000..4da5fcea3
--- /dev/null
+++ b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr
@@ -0,0 +1,463 @@
+error[E0277]: `Zst` cannot be safely transmuted into `V0i8` in the defining scope of `n8::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:48:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `Zst` cannot be safely transmuted into `V0i8` in the defining scope of `n8::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<Zst, n8::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0i8`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0i8` cannot be safely transmuted into `u16` in the defining scope of `n8::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:50:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0i8` cannot be safely transmuted into `u16` in the defining scope of `n8::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0i8, n8::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u16`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `Zst` cannot be safely transmuted into `V0u8` in the defining scope of `n8::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:56:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `Zst` cannot be safely transmuted into `V0u8` in the defining scope of `n8::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<Zst, n8::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0u8`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0u8` cannot be safely transmuted into `u16` in the defining scope of `n8::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:58:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0u8` cannot be safely transmuted into `u16` in the defining scope of `n8::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0u8, n8::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u16`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u8` cannot be safely transmuted into `V0i16` in the defining scope of `n16::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:72:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u8` cannot be safely transmuted into `V0i16` in the defining scope of `n16::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u8, n16::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0i16`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0i16` cannot be safely transmuted into `u32` in the defining scope of `n16::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:74:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0i16` cannot be safely transmuted into `u32` in the defining scope of `n16::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0i16, n16::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u32`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u8` cannot be safely transmuted into `V0u16` in the defining scope of `n16::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:80:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u8` cannot be safely transmuted into `V0u16` in the defining scope of `n16::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u8, n16::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0u16`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0u16` cannot be safely transmuted into `u32` in the defining scope of `n16::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:82:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0u16` cannot be safely transmuted into `u32` in the defining scope of `n16::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0u16, n16::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u32`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u16` cannot be safely transmuted into `V0i32` in the defining scope of `n32::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:96:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u16` cannot be safely transmuted into `V0i32` in the defining scope of `n32::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u16, n32::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0i32`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0i32` cannot be safely transmuted into `u64` in the defining scope of `n32::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:98:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0i32` cannot be safely transmuted into `u64` in the defining scope of `n32::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0i32, n32::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u64`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u16` cannot be safely transmuted into `V0u32` in the defining scope of `n32::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:104:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u16` cannot be safely transmuted into `V0u32` in the defining scope of `n32::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u16, n32::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0u32`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0u32` cannot be safely transmuted into `u64` in the defining scope of `n32::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:106:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0u32` cannot be safely transmuted into `u64` in the defining scope of `n32::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0u32, n32::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u64`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u32` cannot be safely transmuted into `V0i64` in the defining scope of `n64::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:120:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u32` cannot be safely transmuted into `V0i64` in the defining scope of `n64::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u32, n64::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0i64`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0i64` cannot be safely transmuted into `u128` in the defining scope of `n64::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:122:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0i64` cannot be safely transmuted into `u128` in the defining scope of `n64::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0i64, n64::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u128`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u32` cannot be safely transmuted into `V0u64` in the defining scope of `n64::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:128:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u32` cannot be safely transmuted into `V0u64` in the defining scope of `n64::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u32, n64::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0u64`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0u64` cannot be safely transmuted into `u128` in the defining scope of `n64::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:130:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0u64` cannot be safely transmuted into `u128` in the defining scope of `n64::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0u64, n64::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `u128`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u8` cannot be safely transmuted into `V0isize` in the defining scope of `nsize::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:144:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u8` cannot be safely transmuted into `V0isize` in the defining scope of `nsize::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u8, nsize::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0isize`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0isize` cannot be safely transmuted into `[usize; 2]` in the defining scope of `nsize::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:146:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0isize` cannot be safely transmuted into `[usize; 2]` in the defining scope of `nsize::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0isize, nsize::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `[usize; 2]`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `u8` cannot be safely transmuted into `V0usize` in the defining scope of `nsize::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:152:44
+ |
+LL | assert::is_transmutable::<Smaller, Current, Context>();
+ | ^^^^^^^ `u8` cannot be safely transmuted into `V0usize` in the defining scope of `nsize::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u8, nsize::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `V0usize`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error[E0277]: `V0usize` cannot be safely transmuted into `[usize; 2]` in the defining scope of `nsize::Context`.
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:154:44
+ |
+LL | assert::is_transmutable::<Current, Larger, Context>();
+ | ^^^^^^ `V0usize` cannot be safely transmuted into `[usize; 2]` in the defining scope of `nsize::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<V0usize, nsize::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `[usize; 2]`
+note: required by a bound in `is_transmutable`
+ --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14
+ |
+LL | pub fn is_transmutable<Src, Dst, Context>()
+ | --------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_transmutable`
+
+error: aborting due to 20 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.rs b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.rs
new file mode 100644
index 000000000..102111ae2
--- /dev/null
+++ b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.rs
@@ -0,0 +1,124 @@
+//! An enum must have a well-defined layout to participate in a transmutation.
+
+#![crate_type = "lib"]
+#![feature(repr128)]
+#![feature(transmutability)]
+#![allow(dead_code, incomplete_features, non_camel_case_types)]
+
+mod assert {
+ use std::mem::{Assume, BikeshedIntrinsicFrom};
+ pub struct Context;
+
+ pub fn is_maybe_transmutable<Src, Dst>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, {
+ Assume {
+ alignment: true,
+ lifetimes: true,
+ safety: true,
+ validity: true,
+ }
+ }>
+ {}
+}
+
+fn should_reject_repr_rust() {
+ fn void() {
+ enum repr_rust {}
+ assert::is_maybe_transmutable::<repr_rust, ()>(); //~ ERROR cannot be safely transmuted
+ assert::is_maybe_transmutable::<u128, repr_rust>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn singleton() {
+ enum repr_rust { V }
+ assert::is_maybe_transmutable::<repr_rust, ()>(); //~ ERROR cannot be safely transmuted
+ assert::is_maybe_transmutable::<u128, repr_rust>(); //~ ERROR cannot be safely transmuted
+ }
+
+ fn duplex() {
+ enum repr_rust { A, B }
+ assert::is_maybe_transmutable::<repr_rust, ()>(); //~ ERROR cannot be safely transmuted
+ assert::is_maybe_transmutable::<u128, repr_rust>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn should_accept_primitive_reprs()
+{
+ fn should_accept_repr_i8() {
+ #[repr(i8)] enum repr_i8 { V }
+ assert::is_maybe_transmutable::<repr_i8, ()>();
+ assert::is_maybe_transmutable::<i8, repr_i8>();
+ }
+
+ fn should_accept_repr_u8() {
+ #[repr(u8)] enum repr_u8 { V }
+ assert::is_maybe_transmutable::<repr_u8, ()>();
+ assert::is_maybe_transmutable::<u8, repr_u8>();
+ }
+
+ fn should_accept_repr_i16() {
+ #[repr(i16)] enum repr_i16 { V }
+ assert::is_maybe_transmutable::<repr_i16, ()>();
+ assert::is_maybe_transmutable::<i16, repr_i16>();
+ }
+
+ fn should_accept_repr_u16() {
+ #[repr(u16)] enum repr_u16 { V }
+ assert::is_maybe_transmutable::<repr_u16, ()>();
+ assert::is_maybe_transmutable::<u16, repr_u16>();
+ }
+
+ fn should_accept_repr_i32() {
+ #[repr(i32)] enum repr_i32 { V }
+ assert::is_maybe_transmutable::<repr_i32, ()>();
+ assert::is_maybe_transmutable::<i32, repr_i32>();
+ }
+
+ fn should_accept_repr_u32() {
+ #[repr(u32)] enum repr_u32 { V }
+ assert::is_maybe_transmutable::<repr_u32, ()>();
+ assert::is_maybe_transmutable::<u32, repr_u32>();
+ }
+
+ fn should_accept_repr_i64() {
+ #[repr(i64)] enum repr_i64 { V }
+ assert::is_maybe_transmutable::<repr_i64, ()>();
+ assert::is_maybe_transmutable::<i64, repr_i64>();
+ }
+
+ fn should_accept_repr_u64() {
+ #[repr(u64)] enum repr_u64 { V }
+ assert::is_maybe_transmutable::<repr_u64, ()>();
+ assert::is_maybe_transmutable::<u64, repr_u64>();
+ }
+
+ fn should_accept_repr_i128() {
+ #[repr(i128)] enum repr_i128 { V }
+ assert::is_maybe_transmutable::<repr_i128, ()>();
+ assert::is_maybe_transmutable::<i128, repr_i128>();
+ }
+
+ fn should_accept_repr_u128() {
+ #[repr(u128)] enum repr_u128 { V }
+ assert::is_maybe_transmutable::<repr_u128, ()>();
+ assert::is_maybe_transmutable::<u128, repr_u128>();
+ }
+
+ fn should_accept_repr_isize() {
+ #[repr(isize)] enum repr_isize { V }
+ assert::is_maybe_transmutable::<repr_isize, ()>();
+ assert::is_maybe_transmutable::<isize, repr_isize>();
+ }
+
+ fn should_accept_repr_usize() {
+ #[repr(usize)] enum repr_usize { V }
+ assert::is_maybe_transmutable::<repr_usize, ()>();
+ assert::is_maybe_transmutable::<usize, repr_usize>();
+ }
+}
+
+fn should_accept_repr_C() {
+ #[repr(C)] enum repr_c { V }
+ assert::is_maybe_transmutable::<repr_c, ()>();
+ assert::is_maybe_transmutable::<i128, repr_c>();
+}
diff --git a/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr
new file mode 100644
index 000000000..510b8c56e
--- /dev/null
+++ b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr
@@ -0,0 +1,141 @@
+error[E0277]: `void::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:28:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `void::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<void::repr_rust, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `void::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:29:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `void::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `void::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `singleton::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:34:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `singleton::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<singleton::repr_rust, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `singleton::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:35:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `singleton::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `singleton::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `duplex::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:40:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `duplex::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<duplex::repr_rust, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `duplex::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:41:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `duplex::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `duplex::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:14:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, {
+ | ______________^
+LL | | Assume {
+LL | | alignment: true,
+LL | | lifetimes: true,
+... |
+LL | | }
+LL | | }>
+ | |__________^ required by this bound in `is_maybe_transmutable`
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0277`.