From 63b5e784e85f276201cde4b0a3ef191e663cfed4 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Sat, 21 Sep 2024 10:31:39 -0700 Subject: [PATCH] [derive] Improve IntoBytes error messages (#1712) On Rust toolchains 1.78.0 or later, use `#[diagnostic::on_unimplemented]` to improve the error message emitted when `IntoBytes` is derived on a type with inter-field padding. --- src/lib.rs | 19 ++++++------ src/util/macro_util.rs | 24 ++++++++------- zerocopy-derive/Cargo.toml | 2 +- zerocopy-derive/src/lib.rs | 19 ++---------- zerocopy-derive/src/output_tests.rs | 23 ++++++++++++++ zerocopy-derive/tests/ui-msrv/enum.stderr | 18 +++++------ zerocopy-derive/tests/ui-msrv/struct.stderr | 12 ++++---- zerocopy-derive/tests/ui-msrv/union.stderr | 6 ++-- zerocopy-derive/tests/ui-nightly/enum.stderr | 30 +++++++++++++------ .../tests/ui-nightly/struct.stderr | 20 +++++++++---- zerocopy-derive/tests/ui-nightly/union.stderr | 10 +++++-- zerocopy-derive/tests/ui-stable/enum.stderr | 30 +++++++++++++------ zerocopy-derive/tests/ui-stable/struct.stderr | 20 +++++++++---- zerocopy-derive/tests/ui-stable/union.stderr | 10 +++++-- 14 files changed, 152 insertions(+), 91 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b1df9a54a7..6d052ed175 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3852,25 +3852,26 @@ fn mut_from_prefix_suffix( /// /// # Error Messages /// -/// Due to the way that the custom derive for `IntoBytes` is implemented, you -/// may get an error like this: +/// On Rust toolchains prior to 1.78.0, due to the way that the custom derive +/// for `IntoBytes` is implemented, you may get an error like this: /// /// ```text -/// error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +/// error[E0277]: the trait bound `(): PaddingFree` is not satisfied /// --> lib.rs:23:10 /// | /// 1 | #[derive(IntoBytes)] -/// | ^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` +/// | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` /// | -/// = help: the trait `ShouldBe` is implemented for `HasPadding` +/// = help: the following implementations were found: +/// <() as PaddingFree> /// ``` /// /// This error indicates that the type being annotated has padding bytes, which /// is illegal for `IntoBytes` types. Consider reducing the alignment of some -/// fields by using types in the [`byteorder`] module, adding explicit struct -/// fields where those padding bytes would be, or using `#[repr(packed)]`. See -/// the Rust Reference's page on [type layout] for more information about type -/// layout and padding. +/// fields by using types in the [`byteorder`] module, wrapping field types in +/// [`Unalign`], adding explicit struct fields where those padding bytes would +/// be, or using `#[repr(packed)]`. See the Rust Reference's page on [type +/// layout] for more information about type layout and padding. /// /// [type layout]: https://doc.rust-lang.org/reference/type-layout.html /// diff --git a/src/util/macro_util.rs b/src/util/macro_util.rs index 10d98affe0..f7e66056d2 100644 --- a/src/util/macro_util.rs +++ b/src/util/macro_util.rs @@ -17,10 +17,7 @@ #![allow(missing_debug_implementations)] -use core::{ - marker::PhantomData, - mem::{self, ManuallyDrop}, -}; +use core::mem::{self, ManuallyDrop}; // TODO(#29), TODO(https://github.com/rust-lang/rust/issues/69835): Remove this // `cfg` when `size_of_val_raw` is stabilized. @@ -35,13 +32,18 @@ use crate::{ Immutable, IntoBytes, Ptr, TryFromBytes, Unalign, ValidityError, }; -/// A compile-time check that should be one particular value. -pub trait ShouldBe {} - -/// A struct for checking whether `T` contains padding. -pub struct HasPadding(PhantomData); - -impl ShouldBe for HasPadding {} +#[cfg_attr( + zerocopy_diagnostic_on_unimplemented, + diagnostic::on_unimplemented( + message = "`{T}` has inter-field padding", + label = "types with padding cannot implement `IntoBytes`", + note = "consider using `zerocopy::Unalign` to lower the alignment of individual fields", + note = "consider adding explicit fields where padding would be", + note = "consider using `#[repr(packed)]` to remove inter-field padding" + ) +)] +pub trait PaddingFree {} +impl PaddingFree for () {} /// A type whose size is equal to `align_of::()`. #[repr(C)] diff --git a/zerocopy-derive/Cargo.toml b/zerocopy-derive/Cargo.toml index d0caa94ca3..612324ef69 100644 --- a/zerocopy-derive/Cargo.toml +++ b/zerocopy-derive/Cargo.toml @@ -28,7 +28,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.1" quote = "1.0.10" -syn = "2.0.46" +syn = { version = "2.0.46", features = ["full"] } [dev-dependencies] dissimilar = "1.0.9" diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 56db2852db..df983fd190 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -36,7 +36,6 @@ mod repr; use proc_macro2::{TokenStream, TokenTree}; use quote::ToTokens; -use syn::{punctuated::Punctuated, token::Colon, PredicateType}; use { proc_macro2::Span, @@ -1222,27 +1221,15 @@ fn impl_block( let validator_context = check.validator_macro_context(); let validator_macro = check.validator_macro_ident(); let t = tag.iter(); - // We have to manually construct a bound here because the validator - // context may include type definitions and syn cannot parse type - // definitions in const exprs without the `full` feature enabled. - // Constructing these bounds "verbatim" gets around this issue. - let bounded_ty = Type::Verbatim(quote! { - ::zerocopy::util::macro_util::HasPadding< + parse_quote! { + (): ::zerocopy::util::macro_util::PaddingFree< #type_ident, { #validator_context ::zerocopy::#validator_macro!(#type_ident, #(#t,)* #(#variant_types),*) } > - }); - let mut bounds = Punctuated::new(); - bounds.push(parse_quote! { ::zerocopy::util::macro_util::ShouldBe }); - WherePredicate::Type(PredicateType { - lifetimes: None, - bounded_ty, - colon_token: Colon::default(), - bounds, - }) + } }); let self_bounds: Option = match self_type_trait_bounds { diff --git a/zerocopy-derive/src/output_tests.rs b/zerocopy-derive/src/output_tests.rs index 126f0b519e..e89911b0c2 100644 --- a/zerocopy-derive/src/output_tests.rs +++ b/zerocopy-derive/src/output_tests.rs @@ -234,6 +234,29 @@ fn test_into_bytes() { } } no_build } + + test! { + IntoBytes { + #[repr(C)] + struct Foo { + a: u8, + b: u8, + } + } expands to { + #[allow(deprecated)] + unsafe impl ::zerocopy::IntoBytes for Foo + where + u8: ::zerocopy::IntoBytes, + u8: ::zerocopy::IntoBytes, + (): ::zerocopy::util::macro_util::PaddingFree< + Foo, + { ::zerocopy::struct_has_padding!(Foo, [u8, u8]) }, + >, + { + fn only_derive_is_allowed_to_implement_this_trait() {} + } + } no_build + } } #[test] diff --git a/zerocopy-derive/tests/ui-msrv/enum.stderr b/zerocopy-derive/tests/ui-msrv/enum.stderr index e9005e20f4..2b84ad9ccc 100644 --- a/zerocopy-derive/tests/ui-msrv/enum.stderr +++ b/zerocopy-derive/tests/ui-msrv/enum.stderr @@ -343,35 +343,35 @@ error[E0277]: the trait bound `bool: FromBytes` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/enum.rs:533:10 | 533 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/enum.rs:544:10 | 544 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/enum.rs:550:10 | 550 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = 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 60eb7e7168..9cc7ac22a1 100644 --- a/zerocopy-derive/tests/ui-msrv/struct.stderr +++ b/zerocopy-derive/tests/ui-msrv/struct.stderr @@ -110,25 +110,25 @@ error[E0277]: the trait bound `AU16: Unaligned` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/struct.rs:107:10 | 107 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/struct.rs:114:10 | 114 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = 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/union.stderr b/zerocopy-derive/tests/ui-msrv/union.stderr index f1df5fe9c4..26272a5057 100644 --- a/zerocopy-derive/tests/ui-msrv/union.stderr +++ b/zerocopy-derive/tests/ui-msrv/union.stderr @@ -40,13 +40,13 @@ error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satis = help: see issue #48214 = note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: the trait bound `(): PaddingFree` is not satisfied --> tests/ui-msrv/union.rs:39:10 | 39 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ the trait `PaddingFree` is not implemented for `()` | = help: the following implementations were found: - as ShouldBe> + <() as PaddingFree> = help: see issue #48214 = 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/enum.stderr b/zerocopy-derive/tests/ui-nightly/enum.stderr index f93083878b..04db0af8b6 100644 --- a/zerocopy-derive/tests/ui-nightly/enum.stderr +++ b/zerocopy-derive/tests/ui-nightly/enum.stderr @@ -413,13 +413,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes1` has inter-field padding --> tests/ui-nightly/enum.rs:533:10 | 533 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable @@ -427,13 +431,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-nightly/enum.rs:544:10 | 544 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable @@ -441,13 +449,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes3` has inter-field padding --> tests/ui-nightly/enum.rs:550:10 | 550 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable diff --git a/zerocopy-derive/tests/ui-nightly/struct.stderr b/zerocopy-derive/tests/ui-nightly/struct.stderr index 7ecabd3d3c..feef5cb800 100644 --- a/zerocopy-derive/tests/ui-nightly/struct.stderr +++ b/zerocopy-derive/tests/ui-nightly/struct.stderr @@ -241,13 +241,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-nightly/struct.rs:107:10 | 107 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable @@ -255,13 +259,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes3` has inter-field padding --> tests/ui-nightly/struct.rs:114:10 | 114 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable diff --git a/zerocopy-derive/tests/ui-nightly/union.stderr b/zerocopy-derive/tests/ui-nightly/union.stderr index e03b921cf2..7650f84c8e 100644 --- a/zerocopy-derive/tests/ui-nightly/union.stderr +++ b/zerocopy-derive/tests/ui-nightly/union.stderr @@ -55,13 +55,17 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable 9 + #![feature(trivial_bounds)] | -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-nightly/union.rs:39:10 | 39 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `#![feature(trivial_bounds)]` to the crate attributes to enable diff --git a/zerocopy-derive/tests/ui-stable/enum.stderr b/zerocopy-derive/tests/ui-stable/enum.stderr index 359da6ba1b..60f94aa3c4 100644 --- a/zerocopy-derive/tests/ui-stable/enum.stderr +++ b/zerocopy-derive/tests/ui-stable/enum.stderr @@ -385,32 +385,44 @@ error[E0277]: the trait bound `bool: FromBytes` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes1` has inter-field padding --> tests/ui-stable/enum.rs:533:10 | 533 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-stable/enum.rs:544:10 | 544 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes3` has inter-field padding --> tests/ui-stable/enum.rs:550:10 | 550 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = 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/struct.stderr b/zerocopy-derive/tests/ui-stable/struct.stderr index c3ba2b7d39..da842f1a15 100644 --- a/zerocopy-derive/tests/ui-stable/struct.stderr +++ b/zerocopy-derive/tests/ui-stable/struct.stderr @@ -213,23 +213,31 @@ error[E0277]: the trait bound `AU16: Unaligned` is not satisfied = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-stable/struct.rs:107:10 | 107 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes3` has inter-field padding --> tests/ui-stable/struct.rs:114:10 | 114 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = 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 8e9e18c110..eb3f7a09d9 100644 --- a/zerocopy-derive/tests/ui-stable/union.stderr +++ b/zerocopy-derive/tests/ui-stable/union.stderr @@ -51,13 +51,17 @@ error[E0277]: the trait bound `UnsafeCell<()>: zerocopy::Immutable` is not satis = help: see issue #48214 = note: this error originates in the derive macro `Immutable` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `HasPadding: ShouldBe` is not satisfied +error[E0277]: `IntoBytes2` has inter-field padding --> tests/ui-stable/union.rs:39:10 | 39 | #[derive(IntoBytes)] - | ^^^^^^^^^ the trait `ShouldBe` is not implemented for `HasPadding` + | ^^^^^^^^^ types with padding cannot implement `IntoBytes` | - = help: the trait `ShouldBe` is implemented for `HasPadding` + = help: the trait `PaddingFree` is not implemented for `()` + = note: consider using `zerocopy::Unalign` to lower the alignment of individual fields + = note: consider adding explicit fields where padding would be + = note: consider using `#[repr(packed)]` to remove inter-field padding + = help: the trait `PaddingFree` is implemented for `()` = help: see issue #48214 = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)