diff --git a/tools/cargo-zerocopy/src/main.rs b/tools/cargo-zerocopy/src/main.rs index 4256c42d63..adef534b3f 100644 --- a/tools/cargo-zerocopy/src/main.rs +++ b/tools/cargo-zerocopy/src/main.rs @@ -167,7 +167,7 @@ fn install_toolchain_or_exit(versions: &Versions, name: &str) -> Result<(), Erro fn get_rustflags(name: &str) -> String { // See #1792 for context on zerocopy_derive_union_into_bytes. let mut flags = - "--cfg zerocopy_derive_union_into_bytes --cfg __ZEROCOPY_INTERNAL_USE_ONLY_DEV_MODE" + "--cfg zerocopy_unstable_derive_on_error --cfg zerocopy_derive_union_into_bytes --cfg __ZEROCOPY_INTERNAL_USE_ONLY_DEV_MODE" .to_string(); flags += &format!(" --cfg __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN=\"{name}\""); diff --git a/zerocopy-derive/Cargo.toml b/zerocopy-derive/Cargo.toml index f871016075..c7f9ce69ca 100644 --- a/zerocopy-derive/Cargo.toml +++ b/zerocopy-derive/Cargo.toml @@ -24,7 +24,10 @@ exclude = [".*", "tests/enum_from_bytes.rs", "tests/ui-nightly/enum_from_bytes_u [lints.rust] # See #1792 for more context. -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zerocopy_derive_union_into_bytes)'] } +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(zerocopy_derive_union_into_bytes)', + 'cfg(zerocopy_unstable_derive_on_error)', +] } [lib] proc-macro = true diff --git a/zerocopy-derive/src/derive/from_bytes.rs b/zerocopy-derive/src/derive/from_bytes.rs index 1fab960d99..ad8b6233fe 100644 --- a/zerocopy-derive/src/derive/from_bytes.rs +++ b/zerocopy-derive/src/derive/from_bytes.rs @@ -117,10 +117,12 @@ fn derive_from_zeros_enum(ctx: &Ctx, enm: &DataEnum) -> Result { } Repr::Transparent(_) | Repr::Compound(Spanned { t: CompoundRepr::Rust, span: _ }, _) => { - return Err(Error::new( - Span::call_site(), - "must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout", - )); + return ctx.error_or_skip( + Error::new( + Span::call_site(), + "must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout", + ), + ); } } @@ -128,7 +130,7 @@ fn derive_from_zeros_enum(ctx: &Ctx, enm: &DataEnum) -> Result enm.variants.iter().nth(index).unwrap(), // Has unknown variants Err(true) => { - return Err(Error::new_spanned( + return ctx.error_or_skip(Error::new_spanned( &ctx.ast, "FromZeros only supported on enums with a variant that has a discriminant of `0`\n\ help: This enum has discriminants which are not literal integers. One of those may \ @@ -138,7 +140,7 @@ fn derive_from_zeros_enum(ctx: &Ctx, enm: &DataEnum) -> Result { - return Err(Error::new_spanned( + return ctx.error_or_skip(Error::new_spanned( &ctx.ast, "FromZeros only supported on enums with a variant that has a discriminant of `0`", )); @@ -170,7 +172,7 @@ fn derive_from_bytes_enum(ctx: &Ctx, enm: &DataEnum) -> Result Result Result Result { let repr = EnumRepr::from_attrs(&ctx.ast.attrs)?; if !repr.is_c() && !repr.is_primitive() { - return Err(Error::new( + return ctx.error_or_skip(Error::new( Span::call_site(), "must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout", )); @@ -127,6 +127,7 @@ fn derive_into_bytes_union(ctx: &Ctx, unn: &DataUnion) -> Result unsafe { gen_trivial_is_bit_valid_unchecked(ctx) }, - (None, false) => derive_is_bit_valid(ctx, enm, &repr)?, + (None, false) => match derive_is_bit_valid(ctx, enm, &repr) { + Ok(extra) => extra, + Err(_) if ctx.skip_on_error => return Ok(TokenStream::new()), + Err(e) => return Err(e), + }, }; Ok(ImplBlockBuilder::new(ctx, enm, Trait::TryFromBytes, FieldBounds::ALL_SELF) @@ -697,7 +701,13 @@ fn try_gen_trivial_is_bit_valid(ctx: &Ctx, top_level: Trait) -> Option Option proc_macro2::TokenStream { let zerocopy_crate = &ctx.zerocopy_crate; let core = ctx.core_path(); diff --git a/zerocopy-derive/src/derive/unaligned.rs b/zerocopy-derive/src/derive/unaligned.rs index b329e860fa..819d84984a 100644 --- a/zerocopy-derive/src/derive/unaligned.rs +++ b/zerocopy-derive/src/derive/unaligned.rs @@ -28,7 +28,7 @@ fn derive_unaligned_struct(ctx: &Ctx, strct: &DataStruct) -> Result Result Result, } impl Ctx { @@ -25,6 +33,8 @@ impl Ctx { /// `::zerocopy` if not found. pub(crate) fn try_from_derive_input(ast: DeriveInput) -> Result { let mut path = parse_quote!(::zerocopy); + let mut skip_on_error = false; + let mut on_error_span = None; for attr in &ast.attrs { if let Meta::List(ref meta_list) = attr.meta { @@ -45,6 +55,21 @@ impl Ctx { )); } + if meta.path.is_ident("on_error") { + on_error_span = Some(meta.path.span()); + let value = meta.value()?; + let s: LitStr = value.parse()?; + match s.value().as_str() { + "skip" => skip_on_error = true, + "fail" => skip_on_error = false, + _ => return Err(Error::new( + s.span(), + "unrecognized value for `on_error` attribute from `zerocopy`; expected `skip` or `fail`", + )), + } + return Ok(()); + } + Err(Error::new( Span::call_site(), format!( @@ -57,17 +82,55 @@ impl Ctx { } } - Ok(Self { ast, zerocopy_crate: path }) + Ok(Self { ast, zerocopy_crate: path, skip_on_error, on_error_span }) } pub(crate) fn with_input(&self, input: &DeriveInput) -> Self { - Self { ast: input.clone(), zerocopy_crate: self.zerocopy_crate.clone() } + Self { + ast: input.clone(), + zerocopy_crate: self.zerocopy_crate.clone(), + skip_on_error: self.skip_on_error, + on_error_span: self.on_error_span, + } } pub(crate) fn core_path(&self) -> TokenStream { let zerocopy_crate = &self.zerocopy_crate; quote!(#zerocopy_crate::util::macro_util::core_reexport) } + + pub(crate) fn cfg_compile_error(&self) -> TokenStream { + // By checking both during the compilation of the proc macro *and* in + // the generated code, we ensure that `--cfg + // zerocopy_unstable_derive_on_error` need only be passed *either* when + // compiling this crate *or* when compiling the user's crate. The former + // is preferable, but in some situations (such as when cross-compiling + // using `cargo build --target`), it doesn't get propagated to this + // crate's build by default. + if cfg!(zerocopy_unstable_derive_on_error) { + quote!() + } else if let Some(span) = self.on_error_span { + let core = self.core_path(); + let error_message = "`on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable"; + quote::quote_spanned! {span=> + #[allow(unused_attributes, unexpected_cfgs)] + const _: () = { + #[cfg(not(zerocopy_unstable_derive_on_error))] + #core::compile_error!(#error_message); + }; + } + } else { + quote!() + } + } + + pub(crate) fn error_or_skip(&self, error: E) -> Result { + if self.skip_on_error { + Ok(self.cfg_compile_error()) + } else { + Err(error) + } + } } pub(crate) trait DataExt { @@ -586,7 +649,10 @@ impl<'a> ImplBlockBuilder<'a> { }); let inner_extras = self.inner_extras; + let allow_trivial_bounds = + if self.ctx.skip_on_error { quote!(#[allow(trivial_bounds)]) } else { quote!() }; let impl_tokens = quote! { + #allow_trivial_bounds unsafe impl < #(#params),* > #trait_path for #type_ident < #(#param_idents),* > where #(#bounds,)* @@ -598,7 +664,8 @@ impl<'a> ImplBlockBuilder<'a> { }; let outer_extras = self.outer_extras.filter(|e| !e.is_empty()); - const_block([Some(impl_tokens), outer_extras]) + let cfg_compile_error = self.ctx.cfg_compile_error(); + const_block([Some(cfg_compile_error), Some(impl_tokens), outer_extras]) } } diff --git a/zerocopy-derive/tests/on_error.rs b/zerocopy-derive/tests/on_error.rs new file mode 100644 index 0000000000..b731bf2212 --- /dev/null +++ b/zerocopy-derive/tests/on_error.rs @@ -0,0 +1,169 @@ +// Copyright 2026 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. + +// See comment in `include.rs` for why we disable the prelude. +#![no_implicit_prelude] +#![allow(warnings)] +#![cfg_attr(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS, feature(trivial_bounds))] + +include!("include.rs"); + +#[derive(imp::FromBytes)] +#[zerocopy(on_error = "fail")] +#[zerocopy(crate = "zerocopy_renamed")] +struct LoudValid; + +util_assert_impl_all!(LoudValid: imp::FromBytes); + +// `derive(Unaligned)` fails without a repr. +#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +struct Foo { + a: u8, +} + +util_assert_impl_all!(Foo: imp::FromBytes, imp::IntoBytes); +util_assert_not_impl_any!(Foo: imp::Unaligned); + +// Invalid enum for FromZeros (must have discriminant 0). +#[derive(imp::FromZeros)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(u8)] +enum BadFromZerosEnum { + A = 1, + B = 2, +} + +util_assert_not_impl_any!(BadFromZerosEnum: imp::FromZeros); + +// Invalid enum for FromBytes (must have 256 variants). +#[derive(imp::FromBytes)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(u8)] +enum BadFromBytesEnum { + A = 0, +} + +util_assert_not_impl_any!(BadFromBytesEnum: imp::FromBytes); + +// Invalid enum for IntoBytes (invalid repr). +#[derive(imp::IntoBytes)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[cfg_attr( + any( + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "nightly", + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "stable" + ), + repr(Rust) +)] +enum BadIntoBytesEnum { + A, +} + +util_assert_not_impl_any!(BadIntoBytesEnum: imp::IntoBytes); + +// Invalid enum for Unaligned (invalid repr). +#[derive(imp::Unaligned)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(u16)] +enum BadUnalignedEnum { + A, +} + +util_assert_not_impl_any!(BadUnalignedEnum: imp::Unaligned); + +// Invalid enum for TryFromBytes (invalid repr). +#[derive(imp::TryFromBytes)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[cfg_attr( + any( + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "nightly", + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "stable" + ), + repr(Rust) +)] +enum BadTryFromBytesEnum { + A, +} + +util_assert_not_impl_any!(BadTryFromBytesEnum: imp::TryFromBytes); + +// Invalid union for IntoBytes (invalid repr). +#[derive(imp::IntoBytes)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[cfg_attr( + any( + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "nightly", + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "stable" + ), + repr(Rust) +)] +union BadIntoBytesUnion { + a: u8, +} + +util_assert_not_impl_any!(BadIntoBytesUnion: imp::IntoBytes); + +// Invalid union for Unaligned (invalid repr). +#[derive(imp::Unaligned)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[cfg_attr( + any( + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "nightly", + __ZEROCOPY_INTERNAL_USE_ONLY_TOOLCHAIN = "stable" + ), + repr(Rust) +)] +union BadUnalignedUnion { + a: u8, +} + +util_assert_not_impl_any!(BadUnalignedUnion: imp::Unaligned); + +// Invalid union for IntoBytes (generic). +#[derive(imp::IntoBytes)] +#[zerocopy(on_error = "skip")] +#[zerocopy(crate = "zerocopy_renamed")] +#[repr(C)] +union BadIntoBytesUnionGeneric { + a: T, +} + +util_assert_not_impl_any!(BadIntoBytesUnionGeneric: imp::IntoBytes); + +#[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)] +mod trivial_bounds { + use super::*; + + #[derive(imp::FromBytes)] + #[zerocopy(on_error = "skip")] + #[zerocopy(crate = "zerocopy_renamed")] + #[repr(transparent)] + struct TrivialBounds(bool); + + util_assert_not_impl_any!(TrivialBounds: imp::FromBytes); + + #[derive(imp::IntoBytes)] + #[zerocopy(on_error = "skip")] + #[zerocopy(crate = "zerocopy_renamed")] + #[repr(C)] + struct BadIntoBytesStructPadding { + a: u8, + b: u16, + } + + util_assert_not_impl_any!(BadIntoBytesStructPadding: imp::IntoBytes); +} diff --git a/zerocopy-derive/tests/trybuild.rs b/zerocopy-derive/tests/trybuild.rs index ee5759acdd..c3019b1fbf 100644 --- a/zerocopy-derive/tests/trybuild.rs +++ b/zerocopy-derive/tests/trybuild.rs @@ -32,11 +32,12 @@ fn test(subdir: &str) { fn ui() { test(""); - // This tests the behavior when `--cfg zerocopy_derive_union_into_bytes` is - // not present, so remove it. If this logic is wrong, that's fine - it will - // exhibit as a test failure that we can debug at that point. + // This tests the behavior when `--cfg`s are not present, so remove them. If + // this logic is wrong, that's fine - it will exhibit as a test failure that + // we can debug at that point. let rustflags = env::var("RUSTFLAGS").unwrap(); let new_rustflags = rustflags.replace("--cfg zerocopy_derive_union_into_bytes", ""); + let new_rustflags = new_rustflags.replace("--cfg zerocopy_unstable_derive_on_error", ""); // SAFETY: None of our code is concurrently accessinv env vars. It's // possible that the test framework has spawned other threads that are @@ -46,7 +47,7 @@ fn ui() { env::set_var("RUSTFLAGS", new_rustflags) }; - test("union_into_bytes_cfg"); + test("cfgs"); // Reset RUSTFLAGS in case we later add other tests which rely on its value. // This isn't strictly necessary, but it's easier to add this now when we're diff --git a/zerocopy-derive/tests/ui-msrv/cfgs/on_error.rs b/zerocopy-derive/tests/ui-msrv/cfgs/on_error.rs new file mode 120000 index 0000000000..fe540e05e1 --- /dev/null +++ b/zerocopy-derive/tests/ui-msrv/cfgs/on_error.rs @@ -0,0 +1 @@ +../../ui-nightly/cfgs/on_error.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-msrv/cfgs/on_error.stderr b/zerocopy-derive/tests/ui-msrv/cfgs/on_error.stderr new file mode 100644 index 0000000000..da8ab2faa3 --- /dev/null +++ b/zerocopy-derive/tests/ui-msrv/cfgs/on_error.stderr @@ -0,0 +1,16 @@ +error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable + --> tests/ui-msrv/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ + | + = 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 `bool: FromBytes` is not satisfied + --> tests/ui-msrv/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ the trait `FromBytes` is not implemented for `bool` + | + = help: see issue #48214 + = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.rs b/zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.rs new file mode 120000 index 0000000000..c06e751c94 --- /dev/null +++ b/zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.rs @@ -0,0 +1 @@ +../../ui-nightly/cfgs/union_into_bytes_cfg.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.stderr b/zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.stderr similarity index 82% rename from zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.stderr rename to zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.stderr index d25c238f6e..88ad8a4c9c 100644 --- a/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.stderr +++ b/zerocopy-derive/tests/ui-msrv/cfgs/union_into_bytes_cfg.stderr @@ -1,6 +1,6 @@ error: requires --cfg zerocopy_derive_union_into_bytes; please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 - --> tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 + --> tests/ui-msrv/cfgs/union_into_bytes_cfg.rs:20:10 | 20 | #[derive(IntoBytes)] | ^^^^^^^^^ diff --git a/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs b/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs deleted file mode 120000 index 66ef0de5be..0000000000 --- a/zerocopy-derive/tests/ui-msrv/union_into_bytes_cfg/union_into_bytes_cfg.rs +++ /dev/null @@ -1 +0,0 @@ -../../ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-nightly/cfgs/on_error.rs b/zerocopy-derive/tests/ui-nightly/cfgs/on_error.rs new file mode 100644 index 0000000000..2bf197aafd --- /dev/null +++ b/zerocopy-derive/tests/ui-nightly/cfgs/on_error.rs @@ -0,0 +1,19 @@ +// Copyright 2026 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. + +extern crate zerocopy_renamed; + +use zerocopy_renamed::FromBytes; + +#[derive(FromBytes)] +#[zerocopy(crate = "zerocopy_renamed")] +#[zerocopy(on_error = "skip")] +#[repr(C)] +struct Foo(bool); + +fn main() {} diff --git a/zerocopy-derive/tests/ui-nightly/cfgs/on_error.stderr b/zerocopy-derive/tests/ui-nightly/cfgs/on_error.stderr new file mode 100644 index 0000000000..8bc9ad3cf9 --- /dev/null +++ b/zerocopy-derive/tests/ui-nightly/cfgs/on_error.stderr @@ -0,0 +1,31 @@ +error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable + --> tests/ui-nightly/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ + | + = 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 `bool: FromBytes` is not satisfied + --> tests/ui-nightly/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ the trait `FromBytes` is not implemented for `bool` + | + = note: Consider adding `#[derive(FromBytes)]` to `bool` + = help: the following other types implement trait `FromBytes`: + () + (A, B) + (A, B, C) + (A, B, C, D) + (A, B, C, D, E) + (A, B, C, D, E, F) + (A, B, C, D, E, F, G) + (A, B, C, D, E, F, G, H) + and $N others + = help: see issue #48214 + = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | + 9 + #![feature(trivial_bounds)] + | diff --git a/zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs b/zerocopy-derive/tests/ui-nightly/cfgs/union_into_bytes_cfg.rs similarity index 100% rename from zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs rename to zerocopy-derive/tests/ui-nightly/cfgs/union_into_bytes_cfg.rs diff --git a/zerocopy-derive/tests/ui-nightly/cfgs/union_into_bytes_cfg.stderr b/zerocopy-derive/tests/ui-nightly/cfgs/union_into_bytes_cfg.stderr new file mode 100644 index 0000000000..e45e46c16c --- /dev/null +++ b/zerocopy-derive/tests/ui-nightly/cfgs/union_into_bytes_cfg.stderr @@ -0,0 +1,8 @@ +error: requires --cfg zerocopy_derive_union_into_bytes; + please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 + --> tests/ui-nightly/cfgs/union_into_bytes_cfg.rs:20:10 + | +20 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = 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.stderr b/zerocopy-derive/tests/ui-nightly/union.stderr index bf167cbc86..6e5008f1bc 100644 --- a/zerocopy-derive/tests/ui-nightly/union.stderr +++ b/zerocopy-derive/tests/ui-nightly/union.stderr @@ -62,20 +62,6 @@ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) -warning: unexpected `cfg` condition name: `zerocopy_derive_union_into_bytes` - --> tests/ui-nightly/union.rs:42:10 - | -42 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = help: expected names are: `docsrs`, `feature`, and `test` and 31 more - = note: using a cfg inside a derive macro will use the cfgs from the destination crate and not the ones from the defining crate - = help: try referring to `IntoBytes` crate for guidance on how handle this unexpected cfg - = help: the derive macro `IntoBytes` may come from an old version of the `zerocopy_derive` crate, try updating your dependency with `cargo update -p zerocopy_derive` - = note: see for more information about checking conditional configuration - = note: `#[warn(unexpected_cfgs)]` on by default - = note: this warning originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied --> tests/ui-nightly/union.rs:25:10 | diff --git a/zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.stderr b/zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.stderr deleted file mode 100644 index 3154641f24..0000000000 --- a/zerocopy-derive/tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: requires --cfg zerocopy_derive_union_into_bytes; - please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 - --> tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 - | -20 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: unexpected `cfg` condition name: `zerocopy_derive_union_into_bytes` - --> tests/ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 - | -20 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = help: expected names are: `docsrs`, `feature`, and `test` and 31 more - = note: using a cfg inside a derive macro will use the cfgs from the destination crate and not the ones from the defining crate - = help: try referring to `IntoBytes` crate for guidance on how handle this unexpected cfg - = help: the derive macro `IntoBytes` may come from an old version of the `zerocopy_derive` crate, try updating your dependency with `cargo update -p zerocopy_derive` - = note: see for more information about checking conditional configuration - = note: `#[warn(unexpected_cfgs)]` on by default - = note: this warning 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/cfgs/on_error.rs b/zerocopy-derive/tests/ui-stable/cfgs/on_error.rs new file mode 120000 index 0000000000..fe540e05e1 --- /dev/null +++ b/zerocopy-derive/tests/ui-stable/cfgs/on_error.rs @@ -0,0 +1 @@ +../../ui-nightly/cfgs/on_error.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-stable/cfgs/on_error.stderr b/zerocopy-derive/tests/ui-stable/cfgs/on_error.stderr new file mode 100644 index 0000000000..fb979de3ad --- /dev/null +++ b/zerocopy-derive/tests/ui-stable/cfgs/on_error.stderr @@ -0,0 +1,27 @@ +error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable + --> tests/ui-stable/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ + | + = 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 `bool: FromBytes` is not satisfied + --> tests/ui-stable/cfgs/on_error.rs:13:10 + | +13 | #[derive(FromBytes)] + | ^^^^^^^^^ the trait `FromBytes` is not implemented for `bool` + | + = note: Consider adding `#[derive(FromBytes)]` to `bool` + = help: the following other types implement trait `FromBytes`: + () + (A, B) + (A, B, C) + (A, B, C, D) + (A, B, C, D, E) + (A, B, C, D, E, F) + (A, B, C, D, E, F, G) + (A, B, C, D, E, F, G, H) + and $N others + = help: see issue #48214 + = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.rs b/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.rs new file mode 120000 index 0000000000..c06e751c94 --- /dev/null +++ b/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.rs @@ -0,0 +1 @@ +../../ui-nightly/cfgs/union_into_bytes_cfg.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.stderr b/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.stderr new file mode 100644 index 0000000000..072ff13204 --- /dev/null +++ b/zerocopy-derive/tests/ui-stable/cfgs/union_into_bytes_cfg.stderr @@ -0,0 +1,8 @@ +error: requires --cfg zerocopy_derive_union_into_bytes; + please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 + --> tests/ui-stable/cfgs/union_into_bytes_cfg.rs:20:10 + | +20 | #[derive(IntoBytes)] + | ^^^^^^^^^ + | + = 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 b49ca51e0f..9341292756 100644 --- a/zerocopy-derive/tests/ui-stable/union.stderr +++ b/zerocopy-derive/tests/ui-stable/union.stderr @@ -62,20 +62,6 @@ error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute | = note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info) -warning: unexpected `cfg` condition name: `zerocopy_derive_union_into_bytes` - --> tests/ui-stable/union.rs:42:10 - | -42 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = help: expected names are: `docsrs`, `feature`, and `test` and 31 more - = note: using a cfg inside a derive macro will use the cfgs from the destination crate and not the ones from the defining crate - = help: try referring to `IntoBytes` crate for guidance on how handle this unexpected cfg - = help: the derive macro `IntoBytes` may come from an old version of the `zerocopy_derive` crate, try updating your dependency with `cargo update -p zerocopy_derive` - = note: see for more information about checking conditional configuration - = note: `#[warn(unexpected_cfgs)]` on by default - = note: this warning originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied --> tests/ui-stable/union.rs:25:10 | diff --git a/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs b/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs deleted file mode 120000 index 66ef0de5be..0000000000 --- a/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs +++ /dev/null @@ -1 +0,0 @@ -../../ui-nightly/union_into_bytes_cfg/union_into_bytes_cfg.rs \ No newline at end of file diff --git a/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.stderr b/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.stderr deleted file mode 100644 index 9c038e20c8..0000000000 --- a/zerocopy-derive/tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: requires --cfg zerocopy_derive_union_into_bytes; - please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802 - --> tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 - | -20 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: unexpected `cfg` condition name: `zerocopy_derive_union_into_bytes` - --> tests/ui-stable/union_into_bytes_cfg/union_into_bytes_cfg.rs:20:10 - | -20 | #[derive(IntoBytes)] - | ^^^^^^^^^ - | - = help: expected names are: `docsrs`, `feature`, and `test` and 31 more - = note: using a cfg inside a derive macro will use the cfgs from the destination crate and not the ones from the defining crate - = help: try referring to `IntoBytes` crate for guidance on how handle this unexpected cfg - = help: the derive macro `IntoBytes` may come from an old version of the `zerocopy_derive` crate, try updating your dependency with `cargo update -p zerocopy_derive` - = note: see for more information about checking conditional configuration - = note: `#[warn(unexpected_cfgs)]` on by default - = note: this warning originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)