summaryrefslogtreecommitdiffstats
path: root/src/test/ui/transmutability/structs/repr
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/transmutability/structs/repr')
-rw-r--r--src/test/ui/transmutability/structs/repr/should_handle_align.rs36
-rw-r--r--src/test/ui/transmutability/structs/repr/should_handle_packed.rs35
-rw-r--r--src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.rs76
-rw-r--r--src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr195
4 files changed, 342 insertions, 0 deletions
diff --git a/src/test/ui/transmutability/structs/repr/should_handle_align.rs b/src/test/ui/transmutability/structs/repr/should_handle_align.rs
new file mode 100644
index 000000000..71720165a
--- /dev/null
+++ b/src/test/ui/transmutability/structs/repr/should_handle_align.rs
@@ -0,0 +1,36 @@
+// check-pass
+//! The presence of an `align(X)` annotation must be accounted for.
+
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code, incomplete_features, non_camel_case_types)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+ pub struct Context;
+
+ pub fn is_maybe_transmutable<Src, Dst>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ {}
+}
+
+fn should_pad_explicitly_aligned_field() {
+ #[derive(Clone, Copy)] #[repr(u8)] enum V0u8 { V = 0 }
+
+ #[repr(C)]
+ pub union Uninit {
+ a: (),
+ b: V0u8,
+ }
+
+ #[repr(C, align(2))] struct align_2(V0u8);
+
+ #[repr(C)] struct ImplicitlyPadded(align_2, V0u8);
+ #[repr(C)] struct ExplicitlyPadded(V0u8, Uninit, V0u8);
+
+ // An implementation that (incorrectly) does not place a padding byte after
+ // `align_2` will, incorrectly, reject the following transmutations.
+ assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
+ assert::is_maybe_transmutable::<ExplicitlyPadded, ImplicitlyPadded>();
+}
diff --git a/src/test/ui/transmutability/structs/repr/should_handle_packed.rs b/src/test/ui/transmutability/structs/repr/should_handle_packed.rs
new file mode 100644
index 000000000..ae8acf504
--- /dev/null
+++ b/src/test/ui/transmutability/structs/repr/should_handle_packed.rs
@@ -0,0 +1,35 @@
+// check-pass
+//! The presence of an `align(X)` annotation must be accounted for.
+
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code, incomplete_features, non_camel_case_types)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+ pub struct Context;
+
+ pub fn is_maybe_transmutable<Src, Dst>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ {}
+}
+
+fn should_pad_explicitly_packed_field() {
+ #[derive(Clone, Copy)] #[repr(u8)] enum V0u8 { V = 0 }
+ #[derive(Clone, Copy)] #[repr(u32)] enum V0u32 { V = 0 }
+
+ #[repr(C)]
+ pub union Uninit {
+ a: (),
+ b: V0u8,
+ }
+
+ #[repr(C, packed(2))] struct ImplicitlyPadded(V0u8, V0u32);
+ #[repr(C)] struct ExplicitlyPadded(V0u8, Uninit, V0u8, V0u8, V0u8, V0u8);
+
+ // An implementation that (incorrectly) does not place a padding byte after
+ // `align_2` will, incorrectly, reject the following transmutations.
+ assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
+ assert::is_maybe_transmutable::<ExplicitlyPadded, ImplicitlyPadded>();
+}
diff --git a/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.rs b/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.rs
new file mode 100644
index 000000000..556be989d
--- /dev/null
+++ b/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.rs
@@ -0,0 +1,76 @@
+//! A struct must have a well-defined layout to participate in a transmutation.
+
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code, incomplete_features, non_camel_case_types)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+ pub struct Context;
+
+ pub fn is_maybe_transmutable<Src, Dst>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ {}
+}
+
+fn should_reject_repr_rust()
+{
+ fn unit() {
+ struct 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 tuple() {
+ struct 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 braces() {
+ struct 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 aligned() {
+ #[repr(align(1))] struct 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 packed() {
+ #[repr(packed)] struct 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 nested() {
+ struct repr_rust;
+ #[repr(C)] struct repr_c(repr_rust);
+ assert::is_maybe_transmutable::<repr_c, ()>(); //~ ERROR cannot be safely transmuted
+ assert::is_maybe_transmutable::<u128, repr_c>(); //~ ERROR cannot be safely transmuted
+ }
+}
+
+fn should_accept_repr_C()
+{
+ fn unit() {
+ #[repr(C)] struct repr_c;
+ assert::is_maybe_transmutable::<repr_c, ()>();
+ assert::is_maybe_transmutable::<i128, repr_c>();
+ }
+
+ fn tuple() {
+ #[repr(C)] struct repr_c();
+ assert::is_maybe_transmutable::<repr_c, ()>();
+ assert::is_maybe_transmutable::<i128, repr_c>();
+ }
+
+ fn braces() {
+ #[repr(C)] struct repr_c{}
+ assert::is_maybe_transmutable::<repr_c, ()>();
+ assert::is_maybe_transmutable::<i128, repr_c>();
+ }
+}
diff --git a/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr b/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr
new file mode 100644
index 000000000..07355f7c2
--- /dev/null
+++ b/src/test/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr
@@ -0,0 +1,195 @@
+error[E0277]: `should_reject_repr_rust::unit::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:21:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `should_reject_repr_rust::unit::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<should_reject_repr_rust::unit::repr_rust, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust::unit::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:22:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `should_reject_repr_rust::unit::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `should_reject_repr_rust::unit::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `should_reject_repr_rust::tuple::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:27:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `should_reject_repr_rust::tuple::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<should_reject_repr_rust::tuple::repr_rust, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust::tuple::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:28:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `should_reject_repr_rust::tuple::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `should_reject_repr_rust::tuple::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `should_reject_repr_rust::braces::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:33:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `should_reject_repr_rust::braces::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<should_reject_repr_rust::braces::repr_rust, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust::braces::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:34:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `should_reject_repr_rust::braces::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `should_reject_repr_rust::braces::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `aligned::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:39:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `aligned::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<aligned::repr_rust, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `aligned::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:40:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `aligned::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `aligned::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `packed::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:45:52
+ |
+LL | assert::is_maybe_transmutable::<repr_rust, ()>();
+ | ^^ `packed::repr_rust` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<packed::repr_rust, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `packed::repr_rust` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:46:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_rust>();
+ | ^^^^^^^^^ `u128` cannot be safely transmuted into `packed::repr_rust` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `packed::repr_rust`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `nested::repr_c` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:52:49
+ |
+LL | assert::is_maybe_transmutable::<repr_c, ()>();
+ | ^^ `nested::repr_c` cannot be safely transmuted into `()` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<nested::repr_c, assert::Context, true, true, true, true>` is not implemented for `()`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error[E0277]: `u128` cannot be safely transmuted into `nested::repr_c` in the defining scope of `assert::Context`.
+ --> $DIR/should_require_well_defined_layout.rs:53:47
+ |
+LL | assert::is_maybe_transmutable::<u128, repr_c>();
+ | ^^^^^^ `u128` cannot be safely transmuted into `nested::repr_c` in the defining scope of `assert::Context`.
+ |
+ = help: the trait `BikeshedIntrinsicFrom<u128, assert::Context, true, true, true, true>` is not implemented for `nested::repr_c`
+note: required by a bound in `is_maybe_transmutable`
+ --> $DIR/should_require_well_defined_layout.rs:13:14
+ |
+LL | pub fn is_maybe_transmutable<Src, Dst>()
+ | --------------------- required by a bound in this
+LL | where
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_maybe_transmutable`
+
+error: aborting due to 12 previous errors
+
+For more information about this error, try `rustc --explain E0277`.