Skip to content
Merged
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
67 changes: 67 additions & 0 deletions tests/include.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

extern crate zerocopy;

#[allow(unused)]
#[cfg(feature = "derive")]
mod util {
/// A type that doesn't implement any zerocopy traits.
pub struct NotZerocopy<T = ()>(pub T);

/// A `u16` with alignment 2.
///
/// Though `u16` has alignment 2 on some platforms, it's not guaranteed. By
/// contrast, `util::AU16` is guaranteed to have alignment 2.
#[derive(
zerocopy::KnownLayout,
zerocopy::Immutable,
zerocopy::FromBytes,
zerocopy::IntoBytes,
Copy,
Clone,
)]
#[repr(C, align(2))]
pub struct AU16(pub u16);

// Since we can't import these by path (ie, `util::assert_impl_all!`), use a
// name prefix to ensure our derive-emitted code isn't accidentally relying
// on `assert_impl_all!` being in scope.
#[macro_export]
macro_rules! util_assert_impl_all {
($type:ty: $($trait:path),+ $(,)?) => {
const _: fn() = || {
use ::core::prelude::v1::*;
::static_assertions::assert_impl_all!($type: $($trait),+);
};
};
}

// Since we can't import these by path (ie, `util::assert_not_impl_any!`),
// use a name prefix to ensure our derive-emitted code isn't accidentally
// relying on `assert_not_impl_any!` being in scope.
#[macro_export]
macro_rules! util_assert_not_impl_any {
($x:ty: $($t:path),+ $(,)?) => {
const _: fn() = || {
use ::core::prelude::v1::*;
::static_assertions::assert_not_impl_any!($x: $($t),+);
};
};
}

#[macro_export]
macro_rules! test_trivial_is_bit_valid {
($x:ty => $name:ident) => {
#[test]
fn $name() {
util::test_trivial_is_bit_valid::<$x>();
}
};
}
}
12 changes: 6 additions & 6 deletions tests/ui-msrv/diagnostic-not-implemented-from-bytes.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:18:24
error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:16:24
|
18 | takes_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy`
16 | takes_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_from_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:21:24
--> tests/ui-msrv/diagnostic-not-implemented-from-bytes.rs:19:24
|
21 | fn takes_from_bytes<T: FromBytes>() {}
19 | fn takes_from_bytes<T: FromBytes>() {}
| ^^^^^^^^^ required by this bound in `takes_from_bytes`
8 changes: 4 additions & 4 deletions tests/ui-msrv/diagnostic-not-implemented-from-zeros.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:18:24
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:16:24
|
18 | takes_from_zeros::<NotZerocopy>();
16 | takes_from_zeros::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_from_zeros`
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:21:24
--> tests/ui-msrv/diagnostic-not-implemented-from-zeros.rs:19:24
|
21 | fn takes_from_zeros<T: FromZeros>() {}
19 | fn takes_from_zeros<T: FromZeros>() {}
| ^^^^^^^^^ required by this bound in `takes_from_zeros`
12 changes: 6 additions & 6 deletions tests/ui-msrv/diagnostic-not-implemented-immutable.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:18:23
error[E0277]: the trait bound `NotZerocopy: Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:16:23
|
18 | takes_immutable::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
16 | takes_immutable::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `Immutable` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_immutable`
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:21:23
--> tests/ui-msrv/diagnostic-not-implemented-immutable.rs:19:23
|
21 | fn takes_immutable<T: Immutable>() {}
19 | fn takes_immutable<T: Immutable>() {}
| ^^^^^^^^^ required by this bound in `takes_immutable`
12 changes: 6 additions & 6 deletions tests/ui-msrv/diagnostic-not-implemented-into-bytes.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:18:24
error[E0277]: the trait bound `NotZerocopy: IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:16:24
|
18 | takes_into_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy`
16 | takes_into_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_into_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:21:24
--> tests/ui-msrv/diagnostic-not-implemented-into-bytes.rs:19:24
|
21 | fn takes_into_bytes<T: IntoBytes>() {}
19 | fn takes_into_bytes<T: IntoBytes>() {}
| ^^^^^^^^^ required by this bound in `takes_into_bytes`
16 changes: 8 additions & 8 deletions tests/ui-msrv/diagnostic-not-implemented-issue-1296.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19
error[E0277]: the trait bound `NotZerocopy: Immutable` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:50:19
|
52 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `zerocopy::Immutable` is not implemented for `NotZerocopy`
50 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `Immutable` is not implemented for `NotZerocopy`

