diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca8845471b..ff54817986 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,7 +162,10 @@ jobs: --package ${{ matrix.crate }} \ --target ${{ matrix.target }} \ ${{ matrix.features }} \ - --verbose + --verbose \ + -- \ + ${{ (matrix.features == '--no-default-features' || matrix.features == '') && '--skip ui' || '' }} \ + # Only run tests when targetting x86 (32- or 64-bit) - we're executing on # x86_64, so we can't run tests for any non-x86 target. # diff --git a/tests/ui-msrv/transmute-dst-not-frombytes.rs b/tests/ui-msrv/transmute-dst-not-frombytes.rs new file mode 120000 index 0000000000..0906ff449a --- /dev/null +++ b/tests/ui-msrv/transmute-dst-not-frombytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-dst-not-frombytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-dst-not-frombytes.stderr b/tests/ui-msrv/transmute-dst-not-frombytes.stderr new file mode 100644 index 0000000000..c631b23814 --- /dev/null +++ b/tests/ui-msrv/transmute-dst-not-frombytes.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-msrv/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `DST_NOT_FROM_BYTES::transmute` + --> tests/ui-msrv/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ required by this bound in `DST_NOT_FROM_BYTES::transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-illegal.rs b/tests/ui-msrv/transmute-illegal.rs deleted file mode 120000 index 81733075e2..0000000000 --- a/tests/ui-msrv/transmute-illegal.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-illegal.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-illegal.stderr b/tests/ui-msrv/transmute-illegal.stderr deleted file mode 100644 index 37c124ad95..0000000000 --- a/tests/ui-msrv/transmute-illegal.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied - --> tests/ui-msrv/transmute-illegal.rs:10:30 - | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` - | - = help: the following implementations were found: - - - - - and $N others -note: required by a bound in `POINTER_VALUE::transmute` - --> tests/ui-msrv/transmute-illegal.rs:10:30 - | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute` - = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-ptr-to-usize.rs b/tests/ui-msrv/transmute-ptr-to-usize.rs new file mode 120000 index 0000000000..f808a758f8 --- /dev/null +++ b/tests/ui-msrv/transmute-ptr-to-usize.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ptr-to-usize.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-ptr-to-usize.stderr b/tests/ui-msrv/transmute-ptr-to-usize.stderr new file mode 100644 index 0000000000..95b072bb72 --- /dev/null +++ b/tests/ui-msrv/transmute-ptr-to-usize.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied + --> tests/ui-msrv/transmute-ptr-to-usize.rs:16:30 + | +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` + | + = help: the following implementations were found: + + + + + and $N others +note: required by a bound in `POINTER_VALUE::transmute` + --> tests/ui-msrv/transmute-ptr-to-usize.rs:16:30 + | +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-size-decrease.rs b/tests/ui-msrv/transmute-size-decrease.rs new file mode 120000 index 0000000000..899c240c19 --- /dev/null +++ b/tests/ui-msrv/transmute-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-size-decrease.stderr b/tests/ui-msrv/transmute-size-decrease.stderr new file mode 100644 index 0000000000..b2babb6bea --- /dev/null +++ b/tests/ui-msrv/transmute-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/transmute-size-decrease.rs:15:27 + | +15 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-size-increase.rs b/tests/ui-msrv/transmute-size-increase.rs new file mode 120000 index 0000000000..312da091a1 --- /dev/null +++ b/tests/ui-msrv/transmute-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-size-increase.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-size-increase.stderr b/tests/ui-msrv/transmute-size-increase.stderr new file mode 100644 index 0000000000..2e0620b410 --- /dev/null +++ b/tests/ui-msrv/transmute-size-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-msrv/transmute-size-increase.rs:15:29 + | +15 | const INCREASE_SIZE: AU16 = transmute!(0u8); + | ^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `AU16` (16 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-msrv/transmute-src-not-asbytes.rs b/tests/ui-msrv/transmute-src-not-asbytes.rs new file mode 120000 index 0000000000..999d9cea6a --- /dev/null +++ b/tests/ui-msrv/transmute-src-not-asbytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-msrv/transmute-src-not-asbytes.stderr b/tests/ui-msrv/transmute-src-not-asbytes.stderr new file mode 100644 index 0000000000..09ec1cc1b0 --- /dev/null +++ b/tests/ui-msrv/transmute-src-not-asbytes.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied + --> tests/ui-msrv/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy` + | +note: required by a bound in `SRC_NOT_AS_BYTES::transmute` + --> tests/ui-msrv/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SRC_NOT_AS_BYTES::transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-dst-not-frombytes.rs b/tests/ui-nightly/transmute-dst-not-frombytes.rs new file mode 100644 index 0000000000..5e56744b37 --- /dev/null +++ b/tests/ui-nightly/transmute-dst-not-frombytes.rs @@ -0,0 +1,14 @@ +// Copyright 2022 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +include!("../../zerocopy-derive/tests/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute; + +fn main() {} + +// `transmute` requires that the destination type implements `FromBytes` +const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); diff --git a/tests/ui-nightly/transmute-dst-not-frombytes.stderr b/tests/ui-nightly/transmute-dst-not-frombytes.stderr new file mode 100644 index 0000000000..c91ac448f7 --- /dev/null +++ b/tests/ui-nightly/transmute-dst-not-frombytes.stderr @@ -0,0 +1,22 @@ +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-nightly/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `FromBytes`: + () + AU16 + F32 + F64 + I128 + I16 + I32 + I64 + and $N others +note: required by a bound in `DST_NOT_FROM_BYTES::transmute` + --> tests/ui-nightly/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-illegal.rs b/tests/ui-nightly/transmute-illegal.rs deleted file mode 100644 index 74b84391cd..0000000000 --- a/tests/ui-nightly/transmute-illegal.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2022 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -extern crate zerocopy; - -fn main() {} - -// It is unsound to inspect the usize value of a pointer during const eval. -const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); diff --git a/tests/ui-nightly/transmute-ptr-to-usize.rs b/tests/ui-nightly/transmute-ptr-to-usize.rs new file mode 100644 index 0000000000..ec88cb09e1 --- /dev/null +++ b/tests/ui-nightly/transmute-ptr-to-usize.rs @@ -0,0 +1,16 @@ +// Copyright 2022 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +extern crate zerocopy; + +use zerocopy::transmute; + +fn main() {} + +// It is unclear whether we can or should support this transmutation, especially +// in a const context. This test ensures that even if such a transmutation +// becomes valid due to the requisite implementations of `FromBytes` being +// added, that we re-examine whether it should specifically be valid in a const +// context. +const POINTER_VALUE: usize = transmute!(&0usize as *const usize); diff --git a/tests/ui-stable/transmute-illegal.stderr b/tests/ui-nightly/transmute-ptr-to-usize.stderr similarity index 53% rename from tests/ui-stable/transmute-illegal.stderr rename to tests/ui-nightly/transmute-ptr-to-usize.stderr index e9ac2402da..59bf6edf52 100644 --- a/tests/ui-stable/transmute-illegal.stderr +++ b/tests/ui-nightly/transmute-ptr-to-usize.stderr @@ -1,16 +1,16 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied - --> tests/ui-stable/transmute-illegal.rs:10:30 + --> tests/ui-nightly/transmute-ptr-to-usize.rs:16:30 | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the trait `AsBytes` is not implemented for `*const usize` | required by a bound introduced by this call | = help: the trait `AsBytes` is implemented for `usize` note: required by a bound in `POINTER_VALUE::transmute` - --> tests/ui-stable/transmute-illegal.rs:10:30 + --> tests/ui-nightly/transmute-ptr-to-usize.rs:16:30 | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` - = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info) +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-size-decrease.rs b/tests/ui-nightly/transmute-size-decrease.rs new file mode 100644 index 0000000000..51ddb8a121 --- /dev/null +++ b/tests/ui-nightly/transmute-size-decrease.rs @@ -0,0 +1,15 @@ +// Copyright 2022 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +include!("../../zerocopy-derive/tests/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute; + +fn main() {} + +// Although this is not a soundness requirement, we currently require that the +// size of the destination type is not smaller than the size of the source type. +const DECREASE_SIZE: u8 = transmute!(AU16(0)); diff --git a/tests/ui-nightly/transmute-size-decrease.stderr b/tests/ui-nightly/transmute-size-decrease.stderr new file mode 100644 index 0000000000..3cd2cecf98 --- /dev/null +++ b/tests/ui-nightly/transmute-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/transmute-size-decrease.rs:15:27 + | +15 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-size-increase.rs b/tests/ui-nightly/transmute-size-increase.rs new file mode 100644 index 0000000000..9774d02017 --- /dev/null +++ b/tests/ui-nightly/transmute-size-increase.rs @@ -0,0 +1,15 @@ +// Copyright 2022 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +include!("../../zerocopy-derive/tests/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute; + +fn main() {} + +// Although this is not a soundness requirement, we currently require that the +// size of the destination type is not larger than the size of the source type. +const INCREASE_SIZE: AU16 = transmute!(0u8); diff --git a/tests/ui-nightly/transmute-size-increase.stderr b/tests/ui-nightly/transmute-size-increase.stderr new file mode 100644 index 0000000000..08d6f498fe --- /dev/null +++ b/tests/ui-nightly/transmute-size-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-nightly/transmute-size-increase.rs:15:29 + | +15 | const INCREASE_SIZE: AU16 = transmute!(0u8); + | ^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `AU16` (16 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-nightly/transmute-src-not-asbytes.rs b/tests/ui-nightly/transmute-src-not-asbytes.rs new file mode 100644 index 0000000000..4eac86347f --- /dev/null +++ b/tests/ui-nightly/transmute-src-not-asbytes.rs @@ -0,0 +1,14 @@ +// Copyright 2022 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +include!("../../zerocopy-derive/tests/util.rs"); + +extern crate zerocopy; + +use zerocopy::transmute; + +fn main() {} + +// `transmute` requires that the source type implements `AsBytes` +const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); diff --git a/tests/ui-nightly/transmute-src-not-asbytes.stderr b/tests/ui-nightly/transmute-src-not-asbytes.stderr new file mode 100644 index 0000000000..461ec9b9a0 --- /dev/null +++ b/tests/ui-nightly/transmute-src-not-asbytes.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied + --> tests/ui-nightly/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `AsBytes` is not implemented for `NotZerocopy` + | required by a bound introduced by this call + | + = help: the following other types implement trait `AsBytes`: + () + AU16 + F32 + F64 + I128 + I16 + I32 + I64 + and $N others +note: required by a bound in `SRC_NOT_AS_BYTES::transmute` + --> tests/ui-nightly/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-dst-not-frombytes.rs b/tests/ui-stable/transmute-dst-not-frombytes.rs new file mode 120000 index 0000000000..0906ff449a --- /dev/null +++ b/tests/ui-stable/transmute-dst-not-frombytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-dst-not-frombytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-dst-not-frombytes.stderr b/tests/ui-stable/transmute-dst-not-frombytes.stderr new file mode 100644 index 0000000000..223fa46d83 --- /dev/null +++ b/tests/ui-stable/transmute-dst-not-frombytes.stderr @@ -0,0 +1,22 @@ +error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied + --> tests/ui-stable/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy` + | + = help: the following other types implement trait `FromBytes`: + () + AU16 + F32 + F64 + I128 + I16 + I32 + I64 + and $N others +note: required by a bound in `DST_NOT_FROM_BYTES::transmute` + --> tests/ui-stable/transmute-dst-not-frombytes.rs:14:41 + | +14 | const DST_NOT_FROM_BYTES: NotZerocopy = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-illegal.rs b/tests/ui-stable/transmute-illegal.rs deleted file mode 120000 index 81733075e2..0000000000 --- a/tests/ui-stable/transmute-illegal.rs +++ /dev/null @@ -1 +0,0 @@ -../ui-nightly/transmute-illegal.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-ptr-to-usize.rs b/tests/ui-stable/transmute-ptr-to-usize.rs new file mode 120000 index 0000000000..f808a758f8 --- /dev/null +++ b/tests/ui-stable/transmute-ptr-to-usize.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-ptr-to-usize.rs \ No newline at end of file diff --git a/tests/ui-nightly/transmute-illegal.stderr b/tests/ui-stable/transmute-ptr-to-usize.stderr similarity index 53% rename from tests/ui-nightly/transmute-illegal.stderr rename to tests/ui-stable/transmute-ptr-to-usize.stderr index a57544b26f..70a9045bbd 100644 --- a/tests/ui-nightly/transmute-illegal.stderr +++ b/tests/ui-stable/transmute-ptr-to-usize.stderr @@ -1,16 +1,16 @@ error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied - --> tests/ui-nightly/transmute-illegal.rs:10:30 + --> tests/ui-stable/transmute-ptr-to-usize.rs:16:30 | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the trait `AsBytes` is not implemented for `*const usize` | required by a bound introduced by this call | = help: the trait `AsBytes` is implemented for `usize` note: required by a bound in `POINTER_VALUE::transmute` - --> tests/ui-nightly/transmute-illegal.rs:10:30 + --> tests/ui-stable/transmute-ptr-to-usize.rs:16:30 | -10 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` - = note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info) +16 | const POINTER_VALUE: usize = transmute!(&0usize as *const usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-size-decrease.rs b/tests/ui-stable/transmute-size-decrease.rs new file mode 120000 index 0000000000..899c240c19 --- /dev/null +++ b/tests/ui-stable/transmute-size-decrease.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-size-decrease.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-size-decrease.stderr b/tests/ui-stable/transmute-size-decrease.stderr new file mode 100644 index 0000000000..d847f49094 --- /dev/null +++ b/tests/ui-stable/transmute-size-decrease.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/transmute-size-decrease.rs:15:27 + | +15 | const DECREASE_SIZE: u8 = transmute!(AU16(0)); + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `AU16` (16 bits) + = note: target type: `u8` (8 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-size-increase.rs b/tests/ui-stable/transmute-size-increase.rs new file mode 120000 index 0000000000..312da091a1 --- /dev/null +++ b/tests/ui-stable/transmute-size-increase.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-size-increase.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-size-increase.stderr b/tests/ui-stable/transmute-size-increase.stderr new file mode 100644 index 0000000000..b230d33c6d --- /dev/null +++ b/tests/ui-stable/transmute-size-increase.stderr @@ -0,0 +1,9 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> tests/ui-stable/transmute-size-increase.rs:15:29 + | +15 | const INCREASE_SIZE: AU16 = transmute!(0u8); + | ^^^^^^^^^^^^^^^ + | + = note: source type: `u8` (8 bits) + = note: target type: `AU16` (16 bits) + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui-stable/transmute-src-not-asbytes.rs b/tests/ui-stable/transmute-src-not-asbytes.rs new file mode 120000 index 0000000000..999d9cea6a --- /dev/null +++ b/tests/ui-stable/transmute-src-not-asbytes.rs @@ -0,0 +1 @@ +../ui-nightly/transmute-src-not-asbytes.rs \ No newline at end of file diff --git a/tests/ui-stable/transmute-src-not-asbytes.stderr b/tests/ui-stable/transmute-src-not-asbytes.stderr new file mode 100644 index 0000000000..654dd03fa0 --- /dev/null +++ b/tests/ui-stable/transmute-src-not-asbytes.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied + --> tests/ui-stable/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `AsBytes` is not implemented for `NotZerocopy` + | required by a bound introduced by this call + | + = help: the following other types implement trait `AsBytes`: + () + AU16 + F32 + F64 + I128 + I16 + I32 + I64 + and $N others +note: required by a bound in `SRC_NOT_AS_BYTES::transmute` + --> tests/ui-stable/transmute-src-not-asbytes.rs:14:32 + | +14 | const SRC_NOT_AS_BYTES: AU16 = transmute!(NotZerocopy(AU16(0))); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `transmute` + = note: this error originates in the macro `transmute` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/util.rs b/zerocopy-derive/tests/util.rs index 7615d84fff..6b7a545942 100644 --- a/zerocopy-derive/tests/util.rs +++ b/zerocopy-derive/tests/util.rs @@ -5,7 +5,7 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes}; /// A type that doesn't implement any zerocopy traits. -pub struct NotZerocopy(()); +pub struct NotZerocopy(T); /// A `u16` with alignment 2. ///