diff options
Diffstat (limited to 'tests/ui/transmutability/references')
12 files changed, 300 insertions, 0 deletions
diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.rs b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.rs new file mode 100644 index 000000000..a6e2889d3 --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.rs @@ -0,0 +1,25 @@ +// check-fail +#![feature(transmutability)] + +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: false, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct A(bool, &'static A); + #[repr(C)] struct B(u8, &'static B); + assert::is_maybe_transmutable::<&'static A, &'static mut B>(); //~ ERROR cannot be safely transmuted +} diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.stderr b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.stderr new file mode 100644 index 000000000..4b4d6ad02 --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible-mut.stderr @@ -0,0 +1,25 @@ +error[E0277]: `&A` cannot be safely transmuted into `&mut B` in the defining scope of `assert::Context` + --> $DIR/recursive-wrapper-types-bit-compatible-mut.rs:24:49 + | +LL | assert::is_maybe_transmutable::<&'static A, &'static mut B>(); + | ^^^^^^^^^^^^^^ `&A` is a shared reference, but `&mut B` is a unique reference + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/recursive-wrapper-types-bit-compatible-mut.rs:10:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context, { + | ______________^ +LL | | Assume { +LL | | alignment: true, +LL | | lifetimes: false, +... | +LL | | } +LL | | }> + | |__________^ required by this bound in `is_maybe_transmutable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs new file mode 100644 index 000000000..3ea80173a --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs @@ -0,0 +1,26 @@ +// check-fail +// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom +#![feature(transmutability)] + +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: false, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct A(bool, &'static A); + #[repr(C)] struct B(u8, &'static B); + assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr new file mode 100644 index 000000000..fae332e6a --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr @@ -0,0 +1,25 @@ +error[E0275]: overflow evaluating the requirement `B: BikeshedIntrinsicFrom<A, assert::Context, Assume { alignment: true, lifetimes: false, safety: true, validity: false }>` + --> $DIR/recursive-wrapper-types-bit-compatible.rs:25:5 + | +LL | assert::is_maybe_transmutable::<&'static A, &'static B>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/recursive-wrapper-types-bit-compatible.rs:11:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context, { + | ______________^ +LL | | Assume { +LL | | alignment: true, +LL | | lifetimes: false, +... | +LL | | } +LL | | }> + | |__________^ required by this bound in `is_maybe_transmutable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.rs b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.rs new file mode 100644 index 000000000..e8582d2fd --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.rs @@ -0,0 +1,25 @@ +// check-fail +#![feature(transmutability)] + +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: false, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct A(bool, &'static A); + #[repr(C)] struct B(u8, &'static B); + assert::is_maybe_transmutable::<&'static B, &'static A>(); //~ ERROR cannot be safely transmuted +} diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr new file mode 100644 index 000000000..ecfe48659 --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr @@ -0,0 +1,25 @@ +error[E0277]: `B` cannot be safely transmuted into `A` in the defining scope of `assert::Context` + --> $DIR/recursive-wrapper-types-bit-incompatible.rs:24:49 + | +LL | assert::is_maybe_transmutable::<&'static B, &'static A>(); + | ^^^^^^^^^^ At least one value of `B` isn't a bit-valid value of `A` + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/recursive-wrapper-types-bit-incompatible.rs:10:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context, { + | ______________^ +LL | | Assume { +LL | | alignment: true, +LL | | lifetimes: false, +... | +LL | | } +LL | | }> + | |__________^ required by this bound in `is_maybe_transmutable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/transmutability/references/recursive-wrapper-types.rs b/tests/ui/transmutability/references/recursive-wrapper-types.rs new file mode 100644 index 000000000..59d1ad84a --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types.rs @@ -0,0 +1,27 @@ +// check-fail +// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom +#![feature(transmutability)] + +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: false, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct A(&'static B); + #[repr(C)] struct B(&'static A); + assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ overflow evaluating the requirement + assert::is_maybe_transmutable::<&'static B, &'static A>(); +} diff --git a/tests/ui/transmutability/references/recursive-wrapper-types.stderr b/tests/ui/transmutability/references/recursive-wrapper-types.stderr new file mode 100644 index 000000000..35a60c226 --- /dev/null +++ b/tests/ui/transmutability/references/recursive-wrapper-types.stderr @@ -0,0 +1,25 @@ +error[E0275]: overflow evaluating the requirement `A: BikeshedIntrinsicFrom<B, assert::Context, Assume { alignment: true, lifetimes: false, safety: true, validity: false }>` + --> $DIR/recursive-wrapper-types.rs:25:5 + | +LL | assert::is_maybe_transmutable::<&'static A, &'static B>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/recursive-wrapper-types.rs:11:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +LL | where +LL | Dst: BikeshedIntrinsicFrom<Src, Context, { + | ______________^ +LL | | Assume { +LL | | alignment: true, +LL | | lifetimes: false, +... | +LL | | } +LL | | }> + | |__________^ required by this bound in `is_maybe_transmutable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/transmutability/references/u8-to-unit.rs b/tests/ui/transmutability/references/u8-to-unit.rs new file mode 100644 index 000000000..8b37492bd --- /dev/null +++ b/tests/ui/transmutability/references/u8-to-unit.rs @@ -0,0 +1,24 @@ +// check-pass +#![feature(transmutability)] + +mod assert { + use std::mem::{Assume, BikeshedIntrinsicFrom}; + pub struct Context; + + pub fn is_maybe_transmutable<Src, Dst>() + where + Dst: BikeshedIntrinsicFrom<Src, Context, { + Assume { + alignment: false, + lifetimes: true, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct Unit; + assert::is_maybe_transmutable::<&'static u8, &'static Unit>(); +} diff --git a/tests/ui/transmutability/references/unit-to-itself.rs b/tests/ui/transmutability/references/unit-to-itself.rs new file mode 100644 index 000000000..04a7e16d7 --- /dev/null +++ b/tests/ui/transmutability/references/unit-to-itself.rs @@ -0,0 +1,24 @@ +// check-pass +#![feature(transmutability)] + +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: false, + safety: true, + validity: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct Unit; + assert::is_maybe_transmutable::<&'static Unit, &'static Unit>(); +} diff --git a/tests/ui/transmutability/references/unit-to-u8.rs b/tests/ui/transmutability/references/unit-to-u8.rs new file mode 100644 index 000000000..eff516e9a --- /dev/null +++ b/tests/ui/transmutability/references/unit-to-u8.rs @@ -0,0 +1,24 @@ +// check-fail +#![feature(transmutability)] + +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: false, + } + }> + {} +} + +fn main() { + #[repr(C)] struct Unit; + assert::is_maybe_transmutable::<&'static Unit, &'static u8>(); //~ ERROR cannot be safely transmuted +} diff --git a/tests/ui/transmutability/references/unit-to-u8.stderr b/tests/ui/transmutability/references/unit-to-u8.stderr new file mode 100644 index 000000000..f2b72357f --- /dev/null +++ b/tests/ui/transmutability/references/unit-to-u8.stderr @@ -0,0 +1,25 @@ +error[E0277]: `Unit` cannot be safely transmuted into `u8` in the defining scope of `assert::Context` + --> $DIR/unit-to-u8.rs:23:52 + | +LL | assert::is_maybe_transmutable::<&'static Unit, &'static u8>(); + | ^^^^^^^^^^^ The size of `Unit` is smaller than the size of `u8` + | +note: required by a bound in `is_maybe_transmutable` + --> $DIR/unit-to-u8.rs:10:14 + | +LL | pub fn is_maybe_transmutable<Src, Dst>() + | --------------------- required by a bound in this function +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 previous error + +For more information about this error, try `rustc --explain E0277`. |