error[E0277]: the trait bound `NotZerocopy: zerocopy::IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:52:19
error[E0277]: the trait bound `NotZerocopy: IntoBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-issue-1296.rs:50:19
|
52 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `zerocopy::IntoBytes` is not implemented for `NotZerocopy`
50 | Foo.write_obj(NotZerocopy(()));
| ^^^^^^^^^^^^^^^ the trait `IntoBytes` is not implemented for `NotZerocopy`
12 changes: 6 additions & 6 deletions tests/ui-msrv/diagnostic-not-implemented-known-layout.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::KnownLayout` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:18:26
error[E0277]: the trait bound `NotZerocopy: KnownLayout` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:16:26
|
18 | takes_known_layout::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::KnownLayout` is not implemented for `NotZerocopy`
16 | takes_known_layout::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_known_layout`
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:21:26
--> tests/ui-msrv/diagnostic-not-implemented-known-layout.rs:19:26
|
21 | fn takes_known_layout<T: KnownLayout>() {}
19 | fn takes_known_layout<T: KnownLayout>() {}
| ^^^^^^^^^^^ required by this bound in `takes_known_layout`
12 changes: 6 additions & 6 deletions tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:18:28
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:16:28
|
18 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
16 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_try_from_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:21:28
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:19:28
|
21 | fn takes_try_from_bytes<T: TryFromBytes>() {}
19 | fn takes_try_from_bytes<T: TryFromBytes>() {}
| ^^^^^^^^^^^^ required by this bound in `takes_try_from_bytes`
8 changes: 4 additions & 4 deletions tests/ui-msrv/diagnostic-not-implemented-unaligned.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy::Unaligned` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:18:23
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:16:23
|
18 | takes_unaligned::<NotZerocopy>();
16 | takes_unaligned::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `zerocopy::Unaligned` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_unaligned`
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:21:23
--> tests/ui-msrv/diagnostic-not-implemented-unaligned.rs:19:23
|
21 | fn takes_unaligned<T: Unaligned>() {}
19 | fn takes_unaligned<T: Unaligned>() {}
| ^^^^^^^^^ required by this bound in `takes_unaligned`
20 changes: 10 additions & 10 deletions tests/ui-msrv/include_value_not_from_bytes.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
error[E0277]: the trait bound `NotZerocopy<u32>: zerocopy::FromBytes` is not satisfied
--> tests/ui-msrv/include_value_not_from_bytes.rs:19:42
error[E0277]: the trait bound `NotZerocopy<u32>: FromBytes` is not satisfied
--> tests/ui-msrv/include_value_not_from_bytes.rs:17:5
|
19 | const NOT_FROM_BYTES: NotZerocopy<u32> = include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::FromBytes` is not implemented for `NotZerocopy<u32>`
17 | zerocopy::include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy<u32>`
|
note: required by a bound in `NOT_FROM_BYTES::transmute`
--> tests/ui-msrv/include_value_not_from_bytes.rs:19:42
--> tests/ui-msrv/include_value_not_from_bytes.rs:17:5
|
19 | const NOT_FROM_BYTES: NotZerocopy<u32> = include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `NOT_FROM_BYTES::transmute`
17 | zerocopy::include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| required by a bound in this
| required by this bound in `NOT_FROM_BYTES::transmute`
= note: this error originates in the macro `$crate::transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions tests/ui-msrv/include_value_wrong_size.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/include_value_wrong_size.rs:15:25
--> tests/ui-msrv/include_value_wrong_size.rs:12:25
|
15 | const WRONG_SIZE: u64 = include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 | const WRONG_SIZE: u64 = zerocopy::include_value!("../../testdata/include_value/data");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `[u8; 4]` (32 bits)
= note: target type: `u64` (64 bits)
Expand Down
Loading
Loading