diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 3770ba8ec7..b99427fc52 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -753,22 +753,21 @@ fn derive_into_bytes_struct(ast: &DeriveInput, strct: &DataStruct) -> Result Result Result Repr { None } } -} -impl Repr { + pub(crate) fn is_align_gt_1(&self) -> bool { + self.get_align().map(|n| n.t.get() > 1).unwrap_or(false) + } + /// When deriving `Unaligned`, validate that the decorated type has no /// `#[repr(align(N))]` attribute where `N > 1`. If no such attribute exists /// (including if `N == 1`), this returns `Ok(())`, and otherwise it returns diff --git a/zerocopy-derive/tests/ui-msrv/msrv_specific.rs b/zerocopy-derive/tests/ui-msrv/msrv_specific.rs new file mode 100644 index 0000000000..89904ced00 --- /dev/null +++ b/zerocopy-derive/tests/ui-msrv/msrv_specific.rs @@ -0,0 +1,37 @@ +// Copyright 2024 The Fuchsia Authors +// +// Licensed under a BSD-style license , Apache License, Version 2.0 +// , or the MIT +// license , at your option. +// This file may not be copied, modified, or distributed except according to +// those terms. + +// This file contains tests which trigger errors on MSRV during a different +// compiler pass compared to the stable or nightly toolchains. + +#[macro_use] +extern crate zerocopy; + +#[path = "../include.rs"] +mod util; + +use self::util::util::AU16; +use zerocopy::IntoBytes; + +fn main() {} + +// `repr(C, packed(2))` is not equivalent to `repr(C, packed)`. +#[derive(IntoBytes)] +#[repr(C, packed(2))] +struct IntoBytes1 { + t0: T, + // Add a second field to avoid triggering the "repr(C) struct with one + // field" special case. + t1: T, +} + +fn is_into_bytes_1() { + if false { + is_into_bytes_1::>(); + } +} diff --git a/zerocopy-derive/tests/ui-msrv/msrv_specific.stderr b/zerocopy-derive/tests/ui-msrv/msrv_specific.stderr new file mode 100644 index 0000000000..027fd48507 --- /dev/null +++ b/zerocopy-derive/tests/ui-msrv/msrv_specific.stderr @@ -0,0 +1,25 @@ +warning: unused `#[macro_use]` import + --> tests/ui-msrv/msrv_specific.rs:12:1 + | +12 | #[macro_use] + | ^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0277]: the trait bound `AU16: Unaligned` is not satisfied + --> tests/ui-msrv/msrv_specific.rs:35:9 + | +35 | is_into_bytes_1::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16` + | +note: required because of the requirements on the impl of `zerocopy::IntoBytes` for `IntoBytes1` + --> tests/ui-msrv/msrv_specific.rs:24:10 + | +24 | #[derive(IntoBytes)] + | ^^^^^^^^^ +note: required by a bound in `is_into_bytes_1` + --> tests/ui-msrv/msrv_specific.rs:33:23 + | +33 | fn is_into_bytes_1() { + | ^^^^^^^^^ required by this bound in `is_into_bytes_1` + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-msrv/struct.stderr b/zerocopy-derive/tests/ui-msrv/struct.stderr index ceef91f236..0f85734692 100644 --- a/zerocopy-derive/tests/ui-msrv/struct.stderr +++ b/zerocopy-derive/tests/ui-msrv/struct.stderr @@ -20,62 +20,78 @@ error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-msrv/struct.rs:164:10 + | +164 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-msrv/struct.rs:187:10 + | +187 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-msrv/struct.rs:167:11 + --> tests/ui-msrv/struct.rs:198:11 | -167 | #[repr(C, align(2))] +198 | #[repr(C, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/struct.rs:171:8 + --> tests/ui-msrv/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/struct.rs:177:16 + --> tests/ui-msrv/struct.rs:208:16 | -177 | #[repr(packed, align(2))] +208 | #[repr(packed, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/struct.rs:181:18 + --> tests/ui-msrv/struct.rs:212:18 | -181 | #[repr(align(1), align(2))] +212 | #[repr(align(1), align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/struct.rs:185:18 + --> tests/ui-msrv/struct.rs:216:18 | -185 | #[repr(align(2), align(4))] +216 | #[repr(align(2), align(4))] | ^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-msrv/struct.rs:188:10 + --> tests/ui-msrv/struct.rs:219:10 | -188 | #[derive(Unaligned)] +219 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-msrv/struct.rs:191:10 + --> tests/ui-msrv/struct.rs:222:10 | -191 | #[derive(Unaligned)] +222 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: this conflicts with another representation hint - --> tests/ui-msrv/struct.rs:201:8 + --> tests/ui-msrv/struct.rs:232:8 | -201 | #[repr(C, packed(2))] +232 | #[repr(C, packed(2))] | ^ error[E0692]: transparent struct cannot have other repr hints - --> tests/ui-msrv/struct.rs:171:8 + --> tests/ui-msrv/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ ^^^^^^^^ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time diff --git a/zerocopy-derive/tests/ui-msrv/union.stderr b/zerocopy-derive/tests/ui-msrv/union.stderr index 523d6e615b..88251941af 100644 --- a/zerocopy-derive/tests/ui-msrv/union.stderr +++ b/zerocopy-derive/tests/ui-msrv/union.stderr @@ -6,45 +6,61 @@ error: unsupported on types with type parameters | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-msrv/union.rs:47:10 + | +47 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-msrv/union.rs:53:10 + | +53 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-msrv/union.rs:51:11 + --> tests/ui-msrv/union.rs:64:11 | -51 | #[repr(C, align(2))] +64 | #[repr(C, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/union.rs:67:16 + --> tests/ui-msrv/union.rs:80:16 | -67 | #[repr(packed, align(2))] +80 | #[repr(packed, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/union.rs:73:18 + --> tests/ui-msrv/union.rs:86:18 | -73 | #[repr(align(1), align(2))] +86 | #[repr(align(1), align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-msrv/union.rs:79:18 + --> tests/ui-msrv/union.rs:92:18 | -79 | #[repr(align(2), align(4))] +92 | #[repr(align(2), align(4))] | ^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-msrv/union.rs:84:10 + --> tests/ui-msrv/union.rs:97:10 | -84 | #[derive(Unaligned)] +97 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-msrv/union.rs:90:10 - | -90 | #[derive(Unaligned)] - | ^^^^^^^^^ - | - = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/ui-msrv/union.rs:103:10 + | +103 | #[derive(Unaligned)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satisfied --> tests/ui-msrv/union.rs:24:10 diff --git a/zerocopy-derive/tests/ui-nightly/struct.rs b/zerocopy-derive/tests/ui-nightly/struct.rs index b895a8b02b..1204669b12 100644 --- a/zerocopy-derive/tests/ui-nightly/struct.rs +++ b/zerocopy-derive/tests/ui-nightly/struct.rs @@ -12,7 +12,7 @@ extern crate zerocopy; #[path = "../include.rs"] mod util; -use zerocopy::KnownLayout; +use zerocopy::{IntoBytes, KnownLayout}; use self::util::util::AU16; @@ -159,6 +159,37 @@ struct IntoBytes9 { t: T, } +// `repr(packed)` without `repr(C)` is not considered sufficient to guarantee +// layout. +#[derive(IntoBytes)] +#[repr(packed)] +struct IntoBytes10 { + t: T, +} + +// `repr(C, packed(2))` is not equivalent to `repr(C, packed)`. +#[derive(IntoBytes)] +#[repr(C, packed(2))] +struct IntoBytes11 { + t0: T, + // Add a second field to avoid triggering the "repr(C) struct with one + // field" special case. + t1: T, +} + +fn is_into_bytes_11() { + if false { + is_into_bytes_11::>(); + } +} + +// `repr(C, align(2))` is not sufficient to guarantee the layout of this type. +#[derive(IntoBytes)] +#[repr(C, align(2))] +struct IntoBytes12 { + t: T, +} + // // Unaligned errors // diff --git a/zerocopy-derive/tests/ui-nightly/struct.stderr b/zerocopy-derive/tests/ui-nightly/struct.stderr index e07bc32d27..27feadb541 100644 --- a/zerocopy-derive/tests/ui-nightly/struct.stderr +++ b/zerocopy-derive/tests/ui-nightly/struct.stderr @@ -20,65 +20,81 @@ error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-nightly/struct.rs:164:10 + | +164 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-nightly/struct.rs:187:10 + | +187 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-nightly/struct.rs:167:11 + --> tests/ui-nightly/struct.rs:198:11 | -167 | #[repr(C, align(2))] +198 | #[repr(C, align(2))] | ^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/struct.rs:171:8 + --> tests/ui-nightly/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/struct.rs:177:8 + --> tests/ui-nightly/struct.rs:208:8 | -177 | #[repr(packed, align(2))] +208 | #[repr(packed, align(2))] | ^^^^^^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/struct.rs:181:8 + --> tests/ui-nightly/struct.rs:212:8 | -181 | #[repr(align(1), align(2))] +212 | #[repr(align(1), align(2))] | ^^^^^^^^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/struct.rs:185:8 + --> tests/ui-nightly/struct.rs:216:8 | -185 | #[repr(align(2), align(4))] +216 | #[repr(align(2), align(4))] | ^^^^^^^^^^^^^^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-nightly/struct.rs:188:10 + --> tests/ui-nightly/struct.rs:219:10 | -188 | #[derive(Unaligned)] +219 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-nightly/struct.rs:191:10 + --> tests/ui-nightly/struct.rs:222:10 | -191 | #[derive(Unaligned)] +222 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: this conflicts with another representation hint - --> tests/ui-nightly/struct.rs:199:19 + --> tests/ui-nightly/struct.rs:230:19 | -199 | #[repr(packed(2), C)] +230 | #[repr(packed(2), C)] | ___________________^ -200 | | #[derive(Unaligned)] -201 | | #[repr(C, packed(2))] +231 | | #[derive(Unaligned)] +232 | | #[repr(C, packed(2))] | |________^ error[E0692]: transparent struct cannot have other repr hints - --> tests/ui-nightly/struct.rs:171:8 + --> tests/ui-nightly/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ ^^^^^^^^ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time @@ -360,7 +376,36 @@ note: required by a bound in `macro_util::__size_of::size_of` | ^^^^^ required by this bound in `size_of` error[E0587]: type has conflicting packed and align representation hints - --> tests/ui-nightly/struct.rs:178:1 + --> tests/ui-nightly/struct.rs:209:1 | -178 | struct Unaligned3; +209 | struct Unaligned3; | ^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `AU16: Unaligned` is not satisfied + --> tests/ui-nightly/struct.rs:182:28 + | +182 | is_into_bytes_11::>(); + | ^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16`, which is required by `IntoBytes11: zerocopy::IntoBytes` + | + = note: Consider adding `#[derive(Unaligned)]` to `AU16` + = help: the following other types implement trait `Unaligned`: + () + AtomicBool + AtomicI8 + AtomicU8 + F32 + F64 + I128 + I16 + and $N others +note: required for `IntoBytes11` to implement `zerocopy::IntoBytes` + --> tests/ui-nightly/struct.rs:171:10 + | +171 | #[derive(IntoBytes)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +note: required by a bound in `is_into_bytes_11` + --> tests/ui-nightly/struct.rs:180:24 + | +180 | fn is_into_bytes_11() { + | ^^^^^^^^^ required by this bound in `is_into_bytes_11` + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-nightly/union.rs b/zerocopy-derive/tests/ui-nightly/union.rs index b6d464a1bd..ffdd89f04f 100644 --- a/zerocopy-derive/tests/ui-nightly/union.rs +++ b/zerocopy-derive/tests/ui-nightly/union.rs @@ -43,6 +43,19 @@ union IntoBytes2 { bar: [u8; 2], } +// Need a `repr` attribute +#[derive(IntoBytes)] +union IntoBytes3 { + foo: u8, +} + +// `repr(packed(2))` isn't equivalent to `repr(packed)` +#[derive(IntoBytes)] +#[repr(packed(2))] +union IntoBytes4 { + foo: u8, +} + // // Unaligned errors // diff --git a/zerocopy-derive/tests/ui-nightly/union.stderr b/zerocopy-derive/tests/ui-nightly/union.stderr index bc090ce7b0..9060b9947b 100644 --- a/zerocopy-derive/tests/ui-nightly/union.stderr +++ b/zerocopy-derive/tests/ui-nightly/union.stderr @@ -6,45 +6,61 @@ error: unsupported on types with type parameters | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-nightly/union.rs:47:10 + | +47 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-nightly/union.rs:53:10 + | +53 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-nightly/union.rs:51:11 + --> tests/ui-nightly/union.rs:64:11 | -51 | #[repr(C, align(2))] +64 | #[repr(C, align(2))] | ^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/union.rs:67:8 + --> tests/ui-nightly/union.rs:80:8 | -67 | #[repr(packed, align(2))] +80 | #[repr(packed, align(2))] | ^^^^^^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/union.rs:73:8 + --> tests/ui-nightly/union.rs:86:8 | -73 | #[repr(align(1), align(2))] +86 | #[repr(align(1), align(2))] | ^^^^^^^^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-nightly/union.rs:79:8 + --> tests/ui-nightly/union.rs:92:8 | -79 | #[repr(align(2), align(4))] +92 | #[repr(align(2), align(4))] | ^^^^^^^^^^^^^^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-nightly/union.rs:84:10 + --> tests/ui-nightly/union.rs:97:10 | -84 | #[derive(Unaligned)] +97 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-nightly/union.rs:90:10 - | -90 | #[derive(Unaligned)] - | ^^^^^^^^^ - | - = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/ui-nightly/union.rs:103:10 + | +103 | #[derive(Unaligned)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satisfied --> tests/ui-nightly/union.rs:24:10 @@ -90,19 +106,19 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable | error[E0587]: type has conflicting packed and align representation hints - --> tests/ui-nightly/union.rs:68:1 + --> tests/ui-nightly/union.rs:81:1 | -68 | union Unaligned3 { +81 | union Unaligned3 { | ^^^^^^^^^^^^^^^^ error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type - --> tests/ui-nightly/union.rs:92:1 - | -92 | union Unaligned7 { - | ^^^^^^^^^^^^^^^^ - | + --> tests/ui-nightly/union.rs:105:1 + | +105 | union Unaligned7 { + | ^^^^^^^^^^^^^^^^ + | note: `AU16` has a `#[repr(align)]` attribute - --> tests/ui-nightly/../include.rs - | - | pub struct AU16(pub u16); - | ^^^^^^^^^^^^^^^ + --> tests/ui-nightly/../include.rs + | + | pub struct AU16(pub u16); + | ^^^^^^^^^^^^^^^ diff --git a/zerocopy-derive/tests/ui-stable/struct.stderr b/zerocopy-derive/tests/ui-stable/struct.stderr index 5ff8a80a60..f90830b065 100644 --- a/zerocopy-derive/tests/ui-stable/struct.stderr +++ b/zerocopy-derive/tests/ui-stable/struct.stderr @@ -20,62 +20,78 @@ error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-stable/struct.rs:164:10 + | +164 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must have a non-align #[repr(...)] attribute or #[repr(packed)] in order to guarantee this type's memory layout + --> tests/ui-stable/struct.rs:187:10 + | +187 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-stable/struct.rs:167:11 + --> tests/ui-stable/struct.rs:198:11 | -167 | #[repr(C, align(2))] +198 | #[repr(C, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/struct.rs:171:8 + --> tests/ui-stable/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/struct.rs:177:16 + --> tests/ui-stable/struct.rs:208:16 | -177 | #[repr(packed, align(2))] +208 | #[repr(packed, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/struct.rs:181:18 + --> tests/ui-stable/struct.rs:212:18 | -181 | #[repr(align(1), align(2))] +212 | #[repr(align(1), align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/struct.rs:185:18 + --> tests/ui-stable/struct.rs:216:18 | -185 | #[repr(align(2), align(4))] +216 | #[repr(align(2), align(4))] | ^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-stable/struct.rs:188:10 + --> tests/ui-stable/struct.rs:219:10 | -188 | #[derive(Unaligned)] +219 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-stable/struct.rs:191:10 + --> tests/ui-stable/struct.rs:222:10 | -191 | #[derive(Unaligned)] +222 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: this conflicts with another representation hint - --> tests/ui-stable/struct.rs:201:8 + --> tests/ui-stable/struct.rs:232:8 | -201 | #[repr(C, packed(2))] +232 | #[repr(C, packed(2))] | ^ error[E0692]: transparent struct cannot have other repr hints - --> tests/ui-stable/struct.rs:171:8 + --> tests/ui-stable/struct.rs:202:8 | -171 | #[repr(transparent, align(2))] +202 | #[repr(transparent, align(2))] | ^^^^^^^^^^^ ^^^^^^^^ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time @@ -321,7 +337,36 @@ note: required by a bound in `macro_util::__size_of::size_of` | ^^^^^ required by this bound in `size_of` error[E0587]: type has conflicting packed and align representation hints - --> tests/ui-stable/struct.rs:178:1 + --> tests/ui-stable/struct.rs:209:1 | -178 | struct Unaligned3; +209 | struct Unaligned3; | ^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `AU16: Unaligned` is not satisfied + --> tests/ui-stable/struct.rs:182:28 + | +182 | is_into_bytes_11::>(); + | ^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16`, which is required by `IntoBytes11: zerocopy::IntoBytes` + | + = note: Consider adding `#[derive(Unaligned)]` to `AU16` + = help: the following other types implement trait `Unaligned`: + () + AtomicBool + AtomicI8 + AtomicU8 + F32 + F64 + I128 + I16 + and $N others +note: required for `IntoBytes11` to implement `zerocopy::IntoBytes` + --> tests/ui-stable/struct.rs:171:10 + | +171 | #[derive(IntoBytes)] + | ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro +note: required by a bound in `is_into_bytes_11` + --> tests/ui-stable/struct.rs:180:24 + | +180 | fn is_into_bytes_11() { + | ^^^^^^^^^ required by this bound in `is_into_bytes_11` + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-stable/union.stderr b/zerocopy-derive/tests/ui-stable/union.stderr index a6fdadab30..141929e115 100644 --- a/zerocopy-derive/tests/ui-stable/union.stderr +++ b/zerocopy-derive/tests/ui-stable/union.stderr @@ -6,45 +6,61 @@ error: unsupported on types with type parameters | = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-stable/union.rs:47:10 + | +47 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)] + --> tests/ui-stable/union.rs:53:10 + | +53 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) + error: cannot derive `Unaligned` on type with alignment greater than 1 - --> tests/ui-stable/union.rs:51:11 + --> tests/ui-stable/union.rs:64:11 | -51 | #[repr(C, align(2))] +64 | #[repr(C, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/union.rs:67:16 + --> tests/ui-stable/union.rs:80:16 | -67 | #[repr(packed, align(2))] +80 | #[repr(packed, align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/union.rs:73:18 + --> tests/ui-stable/union.rs:86:18 | -73 | #[repr(align(1), align(2))] +86 | #[repr(align(1), align(2))] | ^^^^^ error: this conflicts with another representation hint - --> tests/ui-stable/union.rs:79:18 + --> tests/ui-stable/union.rs:92:18 | -79 | #[repr(align(2), align(4))] +92 | #[repr(align(2), align(4))] | ^^^^^ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-stable/union.rs:84:10 + --> tests/ui-stable/union.rs:97:10 | -84 | #[derive(Unaligned)] +97 | #[derive(Unaligned)] | ^^^^^^^^^ | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment - --> tests/ui-stable/union.rs:90:10 - | -90 | #[derive(Unaligned)] - | ^^^^^^^^^ - | - = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/ui-stable/union.rs:103:10 + | +103 | #[derive(Unaligned)] + | ^^^^^^^^^ + | + = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satisfied --> tests/ui-stable/union.rs:24:10 @@ -82,19 +98,19 @@ error[E0277]: `IntoBytes2` has inter-field padding = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0587]: type has conflicting packed and align representation hints - --> tests/ui-stable/union.rs:68:1 + --> tests/ui-stable/union.rs:81:1 | -68 | union Unaligned3 { +81 | union Unaligned3 { | ^^^^^^^^^^^^^^^^ error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type - --> tests/ui-stable/union.rs:92:1 - | -92 | union Unaligned7 { - | ^^^^^^^^^^^^^^^^ - | + --> tests/ui-stable/union.rs:105:1 + | +105 | union Unaligned7 { + | ^^^^^^^^^^^^^^^^ + | note: `AU16` has a `#[repr(align)]` attribute - --> tests/ui-stable/../include.rs - | - | pub struct AU16(pub u16); - | ^^^^^^^^^^^^^^^ + --> tests/ui-stable/../include.rs + | + | pub struct AU16(pub u16); + | ^^^^^^^^^^^^^^^