Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ jobs:
if: ${{ contains(matrix.target, 'i686') }}

- name: Run tests
run: cargo +${{ env.ZC_TOOLCHAIN }} test --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose
# We skip `ui` tests unless the `byteorder` feature is enabled (currently,
# all feature sets besides `--no-default-features`). The reason is that,
# when a trait impl is missing, rustc emits different suggestions for
# types that implement the trait when the `byteorder` feature is enabled
# than when it's disabled. Thus, any given compiler output will be
# incorrect either when run with `byteorder` or without it, but no output
# can be correct in both circumstances.
run: cargo +${{ env.ZC_TOOLCHAIN }} test --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose -- ${{ matrix.features == '--no-default-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.
#
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ static_assertions = "1.1"
# and the version used in CI are guaranteed to be the same. Future versions
# sometimes change the output format slightly, so a version mismatch can cause
# CI test failures.
trybuild = "=1.0.80"
trybuild = { version = "=1.0.80", features = ["diff"] }
1 change: 1 addition & 0 deletions tests/ui-msrv/transmute-bound-dst-not-frombytes.rs
22 changes: 22 additions & 0 deletions tests/ui-msrv/transmute-bound-dst-not-frombytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: FromBytes` is not satisfied
--> tests/ui-msrv/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy<AU16>`
|
= help: the following other types implement trait `FromBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `DST_NOT_FROM_BYTES::transmute`
--> tests/ui-msrv/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `DST_NOT_FROM_BYTES::transmute`
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 1 addition & 0 deletions tests/ui-msrv/transmute-bound-src-not-asbytes.rs
25 changes: 25 additions & 0 deletions tests/ui-msrv/transmute-bound-src-not-asbytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
--> tests/ui-msrv/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
| required by a bound introduced by this call
|
= help: the following other types implement trait `AsBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `SRC_NOT_AS_BYTES::transmute`
--> tests/ui-msrv/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SRC_NOT_AS_BYTES::transmute`
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 0 additions & 1 deletion tests/ui-msrv/transmute-illegal.rs

This file was deleted.

25 changes: 0 additions & 25 deletions tests/ui-msrv/transmute-illegal.stderr

This file was deleted.

1 change: 1 addition & 0 deletions tests/ui-msrv/transmute-pointer.rs
25 changes: 25 additions & 0 deletions tests/ui-msrv/transmute-pointer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
--> tests/ui-msrv/transmute-pointer.rs:7:30
|
7 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait `AsBytes` is not implemented for `*const usize`
| required by a bound introduced by this call
|
= help: the following other types implement trait `AsBytes`:
f32
f64
i128
i16
i32
i64
i8
isize
and $N others
note: required by a bound in `POINTER_VALUE::transmute`
--> tests/ui-msrv/transmute-pointer.rs:7:30
|
7 | 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)
1 change: 1 addition & 0 deletions tests/ui-msrv/transmute-size-decrease.rs
9 changes: 9 additions & 0 deletions tests/ui-msrv/transmute-size-decrease.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-size-decrease.rs:7:32
|
7 | const SIZE_DECREASE: [u8; 1] = zerocopy::transmute!([0u8; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[u8; 2]` (16 bits)
= note: target type: `[u8; 1]` (8 bits)
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 1 addition & 0 deletions tests/ui-msrv/transmute-size-increase.rs
9 changes: 9 additions & 0 deletions tests/ui-msrv/transmute-size-increase.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-size-increase.rs:7:32
|
7 | const SIZE_INCREASE: [u8; 2] = zerocopy::transmute!([0u8; 1]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[u8; 1]` (8 bits)
= note: target type: `[u8; 2]` (16 bits)
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
13 changes: 13 additions & 0 deletions tests/ui-nightly/transmute-bound-dst-not-frombytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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;

include!("../../zerocopy-derive/tests/util.rs");

// The source type must be `FromBytes`.
const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));

fn main() {
_ = DST_NOT_FROM_BYTES;
}
22 changes: 22 additions & 0 deletions tests/ui-nightly/transmute-bound-dst-not-frombytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: FromBytes` is not satisfied
--> tests/ui-nightly/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy<AU16>`
|
= help: the following other types implement trait `FromBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `DST_NOT_FROM_BYTES::transmute`
--> tests/ui-nightly/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
13 changes: 13 additions & 0 deletions tests/ui-nightly/transmute-bound-src-not-asbytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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;

include!("../../zerocopy-derive/tests/util.rs");

// The source type must be `AsBytes`.
const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));

fn main() {
_ = SRC_NOT_AS_BYTES;
}
25 changes: 25 additions & 0 deletions tests/ui-nightly/transmute-bound-src-not-asbytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
--> tests/ui-nightly/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
| required by a bound introduced by this call
|
= help: the following other types implement trait `AsBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `SRC_NOT_AS_BYTES::transmute`
--> tests/ui-nightly/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 changes: 0 additions & 16 deletions tests/ui-nightly/transmute-illegal.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 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);

fn main() {
_ = POINTER_VALUE;
}
16 changes: 16 additions & 0 deletions tests/ui-nightly/transmute-pointer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied
--> tests/ui-nightly/transmute-pointer.rs:7:30
|
7 | const POINTER_VALUE: usize = zerocopy::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-pointer.rs:7:30
|
7 | 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)
11 changes: 11 additions & 0 deletions tests/ui-nightly/transmute-size-decrease.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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;

// It is unsupported to decrease the size of a transmuted value.
const SIZE_DECREASE: [u8; 1] = zerocopy::transmute!([0u8; 2]);

fn main() {
_ = SIZE_DECREASE;
}
9 changes: 9 additions & 0 deletions tests/ui-nightly/transmute-size-decrease.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-nightly/transmute-size-decrease.rs:7:32
|
7 | const SIZE_DECREASE: [u8; 1] = zerocopy::transmute!([0u8; 2]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[u8; 2]` (16 bits)
= note: target type: `[u8; 1]` (8 bits)
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
11 changes: 11 additions & 0 deletions tests/ui-nightly/transmute-size-increase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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;

// It is usually unsound to increase the size of a transmuted value.
const SIZE_INCREASE: [u8; 2] = zerocopy::transmute!([0u8; 1]);

fn main() {
_ = SIZE_INCREASE;
}
9 changes: 9 additions & 0 deletions tests/ui-nightly/transmute-size-increase.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-nightly/transmute-size-increase.rs:7:32
|
7 | const SIZE_INCREASE: [u8; 2] = zerocopy::transmute!([0u8; 1]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[u8; 1]` (8 bits)
= note: target type: `[u8; 2]` (16 bits)
= note: this error originates in the macro `zerocopy::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 1 addition & 0 deletions tests/ui-stable/transmute-bound-dst-not-frombytes.rs
22 changes: 22 additions & 0 deletions tests/ui-stable/transmute-bound-dst-not-frombytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: FromBytes` is not satisfied
--> tests/ui-stable/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy<AU16>`
|
= help: the following other types implement trait `FromBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `DST_NOT_FROM_BYTES::transmute`
--> tests/ui-stable/transmute-bound-dst-not-frombytes.rs:9:47
|
9 | const DST_NOT_FROM_BYTES: NotZerocopy<AU16> = zerocopy::transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
1 change: 1 addition & 0 deletions tests/ui-stable/transmute-bound-src-not-asbytes.rs
25 changes: 25 additions & 0 deletions tests/ui-stable/transmute-bound-src-not-asbytes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0277]: the trait bound `NotZerocopy<AU16>: AsBytes` is not satisfied
--> tests/ui-stable/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait `AsBytes` is not implemented for `NotZerocopy<AU16>`
| required by a bound introduced by this call
|
= help: the following other types implement trait `AsBytes`:
()
AU16
F32<O>
F64<O>
I128<O>
I16<O>
I32<O>
I64<O>
and $N others
note: required by a bound in `SRC_NOT_AS_BYTES::transmute`
--> tests/ui-stable/transmute-bound-src-not-asbytes.rs:9:32
|
9 | const SRC_NOT_AS_BYTES: AU16 = zerocopy::transmute!(NotZerocopy(AU16(0)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
1 change: 0 additions & 1 deletion tests/ui-stable/transmute-illegal.rs

This file was deleted.

Loading