chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1,131 @@
// Copyright 2024 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
#![deny(deprecated)]
include!("include.rs");
// Make sure no deprecation warnings are generated from our derives (see #553).
#[macro_export]
macro_rules! test {
($name:ident => $ty:item => $($trait:ident),*) => {
#[allow(non_snake_case)]
mod $name {
$(
mod $trait {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::$trait)]
#[zerocopy(crate = "zerocopy_renamed")]
$ty
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!($name: imp::$trait);
}
}
)*
}
};
}
// NOTE: `FromBytes` is tested separately in `enum_from_bytes.rs` since it
// requires 256-variant enums which are extremely verbose; such enums are
// already in that file.
test!(Enum => #[repr(u8)] enum Enum { A, } => TryFromBytes, FromZeros, KnownLayout, Immutable, IntoBytes, Unaligned);
test!(Struct => #[repr(C)] struct Struct; => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
test!(Union => #[repr(C)] union Union{ a: (), } => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
// Tests for ByteHash and ByteEq which require IntoBytes + Immutable
mod enum_hash_eq {
mod ByteHash {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::ByteHash, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum Enum {
A,
}
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(Enum: ::core::hash::Hash);
}
}
mod ByteEq {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::ByteEq, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum Enum {
A,
}
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(Enum: ::core::cmp::PartialEq, ::core::cmp::Eq);
}
}
}
mod struct_hash_eq {
mod ByteHash {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::ByteHash, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct;
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(Struct: ::core::hash::Hash);
}
}
mod ByteEq {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::ByteEq, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct;
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(Struct: ::core::cmp::PartialEq, ::core::cmp::Eq);
}
}
}
// Tests for SplitAt which requires repr(C) and at least one field
mod split_at_test {
mod SplitAt {
use super::super::*;
#[deprecated = "do not use"]
#[derive(imp::SplitAt, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct {
a: [u8],
}
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(Struct: imp::SplitAt);
}
}
}

View File

@@ -0,0 +1,108 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum Foo {
A,
}
util_assert_impl_all!(Foo: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum Bar {
A = 0,
}
util_assert_impl_all!(Bar: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum TwoVariantsHasExplicitZero {
A = 1,
B = 0,
}
util_assert_impl_all!(TwoVariantsHasExplicitZero: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8)]
enum ImplicitNonFirstVariantIsZero {
A = -1,
B,
}
util_assert_impl_all!(ImplicitNonFirstVariantIsZero: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
enum LargeDiscriminant {
A = 0xFFFF_FFFF_FFFF_FFFF,
B = 0x0000_0000_0000_0000,
}
util_assert_impl_all!(LargeDiscriminant: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum FirstVariantIsZeroable {
A(u32),
B { foo: u32 },
}
util_assert_impl_all!(FirstVariantIsZeroable: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FirstVariantIsZeroableSecondIsNot {
A(bool),
B(::core::num::NonZeroU8),
}
util_assert_impl_all!(FirstVariantIsZeroableSecondIsNot: imp::FromZeros);
// MSRV does not support data-carrying enum variants with explicit discriminants
#[cfg(not(__ZEROCOPY_TOOLCHAIN = "msrv"))]
mod msrv_only {
use super::*;
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum ImplicitFirstVariantIsZeroable {
A(bool),
B(::core::num::NonZeroU8) = 1,
}
util_assert_impl_all!(ImplicitFirstVariantIsZeroable: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8)]
enum ImplicitNonFirstVariantIsZeroable {
A(::core::num::NonZeroU8) = 1,
B = -1,
C(bool),
}
util_assert_impl_all!(ImplicitNonFirstVariantIsZeroable: imp::FromZeros);
}

View File

@@ -0,0 +1,54 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Foo {
A,
}
util_assert_impl_all!(Foo: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Bar {
A = 0,
}
util_assert_impl_all!(Bar: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Baz {
A = 1,
B = 0,
}
util_assert_impl_all!(Baz: imp::KnownLayout);
// Deriving `KnownLayout` should work if the enum has bounded parameters.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::KnownLayout,
{
Variant([T; N], imp::PhantomData<&'a &'b ()>),
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);

View File

@@ -0,0 +1,55 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Foo {
A,
}
util_assert_impl_all!(Foo: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Bar {
A = 0,
}
util_assert_impl_all!(Bar: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Baz {
A = 1,
B = 0,
}
util_assert_impl_all!(Baz: imp::Immutable);
// Deriving `Immutable` should work if the enum has bounded parameters.
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::Immutable, const N: ::core::primitive::usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Immutable,
{
Variant([T; N], imp::PhantomData<&'a &'b ()>),
UnsafeCell(imp::PhantomData<imp::UnsafeCell<()>>, &'a imp::UnsafeCell<()>),
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable);

View File

@@ -0,0 +1,156 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// An enum is `IntoBytes` if if has a defined repr.
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum C {
A,
}
util_assert_impl_all!(C: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum U8 {
A,
}
util_assert_impl_all!(U8: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u16)]
enum U16 {
A,
}
util_assert_impl_all!(U16: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum U32 {
A,
}
util_assert_impl_all!(U32: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
enum U64 {
A,
}
util_assert_impl_all!(U64: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(usize)]
enum Usize {
A,
}
util_assert_impl_all!(Usize: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8)]
enum I8 {
A,
}
util_assert_impl_all!(I8: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i16)]
enum I16 {
A,
}
util_assert_impl_all!(I16: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i32)]
enum I32 {
A,
}
util_assert_impl_all!(I32: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i64)]
enum I64 {
A,
}
util_assert_impl_all!(I64: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(isize)]
enum Isize {
A,
}
util_assert_impl_all!(Isize: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum HasData {
A(u8),
B(i8),
}
util_assert_impl_all!(HasData: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum HasData32 {
A(u32),
B(i32),
C([u8; 4]),
D([u16; 2]),
}
util_assert_impl_all!(HasData: imp::IntoBytes);
// After #1752 landed but before #1758 was fixed, this failed to compile because
// the padding check treated the tag type as being `#[repr(u8, align(2))] struct
// Tag { A }`, which is two bytes long, rather than the correct `#[repr(u8)]
// struct Tag { A }`, which is one byte long.
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
enum BadTagWouldHavePadding {
A(u8, u16),
}
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
enum HasAlign {
A(u8),
}
util_assert_impl_all!(HasAlign: imp::IntoBytes);

View File

@@ -0,0 +1,675 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(Eq, PartialEq, Debug, imp::Immutable, imp::KnownLayout, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum Foo {
A,
}
util_assert_impl_all!(Foo: imp::TryFromBytes);
#[test]
fn test_foo() {
imp::assert_eq!(<Foo as imp::TryFromBytes>::try_read_from_bytes(&[0]), imp::Ok(Foo::A));
imp::assert!(<Foo as imp::TryFromBytes>::try_read_from_bytes(&[]).is_err());
imp::assert!(<Foo as imp::TryFromBytes>::try_read_from_bytes(&[1]).is_err());
imp::assert!(<Foo as imp::TryFromBytes>::try_read_from_bytes(&[0, 0]).is_err());
}
#[derive(Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u16)]
enum Bar {
A = 0,
}
util_assert_impl_all!(Bar: imp::TryFromBytes);
#[test]
fn test_bar() {
imp::assert_eq!(<Bar as imp::TryFromBytes>::try_read_from_bytes(&[0, 0]), imp::Ok(Bar::A));
imp::assert!(<Bar as imp::TryFromBytes>::try_read_from_bytes(&[]).is_err());
imp::assert!(<Bar as imp::TryFromBytes>::try_read_from_bytes(&[0]).is_err());
imp::assert!(<Bar as imp::TryFromBytes>::try_read_from_bytes(&[0, 1]).is_err());
imp::assert!(<Bar as imp::TryFromBytes>::try_read_from_bytes(&[0, 0, 0]).is_err());
}
#[derive(Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum Baz {
A = 1,
B = 0,
}
util_assert_impl_all!(Baz: imp::TryFromBytes);
#[test]
fn test_baz() {
imp::assert_eq!(
<Baz as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&1u32)),
imp::Ok(Baz::A)
);
imp::assert_eq!(
<Baz as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&0u32)),
imp::Ok(Baz::B)
);
imp::assert!(<Baz as imp::TryFromBytes>::try_read_from_bytes(&[]).is_err());
imp::assert!(<Baz as imp::TryFromBytes>::try_read_from_bytes(&[0]).is_err());
imp::assert!(<Baz as imp::TryFromBytes>::try_read_from_bytes(&[0, 0]).is_err());
imp::assert!(<Baz as imp::TryFromBytes>::try_read_from_bytes(&[0, 0, 0]).is_err());
imp::assert!(<Baz as imp::TryFromBytes>::try_read_from_bytes(&[0, 0, 0, 0, 0]).is_err());
}
// Test hygiene - make sure that `i8` being shadowed doesn't cause problems for
// the code emitted by the derive.
type i8 = bool;
const THREE: ::core::primitive::i8 = 3;
#[derive(Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8)]
enum Blah {
A = 1,
B = 0,
C = 1 + 2,
D = 3 + THREE,
}
util_assert_impl_all!(Blah: imp::TryFromBytes);
#[test]
fn test_blah() {
imp::assert_eq!(
<Blah as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&1i8)),
imp::Ok(Blah::A)
);
imp::assert_eq!(
<Blah as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&0i8)),
imp::Ok(Blah::B)
);
imp::assert_eq!(
<Blah as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&3i8)),
imp::Ok(Blah::C)
);
imp::assert_eq!(
<Blah as imp::TryFromBytes>::try_read_from_bytes(imp::IntoBytes::as_bytes(&6i8)),
imp::Ok(Blah::D)
);
imp::assert!(<Blah as imp::TryFromBytes>::try_read_from_bytes(&[]).is_err());
imp::assert!(<Blah as imp::TryFromBytes>::try_read_from_bytes(&[4]).is_err());
imp::assert!(<Blah as imp::TryFromBytes>::try_read_from_bytes(&[0, 0]).is_err());
}
#[derive(
Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes, imp::IntoBytes,
)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum FieldlessButNotUnitOnly {
A,
B(),
C {},
}
#[test]
fn test_fieldless_but_not_unit_only() {
const SIZE: usize = ::core::mem::size_of::<FieldlessButNotUnitOnly>();
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(FieldlessButNotUnitOnly::A);
imp::assert_eq!(
<FieldlessButNotUnitOnly as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(FieldlessButNotUnitOnly::A)
);
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(FieldlessButNotUnitOnly::B());
imp::assert_eq!(
<FieldlessButNotUnitOnly as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(FieldlessButNotUnitOnly::B())
);
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(FieldlessButNotUnitOnly::C {});
imp::assert_eq!(
<FieldlessButNotUnitOnly as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(FieldlessButNotUnitOnly::C {})
);
imp::assert!(<FieldlessButNotUnitOnly as imp::TryFromBytes>::try_read_from_bytes(
&[0xFF; SIZE][..]
)
.is_err());
}
#[derive(
Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes, imp::IntoBytes,
)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum WeirdDiscriminants {
A = -7,
B,
C = 33,
}
#[test]
fn test_weird_discriminants() {
const SIZE: usize = ::core::mem::size_of::<WeirdDiscriminants>();
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(WeirdDiscriminants::A);
imp::assert_eq!(
<WeirdDiscriminants as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(WeirdDiscriminants::A)
);
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(WeirdDiscriminants::B);
imp::assert_eq!(
<WeirdDiscriminants as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(WeirdDiscriminants::B)
);
let disc: [u8; SIZE] = ::zerocopy_renamed::transmute!(WeirdDiscriminants::C);
imp::assert_eq!(
<WeirdDiscriminants as imp::TryFromBytes>::try_read_from_bytes(&disc[..]),
imp::Ok(WeirdDiscriminants::C)
);
imp::assert!(
<WeirdDiscriminants as imp::TryFromBytes>::try_read_from_bytes(&[0xFF; SIZE][..]).is_err()
);
}
// Technically non-portable since this is only `IntoBytes` if the discriminant
// is an `i32` or `u32`, but we'll cross that bridge when we get to it...
#[derive(
Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes, imp::IntoBytes,
)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum HasFields {
A(u32),
B { foo: ::core::num::NonZeroU32 },
}
#[test]
fn test_has_fields() {
const SIZE: usize = ::core::mem::size_of::<HasFields>();
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(HasFields::A(10));
imp::assert_eq!(
<HasFields as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFields::A(10)),
);
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(HasFields::B {
foo: ::core::num::NonZeroU32::new(123456).unwrap()
});
imp::assert_eq!(
<HasFields as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFields::B { foo: ::core::num::NonZeroU32::new(123456).unwrap() }),
);
}
#[derive(Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(16))]
enum HasFieldsAligned {
A(u32),
B { foo: ::core::num::NonZeroU32 },
}
util_assert_impl_all!(HasFieldsAligned: imp::TryFromBytes);
#[test]
fn test_has_fields_aligned() {
const SIZE: usize = ::core::mem::size_of::<HasFieldsAligned>();
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct BytesOfHasFieldsAligned {
has_fields: HasFields,
padding: [u8; 8],
}
let wrap = |has_fields| BytesOfHasFieldsAligned { has_fields, padding: [0; 8] };
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(wrap(HasFields::A(10)));
imp::assert_eq!(
<HasFieldsAligned as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsAligned::A(10)),
);
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(wrap(HasFields::B {
foo: ::core::num::NonZeroU32::new(123456).unwrap()
}));
imp::assert_eq!(
<HasFieldsAligned as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsAligned::B { foo: ::core::num::NonZeroU32::new(123456).unwrap() }),
);
}
#[derive(
Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes, imp::IntoBytes,
)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum HasFieldsPrimitive {
A(u32),
B { foo: ::core::num::NonZeroU32 },
}
#[test]
fn test_has_fields_primitive() {
const SIZE: usize = ::core::mem::size_of::<HasFieldsPrimitive>();
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(HasFieldsPrimitive::A(10));
imp::assert_eq!(
<HasFieldsPrimitive as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsPrimitive::A(10)),
);
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(HasFieldsPrimitive::B {
foo: ::core::num::NonZeroU32::new(123456).unwrap(),
});
imp::assert_eq!(
<HasFieldsPrimitive as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsPrimitive::B { foo: ::core::num::NonZeroU32::new(123456).unwrap() }),
);
}
#[derive(Eq, PartialEq, Debug, imp::KnownLayout, imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32, align(16))]
enum HasFieldsPrimitiveAligned {
A(u32),
B { foo: ::core::num::NonZeroU32 },
}
util_assert_impl_all!(HasFieldsPrimitiveAligned: imp::TryFromBytes);
#[test]
fn test_has_fields_primitive_aligned() {
const SIZE: usize = ::core::mem::size_of::<HasFieldsPrimitiveAligned>();
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct BytesOfHasFieldsPrimitiveAligned {
has_fields: HasFieldsPrimitive,
padding: [u8; 8],
}
let wrap = |has_fields| BytesOfHasFieldsPrimitiveAligned { has_fields, padding: [0; 8] };
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(wrap(HasFieldsPrimitive::A(10)));
imp::assert_eq!(
<HasFieldsPrimitiveAligned as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsPrimitiveAligned::A(10)),
);
let bytes: [u8; SIZE] = ::zerocopy_renamed::transmute!(wrap(HasFieldsPrimitive::B {
foo: ::core::num::NonZeroU32::new(123456).unwrap()
}));
imp::assert_eq!(
<HasFieldsPrimitiveAligned as imp::TryFromBytes>::try_read_from_bytes(&bytes[..]),
imp::Ok(HasFieldsPrimitiveAligned::B {
foo: ::core::num::NonZeroU32::new(123456).unwrap()
}),
);
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(4), u32)]
enum HasReprAlignFirst {
A,
B,
}
util_assert_impl_all!(HasReprAlignFirst: imp::TryFromBytes);
#[derive(imp::KnownLayout, imp::TryFromBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum Complex {
UnitLike,
StructLike { a: u8, b: u16 },
TupleLike(bool, char),
}
util_assert_impl_all!(Complex: imp::TryFromBytes);
#[derive(imp::KnownLayout, imp::TryFromBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum ComplexWithGenerics<X, Y> {
UnitLike,
StructLike { a: u8, b: X },
TupleLike(bool, Y),
}
util_assert_impl_all!(ComplexWithGenerics<u16, char>: imp::TryFromBytes);
#[derive(imp::KnownLayout, imp::TryFromBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum GenericWithLifetimes<'a, 'b, X: 'a, Y: 'b> {
Foo(::core::marker::PhantomData<&'a X>),
Bar(::core::marker::PhantomData<&'b Y>),
}
#[derive(Clone, Copy, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct A;
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum B {
A(A),
A2 { a: A },
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FooU8 {
Variant0,
Variant1,
Variant2,
Variant3,
Variant4,
Variant5,
Variant6,
Variant7,
Variant8,
Variant9,
Variant10,
Variant11,
Variant12,
Variant13,
Variant14,
Variant15,
Variant16,
Variant17,
Variant18,
Variant19,
Variant20,
Variant21,
Variant22,
Variant23,
Variant24,
Variant25,
Variant26,
Variant27,
Variant28,
Variant29,
Variant30,
Variant31,
Variant32,
Variant33,
Variant34,
Variant35,
Variant36,
Variant37,
Variant38,
Variant39,
Variant40,
Variant41,
Variant42,
Variant43,
Variant44,
Variant45,
Variant46,
Variant47,
Variant48,
Variant49,
Variant50,
Variant51,
Variant52,
Variant53,
Variant54,
Variant55,
Variant56,
Variant57,
Variant58,
Variant59,
Variant60,
Variant61,
Variant62,
Variant63,
Variant64,
Variant65,
Variant66,
Variant67,
Variant68,
Variant69,
Variant70,
Variant71,
Variant72,
Variant73,
Variant74,
Variant75,
Variant76,
Variant77,
Variant78,
Variant79,
Variant80,
Variant81,
Variant82,
Variant83,
Variant84,
Variant85,
Variant86,
Variant87,
Variant88,
Variant89,
Variant90,
Variant91,
Variant92,
Variant93,
Variant94,
Variant95,
Variant96,
Variant97,
Variant98,
Variant99,
Variant100,
Variant101,
Variant102,
Variant103,
Variant104,
Variant105,
Variant106,
Variant107,
Variant108,
Variant109,
Variant110,
Variant111,
Variant112,
Variant113,
Variant114,
Variant115,
Variant116,
Variant117,
Variant118,
Variant119,
Variant120,
Variant121,
Variant122,
Variant123,
Variant124,
Variant125,
Variant126,
Variant127,
Variant128,
Variant129,
Variant130,
Variant131,
Variant132,
Variant133,
Variant134,
Variant135,
Variant136,
Variant137,
Variant138,
Variant139,
Variant140,
Variant141,
Variant142,
Variant143,
Variant144,
Variant145,
Variant146,
Variant147,
Variant148,
Variant149,
Variant150,
Variant151,
Variant152,
Variant153,
Variant154,
Variant155,
Variant156,
Variant157,
Variant158,
Variant159,
Variant160,
Variant161,
Variant162,
Variant163,
Variant164,
Variant165,
Variant166,
Variant167,
Variant168,
Variant169,
Variant170,
Variant171,
Variant172,
Variant173,
Variant174,
Variant175,
Variant176,
Variant177,
Variant178,
Variant179,
Variant180,
Variant181,
Variant182,
Variant183,
Variant184,
Variant185,
Variant186,
Variant187,
Variant188,
Variant189,
Variant190,
Variant191,
Variant192,
Variant193,
Variant194,
Variant195,
Variant196,
Variant197,
Variant198,
Variant199,
Variant200,
Variant201,
Variant202,
Variant203,
Variant204,
Variant205,
Variant206,
Variant207,
Variant208,
Variant209,
Variant210,
Variant211,
Variant212,
Variant213,
Variant214,
Variant215,
Variant216,
Variant217,
Variant218,
Variant219,
Variant220,
Variant221,
Variant222,
Variant223,
Variant224,
Variant225,
Variant226,
Variant227,
Variant228,
Variant229,
Variant230,
Variant231,
Variant232,
Variant233,
Variant234,
Variant235,
Variant236,
Variant237,
Variant238,
Variant239,
Variant240,
Variant241,
Variant242,
Variant243,
Variant244,
Variant245,
Variant246,
Variant247,
Variant248,
Variant249,
Variant250,
Variant251,
Variant252,
Variant253,
Variant254,
Variant255,
}
#[test]
fn test_trivial_is_bit_valid() {
// Though we don't derive `FromBytes`, `FooU8` *could* soundly implement
// `FromBytes`. Therefore, `TryFromBytes` derive's `is_bit_valid` impl is
// trivial - it unconditionally returns `true`.
util_assert_not_impl_any!(FooU8: imp::FromBytes);
util::test_trivial_is_bit_valid::<FooU8>();
}
#[deny(non_camel_case_types)]
mod issue_2051 {
use super::*;
// Test that the `non_camel_case_types` lint isn't triggered by generated
// code.
// Prevents regressions of #2051.
#[repr(u32)]
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[allow(non_camel_case_types)]
pub enum Code {
I32_ADD,
I32_SUB,
I32_MUL,
}
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum RawIdentifierVariant {
r#type,
}
util_assert_impl_all!(RawIdentifierVariant: imp::TryFromBytes);

View File

@@ -0,0 +1,53 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// An enum is `Unaligned` if:
// - No `repr(align(N > 1))`
// - `repr(u8)` or `repr(i8)`
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum Foo {
A,
}
util_assert_impl_all!(Foo: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8)]
enum Bar {
A,
}
util_assert_impl_all!(Bar: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(1))]
enum Baz {
A,
}
util_assert_impl_all!(Baz: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8, align(1))]
enum Blah {
B,
}
util_assert_impl_all!(Blah: imp::Unaligned);

34
vendor/zerocopy-derive/tests/eq.rs vendored Normal file
View File

@@ -0,0 +1,34 @@
// Copyright 2024 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::Debug, imp::IntoBytes, imp::Immutable, imp::ByteEq)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct {
a: u64,
b: u32,
c: u32,
}
util_assert_impl_all!(Struct: imp::IntoBytes, imp::PartialEq, imp::Eq);
#[test]
fn test_eq() {
use imp::{assert_eq, assert_ne};
let a = Struct { a: 10, b: 15, c: 20 };
let b = Struct { a: 10, b: 15, c: 25 };
assert_eq!(a, a);
assert_ne!(a, b);
assert_ne!(b, a);
}

39
vendor/zerocopy-derive/tests/hash.rs vendored Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2024 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::IntoBytes, imp::Immutable, imp::ByteHash)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct {
a: u64,
b: u32,
c: u32,
}
util_assert_impl_all!(Struct: imp::IntoBytes, imp::hash::Hash);
#[test]
fn test_hash() {
use imp::{
hash::{Hash, Hasher},
DefaultHasher,
};
fn hash(val: impl Hash) -> u64 {
let mut hasher = DefaultHasher::new();
val.hash(&mut hasher);
hasher.finish()
}
hash(Struct { a: 10, b: 15, c: 20 });
hash(&[Struct { a: 10, b: 15, c: 20 }, Struct { a: 5, b: 4, c: 3 }]);
}

60
vendor/zerocopy-derive/tests/hygiene.rs vendored Normal file
View File

@@ -0,0 +1,60 @@
// Copyright 2019 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.
// Make sure that macro hygiene will ensure that when we reference "zerocopy",
// that will work properly even if they've renamed the crate and have not
// imported its traits.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
extern crate zerocopy_renamed as _zerocopy;
#[derive(_zerocopy::KnownLayout, _zerocopy::FromBytes, _zerocopy::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct TypeParams<'a, T, I: imp::Iterator> {
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [::core::primitive::u8]>,
f: imp::PhantomData<&'static ::core::primitive::str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(
TypeParams<'static, (), imp::IntoIter<()>>:
_zerocopy::KnownLayout,
_zerocopy::FromZeros,
_zerocopy::FromBytes,
_zerocopy::Unaligned
);
// Regression test for #2177.
//
// This test ensures that `#[derive(KnownLayout)]` does not trigger the
// `private_bounds` lint when used on a public struct in a macro.
mod issue_2177 {
#![deny(private_bounds)]
// We need to access `_zerocopy` from the parent module.
use super::_zerocopy;
macro_rules! define {
($name:ident, $repr:ty) => {
#[derive(_zerocopy::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct $name($repr);
};
}
define!(Foo, u8);
}

149
vendor/zerocopy-derive/tests/include.rs vendored Normal file
View File

@@ -0,0 +1,149 @@
// Copyright 2019 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.
// ON THE PRELUDE: All of the tests in this directory (excepting UI tests)
// disable the prelude via `#![no_implicit_prelude]`. This ensures that all code
// emitted by our derives doesn't accidentally assume that the prelude is
// included, which helps ensure that items are referred to by absolute path,
// which in turn ensures that these items can't accidentally refer to names
// which have been shadowed. For example, the code `x == None` could behave
// incorrectly if, in the scope in which the derive is invoked, `None` has been
// shadowed by `CONST None: Option<usize> = Some(1)`.
//
// `mod imp` allows us to import items and refer to them in this module without
// introducing the risk that this hides bugs in which derive-emitted code uses
// names which are not fully-qualified. For such a bug to manifest, it would
// need to be of the form `imp::Foo`, which is unlikely to happen by accident.
mod imp {
// Since this file is included in every test file, and since not every test
// file uses every item here, we allow unused imports to avoid generating
// warnings.
#[allow(unused)]
pub use {
::core::{
self, assert_eq, assert_ne,
cell::UnsafeCell,
convert::TryFrom,
hash,
marker::PhantomData,
mem::{ManuallyDrop, MaybeUninit},
option::IntoIter,
prelude::v1::*,
primitive::*,
},
::std::{collections::hash_map::DefaultHasher, prelude::v1::*},
::zerocopy_renamed::*,
};
}
// These items go in their own module (rather than the top level) for the same
// reason that we use `mod imp` above. See its comment for more details.
pub 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(
super::imp::KnownLayout,
super::imp::Immutable,
super::imp::FromBytes,
super::imp::IntoBytes,
Copy,
Clone,
)]
#[zerocopy(crate = "zerocopy_renamed")]
#[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>();
}
};
}
// Under some circumstances, our `TryFromBytes` derive generates a trivial
// `is_bit_valid` impl that unconditionally returns `true`. This test
// attempts to validate that this is, indeed, the behavior of our
// `TryFromBytes` derive. It is not foolproof, but is likely to catch some
// mistakes.
//
// As of this writing, this happens when deriving `TryFromBytes` thanks to a
// top-level `#[derive(FromBytes)]`.
pub fn test_trivial_is_bit_valid<T: super::imp::TryFromBytes>() {
use super::imp::{MaybeUninit, Ptr, ReadOnly};
// This test works based on the insight that a trivial `is_bit_valid`
// impl should never load any bytes from memory. Thus, while it is
// technically a violation of `is_bit_valid`'s safety precondition to
// pass a pointer to uninitialized memory, the `is_bit_valid` impl we
// expect our derives to generate should never touch this memory, and
// thus should never exhibit UB. By contrast, if our derives are
// spuriously generating non-trivial `is_bit_valid` impls, this should
// cause UB which may be caught by Miri.
let mut buf = MaybeUninit::<T>::uninit();
let ptr = Ptr::from_mut(&mut buf);
// SAFETY: This is intentionally unsound; see the preceding comment.
let ptr = unsafe { ptr.assume_initialized() };
let mut ptr = ptr.transmute::<ReadOnly<MaybeUninit<T>>, _, _>();
let ptr = ptr.reborrow_shared();
let ptr = ptr.cast::<_, ::zerocopy_renamed::pointer::cast::CastSized, _>();
assert!(<T as super::imp::TryFromBytes>::is_bit_valid(ptr));
}
pub fn test_is_bit_valid<T: super::imp::TryFromBytes, V: super::imp::IntoBytes>(
val: V,
is_bit_valid: bool,
) {
use super::imp::{
pointer::{cast::CastSized, BecauseImmutable},
ReadOnly,
};
let ro = ReadOnly::new(val);
let candidate = ::zerocopy_renamed::Ptr::from_ref(&ro);
let candidate = candidate.recall_validity();
let candidate = candidate.cast::<ReadOnly<T>, CastSized, (_, BecauseImmutable)>();
super::imp::assert_eq!(T::is_bit_valid(candidate), is_bit_valid);
}
}

View File

@@ -0,0 +1,21 @@
// Copyright 2024 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
#![forbid(unexpected_cfgs)]
include!("include.rs");
// Make sure no unexpected `cfg`s are emitted by our derives (see #2117).
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct Test(pub [u8; 32]);

View File

@@ -0,0 +1,23 @@
// Copyright 2025 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.
use zerocopy_renamed::{IntoBytes, Unalign};
#[allow(unused)]
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Struct {
leading: Unalign<u32>,
trailing: [u8],
}
#[test]
fn test_issue_2835() {
// Compilation is enough to verify the fix
}

View File

@@ -0,0 +1,292 @@
// 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.
#![no_implicit_prelude]
#![deny(non_ascii_idents)]
#![allow(dead_code)]
include!("include.rs");
// FIXME(#2880): Derive `FromBytes` in all types once we support non-ASCII
// idents.
#[derive(imp::KnownLayout, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct TestStruct {
a: u8,
}
#[derive(imp::KnownLayout, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union TestUnion {
a: u8,
}
#[derive(imp::KnownLayout, imp::FromBytes, imp::IntoBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FooU8 {
Variant0,
Variant1,
Variant2,
Variant3,
Variant4,
Variant5,
Variant6,
Variant7,
Variant8,
Variant9,
Variant10,
Variant11,
Variant12,
Variant13,
Variant14,
Variant15,
Variant16,
Variant17,
Variant18,
Variant19,
Variant20,
Variant21,
Variant22,
Variant23,
Variant24,
Variant25,
Variant26,
Variant27,
Variant28,
Variant29,
Variant30,
Variant31,
Variant32,
Variant33,
Variant34,
Variant35,
Variant36,
Variant37,
Variant38,
Variant39,
Variant40,
Variant41,
Variant42,
Variant43,
Variant44,
Variant45,
Variant46,
Variant47,
Variant48,
Variant49,
Variant50,
Variant51,
Variant52,
Variant53,
Variant54,
Variant55,
Variant56,
Variant57,
Variant58,
Variant59,
Variant60,
Variant61,
Variant62,
Variant63,
Variant64,
Variant65,
Variant66,
Variant67,
Variant68,
Variant69,
Variant70,
Variant71,
Variant72,
Variant73,
Variant74,
Variant75,
Variant76,
Variant77,
Variant78,
Variant79,
Variant80,
Variant81,
Variant82,
Variant83,
Variant84,
Variant85,
Variant86,
Variant87,
Variant88,
Variant89,
Variant90,
Variant91,
Variant92,
Variant93,
Variant94,
Variant95,
Variant96,
Variant97,
Variant98,
Variant99,
Variant100,
Variant101,
Variant102,
Variant103,
Variant104,
Variant105,
Variant106,
Variant107,
Variant108,
Variant109,
Variant110,
Variant111,
Variant112,
Variant113,
Variant114,
Variant115,
Variant116,
Variant117,
Variant118,
Variant119,
Variant120,
Variant121,
Variant122,
Variant123,
Variant124,
Variant125,
Variant126,
Variant127,
Variant128,
Variant129,
Variant130,
Variant131,
Variant132,
Variant133,
Variant134,
Variant135,
Variant136,
Variant137,
Variant138,
Variant139,
Variant140,
Variant141,
Variant142,
Variant143,
Variant144,
Variant145,
Variant146,
Variant147,
Variant148,
Variant149,
Variant150,
Variant151,
Variant152,
Variant153,
Variant154,
Variant155,
Variant156,
Variant157,
Variant158,
Variant159,
Variant160,
Variant161,
Variant162,
Variant163,
Variant164,
Variant165,
Variant166,
Variant167,
Variant168,
Variant169,
Variant170,
Variant171,
Variant172,
Variant173,
Variant174,
Variant175,
Variant176,
Variant177,
Variant178,
Variant179,
Variant180,
Variant181,
Variant182,
Variant183,
Variant184,
Variant185,
Variant186,
Variant187,
Variant188,
Variant189,
Variant190,
Variant191,
Variant192,
Variant193,
Variant194,
Variant195,
Variant196,
Variant197,
Variant198,
Variant199,
Variant200,
Variant201,
Variant202,
Variant203,
Variant204,
Variant205,
Variant206,
Variant207,
Variant208,
Variant209,
Variant210,
Variant211,
Variant212,
Variant213,
Variant214,
Variant215,
Variant216,
Variant217,
Variant218,
Variant219,
Variant220,
Variant221,
Variant222,
Variant223,
Variant224,
Variant225,
Variant226,
Variant227,
Variant228,
Variant229,
Variant230,
Variant231,
Variant232,
Variant233,
Variant234,
Variant235,
Variant236,
Variant237,
Variant238,
Variant239,
Variant240,
Variant241,
Variant242,
Variant243,
Variant244,
Variant245,
Variant246,
Variant247,
Variant248,
Variant249,
Variant250,
Variant251,
Variant252,
Variant253,
Variant254,
Variant255,
}

View File

@@ -0,0 +1,78 @@
// 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.
#![no_implicit_prelude]
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
include!("include.rs");
// Original reproducer from #2915
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum MyEnum {
Type,
OtherWithData(u8),
}
// Tests for all other associated types which may be problematic in our codebase
// as of this commit.
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned, imp::Immutable, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct StructCollision {
pub Type: u8,
pub LAYOUT: u8,
pub PointerMetadata: u8,
pub Tag: u8,
pub tag: u8,
pub variants: u8,
}
impl StructCollision {
pub const Type: () = ();
pub const LAYOUT: () = ();
pub const PointerMetadata: () = ();
}
#[derive(imp::FromZeros, imp::Immutable, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub enum EnumCollision {
Type { x: u8 },
LAYOUT { x: u8 },
PointerMetadata { x: u8 },
Tag { x: u8 },
tag { x: u8 },
variants { x: u8 },
}
// Case where generic parameter has associated type colliding with internal usage
pub trait AmbiguousTrait {
type Type;
const LAYOUT: usize;
type PointerMetadata;
}
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned, imp::Immutable, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct GenericCollision<T: AmbiguousTrait> {
pub field: u8,
pub typ: T::Type,
pub pointer_metadata: T::PointerMetadata,
pub _marker: imp::PhantomData<T>,
}
#[test]
fn test_compilation() {
// If the derives compile, we are good.
let _ = StructCollision { Type: 0, LAYOUT: 0, PointerMetadata: 0, Tag: 0, tag: 0, variants: 0 };
let _ = EnumCollision::Type { x: 0 };
}

169
vendor/zerocopy-derive/tests/on_error.rs vendored Normal file
View File

@@ -0,0 +1,169 @@
// 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.
// 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<T: imp::Copy> {
a: T,
}
util_assert_not_impl_any!(BadIntoBytesUnionGeneric<u8>: 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);
}

View File

@@ -0,0 +1,43 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// Ensure that types that are use'd and types that are referenced by path work.
mod foo {
use super::*;
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct Foo {
foo: u8,
}
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct Bar {
bar: u8,
}
}
use foo::Foo;
#[derive(imp::FromBytes, imp::IntoBytes, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Baz {
foo: Foo,
bar: foo::Bar,
}

View File

@@ -0,0 +1,36 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// FIXME(#847): Make this test succeed on earlier Rust versions.
#[::rustversion::stable(1.59)]
mod test {
use super::*;
// These derives do not result in E0446 as of Rust 1.59.0, because of
// https://github.com/rust-lang/rust/pull/90586.
//
// This change eliminates one of the major downsides of emitting `where`
// bounds for field types (i.e., the emission of E0446 for private field
// types).
#[derive(imp::KnownLayout, imp::IntoBytes, imp::FromZeros, imp::FromBytes, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub struct Public(Private);
#[derive(imp::KnownLayout, imp::IntoBytes, imp::FromZeros, imp::FromBytes, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Private(());
}

View File

@@ -0,0 +1,83 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `FromBytes` if:
// - all fields are `FromBytes`
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Zst;
util_assert_impl_all!(Zst: imp::FromBytes);
test_trivial_is_bit_valid!(Zst => test_zst_trivial_is_bit_valid);
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct One {
a: u8,
}
util_assert_impl_all!(One: imp::FromBytes);
test_trivial_is_bit_valid!(One => test_one_trivial_is_bit_valid);
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Two {
a: u8,
b: Zst,
}
util_assert_impl_all!(Two: imp::FromBytes);
test_trivial_is_bit_valid!(Two => test_two_trivial_is_bit_valid);
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Unsized {
a: [u8],
}
util_assert_impl_all!(Unsized: imp::FromBytes);
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct TypeParams<'a, T: ?imp::Sized, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [::core::primitive::u8]>,
d: imp::PhantomData<&'static ::core::primitive::str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::FromBytes);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::FromBytes);
util_assert_impl_all!(TypeParams<'static, [util::AU16], imp::IntoIter<()>>: imp::FromBytes);
test_trivial_is_bit_valid!(TypeParams<'static, (), imp::IntoIter<()>> => test_type_params_trivial_is_bit_valid);
// Deriving `FromBytes` should work if the struct has bounded parameters.
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::FromBytes, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::FromBytes;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::FromBytes);
test_trivial_is_bit_valid!(WithParams<'static, 'static, u8, 42> => test_with_params_trivial_is_bit_valid);

View File

@@ -0,0 +1,78 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `FromZeros` if:
// - all fields are `FromZeros`
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Zst;
util_assert_impl_all!(Zst: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
struct One {
a: bool,
}
util_assert_impl_all!(One: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Unsized {
a: [u8],
}
util_assert_impl_all!(Unsized: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
struct TypeParams<'a, T: ?imp::Sized, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [u8]>,
d: imp::PhantomData<&'static str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::FromZeros);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::FromZeros);
util_assert_impl_all!(TypeParams<'static, [util::AU16], imp::IntoIter<()>>: imp::FromZeros);
// Deriving `FromZeros` should work if the struct has bounded parameters.
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::FromZeros, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::FromZeros;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::FromZeros);

View File

@@ -0,0 +1,131 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
extern crate rustversion;
include!("include.rs");
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Zst;
util_assert_impl_all!(Zst: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct One {
a: bool,
}
util_assert_impl_all!(One: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct TypeParams<'a, T, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [::core::primitive::u8]>,
d: imp::PhantomData<&'static ::core::primitive::str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::KnownLayout);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::KnownLayout);
// Deriving `KnownLayout` should work if the struct has bounded parameters.
//
// N.B. We limit this test to rustc >= 1.62, since earlier versions of rustc ICE
// when `KnownLayout` is derived on a `repr(C)` struct whose trailing field
// contains non-static lifetimes.
#[rustversion::since(1.62)]
const _: () = {
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::KnownLayout;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);
};
const _: () = {
// Similar to the previous test, except that the trailing field contains
// only static lifetimes. This is exercisable on all supported toolchains.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>(
&'a &'b [T; N],
imp::PhantomData<&'static ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::KnownLayout;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);
};
// Deriving `KnownLayout` should work if the struct references `Self`. See
// #2116.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithSelfReference {
leading: [u8; Self::N],
trailing: [[u8; Self::N]],
}
impl WithSelfReference {
const N: usize = 42;
}
util_assert_impl_all!(WithSelfReference: imp::KnownLayout);
// Deriving `KnownLayout` should work with generic `repr(packed)` types. See
// #2302.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct Packet<P> {
payload: P,
}
util_assert_impl_all!(Packet<imp::u8>: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct RawIdentifier {
r#type: u8,
}
util_assert_impl_all!(RawIdentifier: imp::KnownLayout);

View File

@@ -0,0 +1,105 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Zst;
util_assert_impl_all!(Zst: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct One {
a: bool,
}
util_assert_impl_all!(One: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Three {
a: [u8],
}
util_assert_impl_all!(Three: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Four<'a> {
field: &'a imp::UnsafeCell<u8>,
}
util_assert_impl_all!(Four<'static>: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct TypeParams<'a, T, U, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [::core::primitive::u8]>,
d: imp::PhantomData<&'static ::core::primitive::str>,
e: imp::PhantomData<imp::String>,
f: imp::PhantomData<U>,
g: T,
}
util_assert_impl_all!(TypeParams<'static, (), (), imp::IntoIter<()>>: imp::Immutable);
util_assert_impl_all!(TypeParams<'static, util::AU16, util::AU16, imp::IntoIter<()>>: imp::Immutable);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::UnsafeCell<u8>, imp::IntoIter<()>>: imp::Immutable);
util_assert_not_impl_any!(TypeParams<'static, imp::UnsafeCell<()>, (), imp::IntoIter<()>>: imp::Immutable);
util_assert_not_impl_any!(TypeParams<'static, [imp::UnsafeCell<u8>; 0], (), imp::IntoIter<()>>: imp::Immutable);
util_assert_not_impl_any!(TypeParams<'static, (), (), imp::IntoIter<imp::UnsafeCell<()>>>: imp::Immutable);
trait Trait {
type Assoc;
}
impl<T> Trait for imp::UnsafeCell<T> {
type Assoc = T;
}
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct WithAssocType<T: Trait> {
field: <T as Trait>::Assoc,
}
util_assert_impl_all!(WithAssocType<imp::UnsafeCell<u8>>: imp::Immutable);
// Deriving `Immutable` should work if the struct has bounded parameters.
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::Immutable, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
imp::PhantomData<imp::UnsafeCell<()>>,
&'a imp::UnsafeCell<()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Immutable;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable);

View File

@@ -0,0 +1,229 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `IntoBytes` if:
// - all fields are `IntoBytes`
// - `repr(C)` or `repr(transparent)` and
// - no padding (size of struct equals sum of size of field types)
// - `repr(packed)`
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct CZst;
util_assert_impl_all!(CZst: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct C {
a: u8,
b: u8,
c: util::AU16,
}
util_assert_impl_all!(C: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct SyntacticUnsized {
a: u8,
b: u8,
c: [util::AU16],
}
util_assert_impl_all!(C: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct Transparent {
a: u8,
b: (),
}
util_assert_impl_all!(Transparent: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct TransparentGeneric<T: ?imp::Sized> {
a: (),
b: T,
}
util_assert_impl_all!(TransparentGeneric<u64>: imp::IntoBytes);
util_assert_impl_all!(TransparentGeneric<[u64]>: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct CZstPacked;
util_assert_impl_all!(CZstPacked: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct CPacked {
a: u8,
// NOTE: The `u16` type is not guaranteed to have alignment 2, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(2))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u16` here. Luckily, these tests run in CI on
// platforms on which `u16` has alignment 2, so this isn't that big of a
// deal.
b: u16,
}
util_assert_impl_all!(CPacked: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(2))]
// The same caveats as for CPacked apply - we're assuming u64 is at least
// 4-byte aligned by default. Without packed(2), this should fail, as there
// would be padding between a/b assuming u64 is 4+ byte aligned.
struct CPacked2 {
a: u16,
b: u64,
}
util_assert_impl_all!(CPacked2: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct CPackedGeneric<T, U: ?imp::Sized> {
t: T,
// Unsized types stored in `repr(packed)` structs must not be dropped
// because dropping them in-place might be unsound depending on the
// alignment of the outer struct. Sized types can be dropped by first being
// moved to an aligned stack variable, but this isn't possible with unsized
// types.
u: imp::ManuallyDrop<U>,
}
util_assert_impl_all!(CPackedGeneric<u8, util::AU16>: imp::IntoBytes);
util_assert_impl_all!(CPackedGeneric<u8, [util::AU16]>: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed)]
struct PackedGeneric<T, U: ?imp::Sized> {
t: T,
// Unsized types stored in `repr(packed)` structs must not be dropped
// because dropping them in-place might be unsound depending on the
// alignment of the outer struct. Sized types can be dropped by first being
// moved to an aligned stack variable, but this isn't possible with unsized
// types.
u: imp::ManuallyDrop<U>,
}
util_assert_impl_all!(PackedGeneric<u8, util::AU16>: imp::IntoBytes);
util_assert_impl_all!(PackedGeneric<u8, [util::AU16]>: imp::IntoBytes);
// This test is non-portable, but works so long as Rust happens to lay this
// struct out with no padding.
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Unpacked {
a: u8,
b: u8,
}
util_assert_impl_all!(Unpacked: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct ReprCGenericOneField<T: ?imp::Sized> {
t: T,
}
// Even though `ReprCGenericOneField` has generic type arguments, since it only
// has one field, we don't require that its field types implement `Unaligned`.
util_assert_impl_all!(ReprCGenericOneField<util::AU16>: imp::IntoBytes);
util_assert_impl_all!(ReprCGenericOneField<[util::AU16]>: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct ReprCGenericMultipleFields<T, U: ?imp::Sized> {
t: T,
u: U,
}
// Since `ReprCGenericMultipleFields` is generic and has more than one field,
// all field types must implement `Unaligned`.
util_assert_impl_all!(ReprCGenericMultipleFields<u8, [u8; 2]>: imp::IntoBytes);
util_assert_impl_all!(ReprCGenericMultipleFields<u8, [[u8; 2]]>: imp::IntoBytes);
util_assert_not_impl_any!(ReprCGenericMultipleFields<u8, util::AU16>: imp::IntoBytes);
util_assert_not_impl_any!(ReprCGenericMultipleFields<u8, [util::AU16]>: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct Unsized {
a: [u8],
}
util_assert_impl_all!(Unsized: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
struct UnsizedAligned {
a: [[u8; 2]],
}
util_assert_impl_all!(UnsizedAligned: imp::IntoBytes);
// Deriving `IntoBytes` should work if the struct has bounded parameters.
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::IntoBytes, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::IntoBytes;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::IntoBytes);
// Test for the failure reported in #1182.
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
pub struct IndexEntryFlags(u8);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
pub struct IndexEntry<const SIZE_BLOCK_ID: usize> {
block_number: imp::native_endian::U64,
flags: IndexEntryFlags,
block_id: [u8; SIZE_BLOCK_ID],
}
util_assert_impl_all!(IndexEntry<0>: imp::IntoBytes);
util_assert_impl_all!(IndexEntry<1>: imp::IntoBytes);

View File

@@ -0,0 +1,223 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `imp::TryFromBytes` if:
// - all fields are `imp::TryFromBytes`
#[test]
fn zst() {
crate::util::test_is_bit_valid::<(), _>((), true);
}
#[derive(imp::TryFromBytes, imp::Immutable, imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct One {
a: u8,
}
util_assert_impl_all!(One: imp::TryFromBytes);
#[test]
fn one() {
crate::util::test_is_bit_valid::<One, _>(One { a: 42 }, true);
crate::util::test_is_bit_valid::<One, _>(One { a: 43 }, true);
}
#[derive(imp::TryFromBytes, imp::Immutable, imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Two {
a: bool,
b: (),
}
util_assert_impl_all!(Two: imp::TryFromBytes);
#[test]
fn two() {
crate::util::test_is_bit_valid::<Two, _>(Two { a: false, b: () }, true);
crate::util::test_is_bit_valid::<Two, _>(Two { a: true, b: () }, true);
crate::util::test_is_bit_valid::<Two, _>([2u8], false);
}
#[derive(imp::KnownLayout, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Unsized {
a: [u8],
}
util_assert_impl_all!(Unsized: imp::TryFromBytes);
#[test]
fn un_sized() {
// FIXME(#5): Use `try_transmute` in this test once it's available.
let mut buf = [16u8, 12, 42];
let candidate = ::zerocopy_renamed::Ptr::from_mut(&mut buf[..]);
// SAFETY: `&Unsized` consists entirely of initialized bytes.
let candidate = unsafe { candidate.assume_initialized() };
let mut candidate = {
use imp::pointer::{cast::CastUnsized, BecauseExclusive};
candidate.cast::<_, CastUnsized, (_, BecauseExclusive)>()
};
// SAFETY: `candidate`'s referent is as-initialized as `Two`.
let mut candidate = unsafe { candidate.assume_initialized() };
let is_bit_valid = <Unsized as imp::TryFromBytes>::is_bit_valid(candidate.reborrow_shared());
imp::assert!(is_bit_valid);
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct TypeParams<'a, T: ?imp::Sized, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [u8]>,
d: imp::PhantomData<&'static str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::TryFromBytes);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::TryFromBytes);
util_assert_impl_all!(TypeParams<'static, [util::AU16], imp::IntoIter<()>>: imp::TryFromBytes);
// Deriving `imp::TryFromBytes` should work if the struct has bounded
// parameters.
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::TryFromBytes, const N: usize>(
imp::PhantomData<&'a &'b ()>,
[T],
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::TryFromBytes;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::TryFromBytes);
#[derive(imp::FromBytes, imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct MaybeFromBytes<T>(T);
#[test]
fn test_maybe_from_bytes() {
// When deriving `FromBytes` on a type with no generic parameters, we emit a
// trivial `is_bit_valid` impl that always returns true. This test confirms
// that we *don't* spuriously do that when generic parameters are present.
crate::util::test_is_bit_valid::<MaybeFromBytes<bool>, _>(MaybeFromBytes(false), true);
crate::util::test_is_bit_valid::<MaybeFromBytes<bool>, _>(MaybeFromBytes(true), true);
crate::util::test_is_bit_valid::<MaybeFromBytes<bool>, _>([2u8], false);
}
#[derive(Debug, PartialEq, Eq, imp::TryFromBytes, imp::Immutable, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct CPacked {
a: u8,
// NOTE: The `u32` type is not guaranteed to have alignment 4, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(4))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u32` here. Luckily, these tests run in CI on
// platforms on which `u32` has alignment 4, so this isn't that big of a
// deal.
b: u32,
}
#[test]
fn c_packed() {
let candidate = &[42u8, 0xFF, 0xFF, 0xFF, 0xFF];
let converted = <CPacked as imp::TryFromBytes>::try_ref_from_bytes(candidate);
imp::assert_eq!(converted, imp::Ok(&CPacked { a: 42, b: u32::MAX }));
}
#[derive(imp::TryFromBytes, imp::KnownLayout, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct CPackedUnsized {
a: u8,
// NOTE: The `u32` type is not guaranteed to have alignment 4, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(4))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u32` here. Luckily, these tests run in CI on
// platforms on which `u32` has alignment 4, so this isn't that big of a
// deal.
b: [u32],
}
#[test]
fn c_packed_unsized() {
let candidate = &[42u8, 0xFF, 0xFF, 0xFF, 0xFF];
let converted = <CPackedUnsized as imp::TryFromBytes>::try_ref_from_bytes(candidate);
imp::assert!(converted.is_ok());
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed)]
struct PackedUnsized {
a: u8,
// NOTE: The `u32` type is not guaranteed to have alignment 4, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(4))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u32` here. Luckily, these tests run in CI on
// platforms on which `u32` has alignment 4, so this isn't that big of a
// deal.
b: [u32],
}
#[test]
fn packed_unsized() {
let candidate = &[42u8, 0xFF, 0xFF, 0xFF, 0xFF];
let converted = <CPackedUnsized as imp::TryFromBytes>::try_ref_from_bytes(candidate);
imp::assert!(converted.is_ok());
let candidate = &[42u8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
let converted = <CPackedUnsized as imp::TryFromBytes>::try_ref_from_bytes(candidate);
imp::assert!(converted.is_err());
let candidate = &[42u8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
let converted = <CPackedUnsized as imp::TryFromBytes>::try_ref_from_bytes(candidate);
imp::assert!(converted.is_ok());
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct A;
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
struct B {
a: A,
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct RawIdent {
r#type: u8,
}
util_assert_impl_all!(RawIdent: imp::TryFromBytes);

View File

@@ -0,0 +1,103 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `Unaligned` if:
// - `repr(align)` is no more than 1 and either
// - `repr(C)` or `repr(transparent)` and
// - all fields Unaligned
// - `repr(packed)`
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Foo {
a: u8,
}
util_assert_impl_all!(Foo: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct Bar {
a: u8,
}
util_assert_impl_all!(Bar: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed)]
struct Baz {
// NOTE: The `u16` type is not guaranteed to have alignment 2, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(2))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u16` here. Luckily, these tests run in CI on
// platforms on which `u16` has alignment 2, so this isn't that big of a
// deal.
a: u16,
}
util_assert_impl_all!(Baz: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(1))]
struct FooAlign {
a: u8,
}
util_assert_impl_all!(FooAlign: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct Unsized {
a: [u8],
}
util_assert_impl_all!(Unsized: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct TypeParams<'a, T: ?imp::Sized, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [::core::primitive::u8]>,
d: imp::PhantomData<&'static ::core::primitive::str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::Unaligned);
util_assert_impl_all!(TypeParams<'static, ::core::primitive::u8, imp::IntoIter<()>>: imp::Unaligned);
util_assert_impl_all!(TypeParams<'static, [::core::primitive::u8], imp::IntoIter<()>>: imp::Unaligned);
// Deriving `Unaligned` should work if the struct has bounded parameters.
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::Unaligned, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Unaligned;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Unaligned);

27
vendor/zerocopy-derive/tests/ui.rs vendored Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2019 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.
use testutil::UiTestRunner;
#[test]
#[cfg_attr(miri, ignore)]
fn ui() {
// This tests the behavior when `--cfg zerocopy_derive_union_into_bytes` is
// present.
UiTestRunner::new()
.rustc_arg("--cfg=zerocopy_derive_union_into_bytes")
.rustc_arg("--cfg=zerocopy_unstable_derive_on_error")
.rustc_arg("-Wwarnings") // To ensure .stderr files reflect typical user encounter
.run();
// This tests the behavior when various `--cfg` flags are not present.
UiTestRunner::new()
.subdir("cfgs")
.rustc_arg("-Wwarnings") // To ensure .stderr files reflect typical user encounter
.run();
}

View File

@@ -0,0 +1,14 @@
error: use of deprecated struct `OldHeader`: Do not use
--> $DIR/absence_of_deprecated_warning.rs:32:12
|
32 | impl T for OldHeader {}
| ^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/absence_of_deprecated_warning.rs:14:9
|
14 | #![deny(deprecated)]
| ^^^^^^^^^^
error: aborting due to previous error

View File

@@ -0,0 +1,28 @@
error: use of deprecated struct `OldHeader`: Do not use
--> $DIR/absence_of_deprecated_warning.rs:32:12
|
32 | impl T for OldHeader {}
| ^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/absence_of_deprecated_warning.rs:14:9
|
14 | #![deny(deprecated)]
| ^^^^^^^^^^
warning: struct `OldHeader` is never constructed
--> $DIR/absence_of_deprecated_warning.rs:24:8
|
24 | struct OldHeader {
| ^^^^^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: trait `T` is never used
--> $DIR/absence_of_deprecated_warning.rs:29:7
|
29 | trait T {}
| ^
error: aborting due to 1 previous error; 2 warnings emitted

View File

@@ -0,0 +1,35 @@
// Copyright 2024 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.
//! See: https://github.com/google/zerocopy/issues/553
//! zerocopy must still allow derives of deprecated types.
//! This test has a hand-written impl of a deprecated type, and should result in a compilation
//! error. If zerocopy does not tack an allow(deprecated) annotation onto its impls, then this
//! test will fail because more than one compile error will be generated.
#![deny(deprecated)]
extern crate zerocopy_renamed;
use zerocopy_renamed::IntoBytes;
#[deprecated = "Do not use"]
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct OldHeader {
field_a: usize,
collection: [u8; 8],
}
trait T {}
// Intentionally trigger a deprecation error
impl T for OldHeader {}
//~[msrv, stable, nightly]^ ERROR: use of deprecated struct `OldHeader`: Do not use
fn main() {}

View File

@@ -0,0 +1,28 @@
error: use of deprecated struct `OldHeader`: Do not use
--> $DIR/absence_of_deprecated_warning.rs:32:12
|
32 | impl T for OldHeader {}
| ^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/absence_of_deprecated_warning.rs:14:9
|
14 | #![deny(deprecated)]
| ^^^^^^^^^^
warning: struct `OldHeader` is never constructed
--> $DIR/absence_of_deprecated_warning.rs:24:8
|
24 | struct OldHeader {
| ^^^^^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: trait `T` is never used
--> $DIR/absence_of_deprecated_warning.rs:29:7
|
29 | trait T {}
| ^
error: aborting due to 1 previous error; 2 warnings emitted

View File

@@ -0,0 +1,20 @@
error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable
--> $DIR/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
--> $DIR/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)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,35 @@
error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable
--> $DIR/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
--> $DIR/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 79 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)]
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,21 @@
// 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_renamed;
use zerocopy_renamed::FromBytes;
#[derive(FromBytes)]
//~^ ERROR: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable
//~| ERROR: the trait bound `bool: FromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[zerocopy(on_error = "skip")]
#[repr(C)]
struct Foo(bool);
fn main() {}

View File

@@ -0,0 +1,31 @@
error: `on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable
--> $DIR/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
--> $DIR/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 79 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)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,11 @@
error: requires --cfg zerocopy_derive_union_into_bytes;
please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802
--> $DIR/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)
error: aborting due to previous error

View File

@@ -0,0 +1,11 @@
error: requires --cfg zerocopy_derive_union_into_bytes;
please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802
--> $DIR/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)
error: aborting due to 1 previous error

View File

@@ -0,0 +1,28 @@
// Copyright 2024 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.
//! See: https://github.com/google/zerocopy/issues/553
//! zerocopy must still allow derives of deprecated types.
//! This test has a hand-written impl of a deprecated type, and should result in a compilation
//! error. If zerocopy does not tack an allow(deprecated) annotation onto its impls, then this
//! test will fail because more than one compile error will be generated.
#![deny(deprecated)]
extern crate zerocopy_renamed;
use zerocopy_renamed::IntoBytes;
#[derive(IntoBytes)]
//~^ ERROR: requires --cfg zerocopy_derive_union_into_bytes
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union Foo {
a: u8,
}
fn main() {}

View File

@@ -0,0 +1,11 @@
error: requires --cfg zerocopy_derive_union_into_bytes;
please let us know you use this feature: https://github.com/google/zerocopy/discussions/1802
--> $DIR/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)
error: aborting due to 1 previous error

View File

@@ -0,0 +1,93 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/derive_transparent.rs:35:1
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `zerocopy_renamed::TryFromBytes` for `TransparentStruct<NotZerocopy>`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:35:1
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/derive_transparent.rs:38:1
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `FromZeros` for `TransparentStruct<NotZerocopy>`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:38:1
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/derive_transparent.rs:41:1
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `zerocopy_renamed::FromBytes` for `TransparentStruct<NotZerocopy>`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:41:1
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/derive_transparent.rs:44:1
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `zerocopy_renamed::IntoBytes` for `TransparentStruct<NotZerocopy>`
--> $DIR/derive_transparent.rs:24:10
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:44:1
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/derive_transparent.rs:47:1
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy_renamed::Unaligned` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `zerocopy_renamed::Unaligned` for `TransparentStruct<NotZerocopy>`
--> $DIR/derive_transparent.rs:24:32
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:47:1
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `::static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,198 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/derive_transparent.rs:35:23
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 154 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::TryFromBytes`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/../include.rs:74:17
|
74 | ::static_assertions::assert_impl_all!($type: $($trait),+);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
|
::: $DIR/derive_transparent.rs:35:1
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ------------------------------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/derive_transparent.rs:38:23
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 142 others
note: required for `TransparentStruct<NotZerocopy>` to implement `FromZeros`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/../include.rs:74:17
|
74 | ::static_assertions::assert_impl_all!($type: $($trait),+);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
|
::: $DIR/derive_transparent.rs:38:1
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ---------------------------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/derive_transparent.rs:41:23
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::FromBytes`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/../include.rs:74:17
|
74 | ::static_assertions::assert_impl_all!($type: $($trait),+);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
|
::: $DIR/derive_transparent.rs:41:1
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ---------------------------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/derive_transparent.rs:44:23
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::IntoBytes`:
()
AU16
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
and 69 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/derive_transparent.rs:24:10
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/../include.rs:74:17
|
74 | ::static_assertions::assert_impl_all!($type: $($trait),+);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
|
::: $DIR/derive_transparent.rs:44:1
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ---------------------------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `IntoBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/derive_transparent.rs:47:23
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 27 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::Unaligned`
--> $DIR/derive_transparent.rs:24:32
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/../include.rs:74:17
|
74 | ::static_assertions::assert_impl_all!($type: $($trait),+);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
|
::: $DIR/derive_transparent.rs:47:1
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ---------------------------------------------------------------- in this macro invocation
= note: this error originates in the derive macro `Unaligned` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,48 @@
// Copyright 2019 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_renamed;
#[path = "../include.rs"]
mod util;
use core::marker::PhantomData;
use zerocopy_renamed::{FromBytes, FromZeros, IntoBytes, TryFromBytes, Unaligned};
use self::util::util::NotZerocopy;
fn main() {}
// Test generic transparent structs
#[derive(IntoBytes, FromBytes, Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct TransparentStruct<T> {
inner: T,
_phantom: PhantomData<()>,
}
// It should be legal to derive these traits on a transparent struct, but it
// must also ensure the traits are only implemented when the inner type
// implements them.
util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::Unaligned` is not satisfied

View File

@@ -0,0 +1,173 @@
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/derive_transparent.rs:35:23
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 154 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::TryFromBytes`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:35:1
|
35 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/derive_transparent.rs:38:23
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 142 others
note: required for `TransparentStruct<NotZerocopy>` to implement `FromZeros`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:38:1
|
38 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/derive_transparent.rs:41:23
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::FromBytes`
--> $DIR/derive_transparent.rs:24:21
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:41:1
|
41 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `FromBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/derive_transparent.rs:44:23
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::IntoBytes`:
()
AU16
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
and 69 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/derive_transparent.rs:24:10
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:44:1
|
44 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `IntoBytes` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/derive_transparent.rs:47:23
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 27 others
note: required for `TransparentStruct<NotZerocopy>` to implement `zerocopy_renamed::Unaligned`
--> $DIR/derive_transparent.rs:24:32
|
24 | #[derive(IntoBytes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::_::{closure#0}::assert_impl_all`
--> $DIR/derive_transparent.rs:47:1
|
47 | util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `Unaligned` which comes from the expansion of the macro `util_assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,419 @@
error: unrecognized representation hint
--> $DIR/enum.rs:20:8
|
20 | #[repr("foo")]
| ^^^^^
error: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:36:10
|
36 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this conflicts with another representation hint
--> $DIR/enum.rs:46:12
|
46 | #[repr(u8, u16)]
| ^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:53:10
|
53 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:88:1
|
88 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:95:1
|
95 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:117:1
|
117 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:124:1
|
124 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:132:1
|
132 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:140:1
|
140 | / #[zerocopy(crate = "zerocopy_renamed")]
141 | |
142 | | #[repr(u8)]
143 | | enum FromZeros4 {
144 | | A = 1,
145 | | B = 2,
146 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
help: This enum has discriminants which are not literal integers. One of those may define or imply which variant has a discriminant of zero. Use a literal integer to define or imply the variant with a discriminant of zero.
--> $DIR/enum.rs:151:1
|
151 | / #[zerocopy(crate = "zerocopy_renamed")]
152 | |
153 | | #[repr(i8)]
154 | | enum FromZeros5 {
155 | | A = NEGATIVE_ONE,
156 | | B,
157 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:171:1
|
171 | / #[zerocopy(crate = "zerocopy_renamed")]
172 | |
173 | | #[repr(u8)]
174 | | enum FromZeros7 {
... |
177 | | B(NotFromZeros),
178 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:184:10
|
184 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:193:8
|
193 | #[repr(C)]
| ^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:201:8
|
201 | #[repr(usize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:209:8
|
209 | #[repr(isize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:217:8
|
217 | #[repr(u32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:225:8
|
225 | #[repr(i32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:233:8
|
233 | #[repr(u64)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:241:8
|
241 | #[repr(i64)]
| ^^^
error: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:515:10
|
515 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:523:10
|
523 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:531:10
|
531 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:539:10
|
539 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:547:10
|
547 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:555:10
|
555 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:563:10
|
563 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:571:10
|
571 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:579:10
|
579 | #[derive(Unaligned)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:589:12
|
589 | #[repr(u8, align(2))]
| ^^^^^
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:597:12
|
597 | #[repr(i8, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:605:18
|
605 | #[repr(align(1), align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:613:18
|
613 | #[repr(align(2), align(4))]
| ^^^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:657:10
|
657 | #[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 #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:665:10
|
665 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: generic parameters may not be used in const operations
--> $DIR/enum.rs:677:7
|
677 | A(T),
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants
--> $DIR/enum.rs:175:9
|
175 | A = 1,
| ^ disallowed custom discriminant
176 |
177 | B(NotFromZeros),
| --------------- tuple variant defined here
|
= note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
error[E0565]: meta item in `repr` must be an identifier
--> $DIR/enum.rs:20:8
|
20 | #[repr("foo")]
| ^^^^^
error[E0552]: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
error[E0566]: conflicting representation hints
--> $DIR/enum.rs:46:8
|
46 | #[repr(u8, u16)]
| ^^ ^^^
|
= note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
error[E0277]: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
--> $DIR/enum.rs:64:10
|
64 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<()>`
|
= 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 `UnsafeCell<u8>: Immutable` is not satisfied
--> $DIR/enum.rs:75:10
|
75 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<u8>`
|
= 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 `NotTryFromBytes: TryFromBytes` is not satisfied
--> $DIR/enum.rs:104:10
|
104 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotTryFromBytes`
|
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotFromZeros`
|
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotFromZeros: FromZeros` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `FromZeros` is not implemented for `NotFromZeros`
|
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `bool: FromBytes` is not satisfied
--> $DIR/enum.rs:247:10
|
247 | #[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)
error[E0277]: the trait bound `(): PaddingFree<IntoBytes1, 1_usize>` is not satisfied
--> $DIR/enum.rs:623:10
|
623 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `PaddingFree<IntoBytes1, 1_usize>` is not implemented for `()`
|
= help: the following implementations were found:
<() as PaddingFree<T, 0_usize>>
= 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 `(): PaddingFree<IntoBytes2, 3_usize>` is not satisfied
--> $DIR/enum.rs:638:10
|
638 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `PaddingFree<IntoBytes2, 3_usize>` is not implemented for `()`
|
= help: the following implementations were found:
<() as PaddingFree<T, 0_usize>>
= 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 `(): PaddingFree<IntoBytes3, 2_usize>` is not satisfied
--> $DIR/enum.rs:647:10
|
647 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `PaddingFree<IntoBytes3, 2_usize>` is not implemented for `()`
|
= help: the following implementations were found:
<() as PaddingFree<T, 0_usize>>
= 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: generic `Self` types are currently not permitted in anonymous constants
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
= 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 `(): PaddingFree<IntoBytes7, 1_usize>` is not satisfied
--> $DIR/enum.rs:681:10
|
681 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `PaddingFree<IntoBytes7, 1_usize>` is not implemented for `()`
|
= help: the following implementations were found:
<() as PaddingFree<T, 0_usize>>
= 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: aborting due to 52 previous errors
Some errors have detailed explanations: E0277, E0552, E0565, E0566, E0658.
For more information about an error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,601 @@
error: unrecognized representation hint
--> $DIR/enum.rs:20:8
|
20 | #[repr("foo")]
| ^^^^^
error: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:36:10
|
36 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this conflicts with another representation hint
--> $DIR/enum.rs:46:8
|
46 | #[repr(u8, u16)]
| ^^^^^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:53:10
|
53 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:88:1
|
88 | / #[zerocopy(crate = "zerocopy_renamed")]
89 | |
90 | | enum TryFromBytes1 {
91 | | A,
92 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:95:1
|
95 | / #[zerocopy(crate = "zerocopy_renamed")]
96 | |
97 | | enum TryFromBytes2 {
98 | | A,
99 | | B(u8),
100 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:117:1
|
117 | / #[zerocopy(crate = "zerocopy_renamed")]
118 | |
119 | | enum FromZeros1 {
120 | | A(u8),
121 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:124:1
|
124 | / #[zerocopy(crate = "zerocopy_renamed")]
125 | |
126 | | enum FromZeros2 {
127 | | A,
128 | | B(u8),
129 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:132:1
|
132 | / #[zerocopy(crate = "zerocopy_renamed")]
133 | |
134 | | enum FromZeros3 {
135 | | A = 1,
136 | | B,
137 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:140:1
|
140 | / #[zerocopy(crate = "zerocopy_renamed")]
141 | |
142 | | #[repr(u8)]
143 | | enum FromZeros4 {
144 | | A = 1,
145 | | B = 2,
146 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
help: This enum has discriminants which are not literal integers. One of those may define or imply which variant has a discriminant of zero. Use a literal integer to define or imply the variant with a discriminant of zero.
--> $DIR/enum.rs:151:1
|
151 | / #[zerocopy(crate = "zerocopy_renamed")]
152 | |
153 | | #[repr(i8)]
154 | | enum FromZeros5 {
155 | | A = NEGATIVE_ONE,
156 | | B,
157 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:171:1
|
171 | / #[zerocopy(crate = "zerocopy_renamed")]
172 | |
173 | | #[repr(u8)]
174 | | enum FromZeros7 {
... |
177 | | B(NotFromZeros),
178 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:184:10
|
184 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:193:8
|
193 | #[repr(C)]
| ^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:201:8
|
201 | #[repr(usize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:209:8
|
209 | #[repr(isize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:217:8
|
217 | #[repr(u32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:225:8
|
225 | #[repr(i32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:233:8
|
233 | #[repr(u64)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:241:8
|
241 | #[repr(i64)]
| ^^^
error: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:515:10
|
515 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:523:10
|
523 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:531:10
|
531 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:539:10
|
539 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:547:10
|
547 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:555:10
|
555 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:563:10
|
563 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:571:10
|
571 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:579:10
|
579 | #[derive(Unaligned)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:589:12
|
589 | #[repr(u8, align(2))]
| ^^^^^^^^
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:597:12
|
597 | #[repr(i8, align(2))]
| ^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:605:8
|
605 | #[repr(align(1), align(2))]
| ^^^^^^^^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:613:8
|
613 | #[repr(align(2), align(4))]
| ^^^^^^^^^^^^^^^^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:657:10
|
657 | #[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 #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:665:10
|
665 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: generic parameters may not be used in const operations
--> $DIR/enum.rs:677:7
|
677 | A(T),
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
error[E0565]: meta item in `repr` must be an identifier
--> $DIR/enum.rs:20:1
|
20 | #[repr("foo")]
| ^^^^^^^^^^^^^^
error[E0552]: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
|
= help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations>
error[E0566]: conflicting representation hints
--> $DIR/enum.rs:46:8
|
46 | #[repr(u8, u16)]
| ^^ ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default
error[E0277]: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
--> $DIR/enum.rs:64:10
|
64 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 137 others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (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)]
|
error[E0277]: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
--> $DIR/enum.rs:75:10
|
75 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<u8>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 137 others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (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)]
|
error[E0277]: the trait bound `NotTryFromBytes: TryFromBytes` is not satisfied
--> $DIR/enum.rs:104:10
|
104 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `TryFromBytes` is not implemented for `NotTryFromBytes`
--> $DIR/enum.rs:102:1
|
102 | struct NotTryFromBytes;
| ^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotTryFromBytes`
= help: the following other types implement trait `TryFromBytes`:
()
(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 157 others
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (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)]
|
error[E0277]: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `TryFromBytes` is not implemented for `NotFromZeros`
--> $DIR/enum.rs:159:1
|
159 | struct NotFromZeros;
| ^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotFromZeros`
= help: the following other types implement trait `TryFromBytes`:
()
(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 157 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (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)]
|
error[E0277]: the trait bound `NotFromZeros: FromZeros` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotFromZeros`
--> $DIR/enum.rs:159:1
|
159 | struct NotFromZeros;
| ^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotFromZeros`
= help: the following other types implement trait `FromZeros`:
()
(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 142 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (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)]
|
error[E0277]: the trait bound `bool: FromBytes` is not satisfied
--> $DIR/enum.rs:247:10
|
247 | #[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 79 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)]
|
error[E0277]: `IntoBytes1` has 1 total byte(s) of padding
--> $DIR/enum.rs:623:10
|
623 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes1, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes1, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes2` has 3 total byte(s) of padding
--> $DIR/enum.rs:638:10
|
638 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 3>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes3` has 2 total byte(s) of padding
--> $DIR/enum.rs:647:10
|
647 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes3, 2>` is not implemented for `()`
but trait `PaddingFree<IntoBytes3, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error: generic `Self` types are currently not permitted in anonymous constants
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `IntoBytes7` has 1 total byte(s) of padding
--> $DIR/enum.rs:681:10
|
681 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes7, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes7, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: the trait bound `bool: FromBytes` is not satisfied
--> $DIR/enum.rs:247:10
|
247 | #[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 79 others
note: required for `FooU8` to implement `FromBytes`
--> $DIR/enum.rs:247:10
|
247 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_is_from_bytes`
--> $DIR/enum.rs:247:10
|
247 | #[derive(FromBytes)]
| ^^^^^^^^^ required by this bound in `assert_is_from_bytes`
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 52 previous errors
Some errors have detailed explanations: E0277, E0552, E0565, E0566.
For more information about an error, try `rustc --explain E0277`.

688
vendor/zerocopy-derive/tests/ui/enum.rs vendored Normal file
View File

@@ -0,0 +1,688 @@
// Copyright 2019 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.
#[macro_use]
extern crate zerocopy_renamed;
fn main() {}
//
// Generic errors
//
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr("foo")]
//~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
//~[msrv, stable, nightly]^^ ERROR: meta item in `repr` must be an identifier
enum Generic1 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(foo)]
//~[msrv, stable, nightly]^ ERROR: unrecognized representation hint
//~[msrv, stable, nightly]^^ ERROR: unrecognized representation hint
enum Generic2 {
A,
}
#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
enum Generic3 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, u16)]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
//~[msrv, stable, nightly]^^ ERROR: conflicting representation hints
enum Generic4 {
A,
}
#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum Generic5 {
A,
}
//
// Immutable errors
//
#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
enum Immutable1 {
A(core::cell::UnsafeCell<()>),
}
#[derive(Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
enum Never {}
#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<u8>: Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
enum Immutable2 {
Uninhabited(Never, core::cell::UnsafeCell<u8>),
Inhabited(u8),
}
//
// TryFromBytes errors
//
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum TryFromBytes1 {
A,
}
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum TryFromBytes2 {
A,
B(u8),
}
struct NotTryFromBytes;
#[derive(TryFromBytes)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotTryFromBytes: TryFromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum TryFromBytes3 {
A(NotTryFromBytes),
}
//
// FromZeros errors
//
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros1 {
A(u8),
}
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros2 {
A,
B(u8),
}
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
enum FromZeros3 {
A = 1,
B,
}
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(u8)]
enum FromZeros4 {
A = 1,
B = 2,
}
const NEGATIVE_ONE: i8 = -1;
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(i8)]
enum FromZeros5 {
A = NEGATIVE_ONE,
B,
}
struct NotFromZeros;
#[derive(FromZeros)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
//~[msrv, stable, nightly]^^ ERROR: the trait bound `NotFromZeros: FromZeros` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FromZeros6 {
A(NotFromZeros),
}
#[derive(FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromZeros only supported on enums with a variant that has a discriminant of `0`
#[repr(u8)]
enum FromZeros7 {
A = 1,
//~[msrv]^ ERROR: custom discriminant values are not allowed in enums with tuple or struct variants
B(NotFromZeros),
}
//
// FromBytes errors
//
#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum FromBytes1 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes2 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(usize)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes3 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(isize)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes4 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes5 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i32)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes6 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes7 {
A,
}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i64)]
//~[msrv, stable, nightly]^ ERROR: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
enum FromBytes8 {
A,
}
#[derive(FromBytes)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `bool: FromBytes` is not satisfied
//~[stable, nightly]^^ ERROR: the trait bound `bool: FromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum FooU8 {
Variant0,
Variant1,
Variant2,
Variant3,
Variant4,
Variant5,
Variant6,
Variant7,
Variant8,
Variant9,
Variant10,
Variant11,
Variant12,
Variant13,
Variant14,
Variant15,
Variant16,
Variant17,
Variant18,
Variant19,
Variant20,
Variant21,
Variant22,
Variant23,
Variant24,
Variant25,
Variant26,
Variant27,
Variant28,
Variant29,
Variant30,
Variant31,
Variant32,
Variant33,
Variant34,
Variant35,
Variant36,
Variant37,
Variant38,
Variant39,
Variant40,
Variant41,
Variant42,
Variant43,
Variant44,
Variant45,
Variant46,
Variant47,
Variant48,
Variant49,
Variant50,
Variant51,
Variant52,
Variant53,
Variant54,
Variant55,
Variant56,
Variant57,
Variant58,
Variant59,
Variant60,
Variant61,
Variant62,
Variant63,
Variant64,
Variant65,
Variant66,
Variant67,
Variant68,
Variant69,
Variant70,
Variant71,
Variant72,
Variant73,
Variant74,
Variant75,
Variant76,
Variant77,
Variant78,
Variant79,
Variant80,
Variant81,
Variant82,
Variant83,
Variant84,
Variant85,
Variant86,
Variant87,
Variant88,
Variant89,
Variant90,
Variant91,
Variant92,
Variant93,
Variant94,
Variant95,
Variant96,
Variant97,
Variant98,
Variant99,
Variant100,
Variant101,
Variant102,
Variant103,
Variant104,
Variant105,
Variant106,
Variant107,
Variant108,
Variant109,
Variant110,
Variant111,
Variant112,
Variant113,
Variant114,
Variant115,
Variant116,
Variant117,
Variant118,
Variant119,
Variant120,
Variant121,
Variant122,
Variant123,
Variant124,
Variant125,
Variant126,
Variant127,
Variant128,
Variant129,
Variant130,
Variant131,
Variant132,
Variant133,
Variant134,
Variant135,
Variant136,
Variant137,
Variant138,
Variant139,
Variant140,
Variant141,
Variant142,
Variant143,
Variant144,
Variant145,
Variant146,
Variant147,
Variant148,
Variant149,
Variant150,
Variant151,
Variant152,
Variant153,
Variant154,
Variant155,
Variant156,
Variant157,
Variant158,
Variant159,
Variant160,
Variant161,
Variant162,
Variant163,
Variant164,
Variant165,
Variant166,
Variant167,
Variant168,
Variant169,
Variant170,
Variant171,
Variant172,
Variant173,
Variant174,
Variant175,
Variant176,
Variant177,
Variant178,
Variant179,
Variant180,
Variant181,
Variant182,
Variant183,
Variant184,
Variant185,
Variant186,
Variant187,
Variant188,
Variant189,
Variant190,
Variant191,
Variant192,
Variant193,
Variant194,
Variant195,
Variant196,
Variant197,
Variant198,
Variant199,
Variant200,
Variant201,
Variant202,
Variant203,
Variant204,
Variant205,
Variant206,
Variant207,
Variant208,
Variant209,
Variant210,
Variant211,
Variant212,
Variant213,
Variant214,
Variant215,
Variant216,
Variant217,
Variant218,
Variant219,
Variant220,
Variant221,
Variant222,
Variant223,
Variant224,
Variant225,
Variant226,
Variant227,
Variant228,
Variant229,
Variant230,
Variant231,
Variant232,
Variant233,
Variant234,
Variant235,
Variant236,
Variant237,
Variant238,
Variant239,
Variant240,
Variant241,
Variant242,
Variant243,
Variant244,
Variant245,
Variant246,
Variant247,
Variant248,
Variant249,
Variant250,
Variant251,
Variant252,
Variant253,
Variant254,
Variant255(bool),
}
//
// Unaligned errors
//
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
enum Unaligned1 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u16)]
enum Unaligned2 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i16)]
enum Unaligned3 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum Unaligned4 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i32)]
enum Unaligned5 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u64)]
enum Unaligned6 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i64)]
enum Unaligned7 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(usize)]
enum Unaligned8 {
A,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(isize)]
enum Unaligned9 {
A,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
enum Unaligned10 {
A,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(i8, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
enum Unaligned11 {
A,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(1), align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
enum Unaligned12 {
A,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(2), align(4))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
enum Unaligned13 {
A,
}
//
// IntoBytes errors
//
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes1, 1_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes1` has 1 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes1 {
A,
B(u8),
}
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(4))]
struct Align4IntoBytes(u32);
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes2, 3_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes2` has 3 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes2 {
A(Align4IntoBytes),
}
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes3, 2_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes3` has 2 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u32)]
enum IntoBytes3 {
A(u32),
B(u16),
}
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum IntoBytes4 {
A(u32),
B(u16),
}
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
enum IntoBytes5 {
A(u32),
}
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: generic `Self` types are currently not permitted in anonymous constants
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum IntoBytes6<T> {
A(T),
//~[msrv, stable, nightly]^ ERROR: generic parameters may not be used in const operations
}
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes7, 1_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes7` has 1 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8, align(2))]
enum IntoBytes7 {
A,
}

View File

@@ -0,0 +1,549 @@
error: unrecognized representation hint
--> $DIR/enum.rs:20:8
|
20 | #[repr("foo")]
| ^^^^^
error: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:36:10
|
36 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this conflicts with another representation hint
--> $DIR/enum.rs:46:12
|
46 | #[repr(u8, u16)]
| ^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:53:10
|
53 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:88:1
|
88 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:95:1
|
95 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:117:1
|
117 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:124:1
|
124 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:132:1
|
132 | #[zerocopy(crate = "zerocopy_renamed")]
| ^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:140:1
|
140 | / #[zerocopy(crate = "zerocopy_renamed")]
141 | |
142 | | #[repr(u8)]
143 | | enum FromZeros4 {
144 | | A = 1,
145 | | B = 2,
146 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
help: This enum has discriminants which are not literal integers. One of those may define or imply which variant has a discriminant of zero. Use a literal integer to define or imply the variant with a discriminant of zero.
--> $DIR/enum.rs:151:1
|
151 | / #[zerocopy(crate = "zerocopy_renamed")]
152 | |
153 | | #[repr(i8)]
154 | | enum FromZeros5 {
155 | | A = NEGATIVE_ONE,
156 | | B,
157 | | }
| |_^
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> $DIR/enum.rs:171:1
|
171 | / #[zerocopy(crate = "zerocopy_renamed")]
172 | |
173 | | #[repr(u8)]
174 | | enum FromZeros7 {
... |
177 | | B(NotFromZeros),
178 | | }
| |_^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:184:10
|
184 | #[derive(FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:193:8
|
193 | #[repr(C)]
| ^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:201:8
|
201 | #[repr(usize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:209:8
|
209 | #[repr(isize)]
| ^^^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:217:8
|
217 | #[repr(u32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:225:8
|
225 | #[repr(i32)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:233:8
|
233 | #[repr(u64)]
| ^^^
error: `FromBytes` only supported on enums with `#[repr(...)]` attributes `u8`, `i8`, `u16`, or `i16`
--> $DIR/enum.rs:241:8
|
241 | #[repr(i64)]
| ^^^
error: must have #[repr(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:515:10
|
515 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:523:10
|
523 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:531:10
|
531 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:539:10
|
539 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:547:10
|
547 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:555:10
|
555 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:563:10
|
563 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:571:10
|
571 | #[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(u8)] or #[repr(i8)] attribute in order to guarantee this type's alignment
--> $DIR/enum.rs:579:10
|
579 | #[derive(Unaligned)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:589:12
|
589 | #[repr(u8, align(2))]
| ^^^^^
error: cannot derive `Unaligned` on type with alignment greater than 1
--> $DIR/enum.rs:597:12
|
597 | #[repr(i8, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:605:18
|
605 | #[repr(align(1), align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/enum.rs:613:18
|
613 | #[repr(align(2), align(4))]
| ^^^^^
error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:657:10
|
657 | #[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 #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout
--> $DIR/enum.rs:665:10
|
665 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: generic parameters may not be used in const operations
--> $DIR/enum.rs:677:7
|
677 | A(T),
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
error[E0565]: meta item in `repr` must be an identifier
--> $DIR/enum.rs:20:1
|
20 | #[repr("foo")]
| ^^^^^^^^^^^^^^
error[E0552]: unrecognized representation hint
--> $DIR/enum.rs:29:8
|
29 | #[repr(foo)]
| ^^^
|
= help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations>
error[E0566]: conflicting representation hints
--> $DIR/enum.rs:46:8
|
46 | #[repr(u8, u16)]
| ^^ ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default
error[E0277]: the trait bound `UnsafeCell<()>: Immutable` is not satisfied
--> $DIR/enum.rs:64:10
|
64 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 137 others
= 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 `UnsafeCell<u8>: Immutable` is not satisfied
--> $DIR/enum.rs:75:10
|
75 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `Immutable` is not implemented for `UnsafeCell<u8>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 137 others
= 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 `NotTryFromBytes: TryFromBytes` is not satisfied
--> $DIR/enum.rs:104:10
|
104 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `TryFromBytes` is not implemented for `NotTryFromBytes`
--> $DIR/enum.rs:102:1
|
102 | struct NotTryFromBytes;
| ^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotTryFromBytes`
= help: the following other types implement trait `TryFromBytes`:
()
(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 157 others
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotFromZeros: TryFromBytes` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `TryFromBytes` is not implemented for `NotFromZeros`
--> $DIR/enum.rs:159:1
|
159 | struct NotFromZeros;
| ^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotFromZeros`
= help: the following other types implement trait `TryFromBytes`:
()
(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 157 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotFromZeros: FromZeros` is not satisfied
--> $DIR/enum.rs:161:10
|
161 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotFromZeros`
--> $DIR/enum.rs:159:1
|
159 | struct NotFromZeros;
| ^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotFromZeros`
= help: the following other types implement trait `FromZeros`:
()
(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 142 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `bool: FromBytes` is not satisfied
--> $DIR/enum.rs:247:10
|
247 | #[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 79 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)
error[E0277]: `IntoBytes1` has 1 total byte(s) of padding
--> $DIR/enum.rs:623:10
|
623 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes1, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes1, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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]: `IntoBytes2` has 3 total byte(s) of padding
--> $DIR/enum.rs:638:10
|
638 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 3>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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]: `IntoBytes3` has 2 total byte(s) of padding
--> $DIR/enum.rs:647:10
|
647 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes3, 2>` is not implemented for `()`
but trait `PaddingFree<IntoBytes3, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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: generic `Self` types are currently not permitted in anonymous constants
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> $DIR/enum.rs:672:10
|
672 | #[derive(IntoBytes)]
| ^^^^^^^^^
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `IntoBytes7` has 1 total byte(s) of padding
--> $DIR/enum.rs:681:10
|
681 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes7, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes7, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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 `bool: FromBytes` is not satisfied
--> $DIR/enum.rs:247:10
|
247 | #[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 79 others
note: required for `FooU8` to implement `FromBytes`
--> $DIR/enum.rs:247:10
|
247 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_is_from_bytes`
--> $DIR/enum.rs:247:10
|
247 | #[derive(FromBytes)]
| ^^^^^^^^^ required by this bound in `assert_is_from_bytes`
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 52 previous errors
Some errors have detailed explanations: E0277, E0552, E0565, E0566.
For more information about an error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,14 @@
error: FromBytes only supported on repr(u8) enum with 256 variants
--> $DIR/enum_from_bytes_u8_too_few.rs:15:1
|
15 | / #[zerocopy(crate = "zerocopy_renamed")]
16 | |
17 | | #[repr(u8)]
18 | | enum Foo {
... |
273 | | Variant254,
274 | | }
| |_^
error: aborting due to previous error

View File

@@ -0,0 +1,14 @@
error: FromBytes only supported on repr(u8) enum with 256 variants
--> $DIR/enum_from_bytes_u8_too_few.rs:15:1
|
15 | / #[zerocopy(crate = "zerocopy_renamed")]
16 | |
17 | | #[repr(u8)]
18 | | enum Foo {
... |
273 | | Variant254,
274 | | }
| |_^
error: aborting due to 1 previous error

View File

@@ -0,0 +1,274 @@
// Copyright 2019 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.
#[macro_use]
extern crate zerocopy_renamed;
fn main() {}
#[derive(FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
//~[msrv, stable, nightly]^ ERROR: FromBytes only supported on repr(u8) enum with 256 variants
#[repr(u8)]
enum Foo {
Variant0,
Variant1,
Variant2,
Variant3,
Variant4,
Variant5,
Variant6,
Variant7,
Variant8,
Variant9,
Variant10,
Variant11,
Variant12,
Variant13,
Variant14,
Variant15,
Variant16,
Variant17,
Variant18,
Variant19,
Variant20,
Variant21,
Variant22,
Variant23,
Variant24,
Variant25,
Variant26,
Variant27,
Variant28,
Variant29,
Variant30,
Variant31,
Variant32,
Variant33,
Variant34,
Variant35,
Variant36,
Variant37,
Variant38,
Variant39,
Variant40,
Variant41,
Variant42,
Variant43,
Variant44,
Variant45,
Variant46,
Variant47,
Variant48,
Variant49,
Variant50,
Variant51,
Variant52,
Variant53,
Variant54,
Variant55,
Variant56,
Variant57,
Variant58,
Variant59,
Variant60,
Variant61,
Variant62,
Variant63,
Variant64,
Variant65,
Variant66,
Variant67,
Variant68,
Variant69,
Variant70,
Variant71,
Variant72,
Variant73,
Variant74,
Variant75,
Variant76,
Variant77,
Variant78,
Variant79,
Variant80,
Variant81,
Variant82,
Variant83,
Variant84,
Variant85,
Variant86,
Variant87,
Variant88,
Variant89,
Variant90,
Variant91,
Variant92,
Variant93,
Variant94,
Variant95,
Variant96,
Variant97,
Variant98,
Variant99,
Variant100,
Variant101,
Variant102,
Variant103,
Variant104,
Variant105,
Variant106,
Variant107,
Variant108,
Variant109,
Variant110,
Variant111,
Variant112,
Variant113,
Variant114,
Variant115,
Variant116,
Variant117,
Variant118,
Variant119,
Variant120,
Variant121,
Variant122,
Variant123,
Variant124,
Variant125,
Variant126,
Variant127,
Variant128,
Variant129,
Variant130,
Variant131,
Variant132,
Variant133,
Variant134,
Variant135,
Variant136,
Variant137,
Variant138,
Variant139,
Variant140,
Variant141,
Variant142,
Variant143,
Variant144,
Variant145,
Variant146,
Variant147,
Variant148,
Variant149,
Variant150,
Variant151,
Variant152,
Variant153,
Variant154,
Variant155,
Variant156,
Variant157,
Variant158,
Variant159,
Variant160,
Variant161,
Variant162,
Variant163,
Variant164,
Variant165,
Variant166,
Variant167,
Variant168,
Variant169,
Variant170,
Variant171,
Variant172,
Variant173,
Variant174,
Variant175,
Variant176,
Variant177,
Variant178,
Variant179,
Variant180,
Variant181,
Variant182,
Variant183,
Variant184,
Variant185,
Variant186,
Variant187,
Variant188,
Variant189,
Variant190,
Variant191,
Variant192,
Variant193,
Variant194,
Variant195,
Variant196,
Variant197,
Variant198,
Variant199,
Variant200,
Variant201,
Variant202,
Variant203,
Variant204,
Variant205,
Variant206,
Variant207,
Variant208,
Variant209,
Variant210,
Variant211,
Variant212,
Variant213,
Variant214,
Variant215,
Variant216,
Variant217,
Variant218,
Variant219,
Variant220,
Variant221,
Variant222,
Variant223,
Variant224,
Variant225,
Variant226,
Variant227,
Variant228,
Variant229,
Variant230,
Variant231,
Variant232,
Variant233,
Variant234,
Variant235,
Variant236,
Variant237,
Variant238,
Variant239,
Variant240,
Variant241,
Variant242,
Variant243,
Variant244,
Variant245,
Variant246,
Variant247,
Variant248,
Variant249,
Variant250,
Variant251,
Variant252,
Variant253,
Variant254,
}

View File

@@ -0,0 +1,14 @@
error: FromBytes only supported on repr(u8) enum with 256 variants
--> $DIR/enum_from_bytes_u8_too_few.rs:15:1
|
15 | / #[zerocopy(crate = "zerocopy_renamed")]
16 | |
17 | | #[repr(u8)]
18 | | enum Foo {
... |
273 | | Variant254,
274 | | }
| |_^
error: aborting due to 1 previous error

View File

@@ -0,0 +1,101 @@
warning: unused import: `zerocopy_renamed::KnownLayout`
--> $DIR/late_compile_pass.rs:15:5
|
15 | use zerocopy_renamed::KnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:29:10
|
29 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
|
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
|
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy`
|
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
|
= 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 `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ the trait `FromZeros` is not implemented for `NotZerocopy`
|
= 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 `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
|
= 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 `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/late_compile_pass.rs:70:10
|
70 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
|
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:83:10
|
83 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
|
= help: see issue #48214
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:93:10
|
93 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
|
= help: see issue #48214
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:102:10
|
102 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
|
= help: see issue #48214
= note: this error originates in the derive macro `Unaligned` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 10 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,335 @@
warning: unused import: `zerocopy_renamed::KnownLayout`
--> $DIR/late_compile_pass.rs:15:5
|
15 | use zerocopy_renamed::KnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:29:10
|
29 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 others
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (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)]
|
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (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)]
|
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 143 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (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)]
|
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 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)]
|
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 143 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)]
|
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 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)]
|
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/late_compile_pass.rs:70:10
|
70 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::IntoBytes`:
()
AU16
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
and 69 others
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:83:10
|
83 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= note: this error originates in the derive macro `Unaligned` (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)]
|
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:93:10
|
93 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= note: this error originates in the derive macro `Unaligned` (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)]
|
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:102:10
|
102 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= note: this error originates in the derive macro `Unaligned` (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)]
|
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 others
note: required for `FromBytes1` to implement `zerocopy_renamed::FromBytes`
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::_::<impl zerocopy_renamed::TryFromBytes for FromBytes1>::is_bit_valid::assert_is_from_bytes`
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ required by this bound in `assert_is_from_bytes`
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 11 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,108 @@
// Copyright 2019 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.
#[macro_use]
extern crate zerocopy_renamed;
#[path = "../include.rs"]
mod util;
use zerocopy_renamed::KnownLayout;
use self::util::util::{NotZerocopy, AU16};
fn main() {}
// These tests cause errors which are generated by a later compilation pass than
// the other errors we generate, and so if they're compiled in the same file,
// the compiler will never get to that pass, and so we won't get the errors.
//
// TryFromBytes errors
//
#[derive(TryFromBytes)]
//~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
//~[stable, nightly]^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
struct TryFromBytes1 {
value: NotZerocopy,
}
//
// FromZeros errors
//
#[derive(FromZeros)]
//~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
//~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
//~[stable, nightly]^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
struct FromZeros1 {
value: NotZerocopy,
}
//
// FromBytes errors
//
#[derive(FromBytes)]
//~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
//~[msrv, stable, nightly]^^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
//~[msrv]^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
//~[stable, nightly]^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
//~[stable, nightly]^^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
//~[stable, nightly]^^^^^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
struct FromBytes1 {
value: NotZerocopy,
}
//
// IntoBytes errors
//
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
//~[stable, nightly]^^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes1 {
value: NotZerocopy,
}
//
// Unaligned errors
//
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Unaligned1 {
aligned: AU16,
}
// This specifically tests a bug we had in an old version of the code in which
// the trait bound would only be enforced for the first field's type.
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Unaligned2 {
unaligned: u8,
aligned: AU16,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent)]
struct Unaligned3 {
aligned: AU16,
}

View File

@@ -0,0 +1,295 @@
warning: unused import: `zerocopy_renamed::KnownLayout`
--> $DIR/late_compile_pass.rs:15:5
|
15 | use zerocopy_renamed::KnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:29:10
|
29 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 others
= help: see issue #48214
= note: this error originates in the derive macro `TryFromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:41:10
|
41 | #[derive(FromZeros)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 143 others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::TryFromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::TryFromBytes`:
()
(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 156 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)
error[E0277]: the trait bound `NotZerocopy: FromZeros` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `FromZeros` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromZeros)]` to `NotZerocopy`
= help: the following other types implement trait `FromZeros`:
()
(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 143 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)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 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)
error[E0277]: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
--> $DIR/late_compile_pass.rs:70:10
|
70 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::IntoBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(IntoBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::IntoBytes`:
()
AU16
AtomicBool
AtomicI16
AtomicI32
AtomicI64
AtomicI8
AtomicIsize
and 69 others
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:83:10
|
83 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:93:10
|
93 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= 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 `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/late_compile_pass.rs:102:10
|
102 | #[derive(Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 29 others
= help: see issue #48214
= 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 `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::FromBytes` is not implemented for `NotZerocopy`
--> $DIR/../include.rs:48:5
|
48 | pub struct NotZerocopy<T = ()>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(FromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `zerocopy_renamed::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 80 others
note: required for `FromBytes1` to implement `zerocopy_renamed::FromBytes`
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::_::<impl zerocopy_renamed::TryFromBytes for FromBytes1>::is_bit_valid::assert_is_from_bytes`
--> $DIR/late_compile_pass.rs:54:10
|
54 | #[derive(FromBytes)]
| ^^^^^^^^^ required by this bound in `assert_is_from_bytes`
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 11 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,101 @@
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:67:26
|
67 | fn test_kl13<T>(t: T) -> impl KnownLayout {
| ^^^^^^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `T`
|
note: required because of the requirements on the impl of `KnownLayout` for `KL13<T>`
--> $DIR/mid_compile_pass.rs:62:10
|
62 | #[derive(KnownLayout)]
| ^^^^^^^^^^^
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|
67 | fn test_kl13<T: zerocopy_renamed::KnownLayout>(t: T) -> impl KnownLayout {
| +++++++++++++++++++++++++++++++
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:32:15
|
31 | fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
| - this type parameter needs to be `std::marker::Sized`
32 | assert_kl(kl);
| ^^ doesn't have a size known at compile-time
|
note: required because it appears within the type `KL04<T>`
--> $DIR/mid_compile_pass.rs:29:8
|
29 | struct KL04<T: ?Sized>(u8, T);
| ^^^^
note: required because of the requirements on the impl of `KnownLayout` for `KL04<T>`
--> $DIR/mid_compile_pass.rs:27:10
|
27 | #[derive(KnownLayout)]
| ^^^^^^^^^^^
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
31 - fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
31 + fn test_kl04<T>(kl: &KL04<T>) {
|
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:43:15
|
42 | fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
| - this type parameter needs to be `std::marker::Sized`
43 | assert_kl(kl);
| ^^ doesn't have a size known at compile-time
|
note: required because it appears within the type `KL06<T>`
--> $DIR/mid_compile_pass.rs:40:8
|
40 | struct KL06<T: ?Sized + KnownLayout>(u8, T);
| ^^^^
note: required because of the requirements on the impl of `KnownLayout` for `KL06<T>`
--> $DIR/mid_compile_pass.rs:38:10
|
38 | #[derive(KnownLayout)]
| ^^^^^^^^^^^
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
42 - fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
42 + fn test_kl06<T: KnownLayout>(kl: &KL06<T>) {
|
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:55:15
|
55 | assert_kl(kl)
| ^^
| |
| expected an implementor of trait `KnownLayout`
| help: consider borrowing here: `&kl`
|
note: required because of the requirements on the impl of `KnownLayout` for `KL12<T>`
--> $DIR/mid_compile_pass.rs:49:10
|
49 | #[derive(KnownLayout)]
| ^^^^^^^^^^^
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,114 @@
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:67:26
|
67 | fn test_kl13<T>(t: T) -> impl KnownLayout {
| ^^^^^^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `T`
68 |
69 | KL13(0u8, t)
| ------------ return type was inferred to be `KL13<T>` here
|
= note: Consider adding `#[derive(KnownLayout)]` to `T`
note: required for `KL13<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:62:10
|
62 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T` with trait `KnownLayout`
|
67 | fn test_kl13<T: zerocopy_renamed::KnownLayout>(t: T) -> impl KnownLayout {
| +++++++++++++++++++++++++++++++
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:32:15
|
31 | fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
| - this type parameter needs to be `Sized`
32 | assert_kl(kl);
| --------- ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
note: required because it appears within the type `KL04<T>`
--> $DIR/mid_compile_pass.rs:29:8
|
29 | struct KL04<T: ?Sized>(u8, T);
| ^^^^
note: required for `KL04<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:27:10
|
27 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
31 - fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
31 + fn test_kl04<T>(kl: &KL04<T>) {
|
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:43:15
|
42 | fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
| - this type parameter needs to be `Sized`
43 | assert_kl(kl);
| --------- ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
note: required because it appears within the type `KL06<T>`
--> $DIR/mid_compile_pass.rs:40:8
|
40 | struct KL06<T: ?Sized + KnownLayout>(u8, T);
| ^^^^
note: required for `KL06<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:38:10
|
38 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
42 - fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
42 + fn test_kl06<T: KnownLayout>(kl: &KL06<T>) {
|
error[E0277]: the trait bound `KL12<T>: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:55:15
|
55 | assert_kl(kl)
| --------- ^^ the trait `KnownLayout` is not implemented for `KL12<T>`
| |
| required by a bound introduced by this call
|
note: required for `KL12<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:49:10
|
49 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
|
55 | assert_kl(&kl)
| +
55 | assert_kl(&mut kl)
| ++++
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,70 @@
// Copyright 2023 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_renamed;
use zerocopy_renamed::KnownLayout;
fn main() {}
// These tests cause errors which are generated by a later compilation pass than
// the other errors we generate, and so if they're compiled in the same file,
// the compiler will never get to that pass, and so we won't get the errors.
//
// KnownLayout errors
//
fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| N | Y | N | N | KL04 |
#[derive(KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct KL04<T: ?Sized>(u8, T);
fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
assert_kl(kl);
//~[msrv, stable, nightly]^ ERROR: the size for values of type `T` cannot be known at compilation time
}
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| N | Y | Y | N | KL06 |
#[derive(KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct KL06<T: ?Sized + KnownLayout>(u8, T);
fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
assert_kl(kl);
//~[msrv, stable, nightly]^ ERROR: the size for values of type `T` cannot be known at compilation time
}
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| Y | Y | N | N | KL12 |
#[derive(KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct KL12<T: ?Sized>(u8, T);
fn test_kl12<T: ?Sized>(kl: &KL12<T>) {
assert_kl(kl)
//~[msrv]^ ERROR: the trait bound `T: KnownLayout` is not satisfied
//~[stable, nightly]^^ ERROR: the trait bound `KL12<T>: KnownLayout` is not satisfied
}
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| Y | Y | N | Y | KL13 |
#[derive(KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct KL13<T>(u8, T);
fn test_kl13<T>(t: T) -> impl KnownLayout {
//~[msrv, stable, nightly]^ ERROR: the trait bound `T: KnownLayout` is not satisfied
KL13(0u8, t)
}

View File

@@ -0,0 +1,114 @@
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:67:26
|
67 | fn test_kl13<T>(t: T) -> impl KnownLayout {
| ^^^^^^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `T`
68 |
69 | KL13(0u8, t)
| ------------ return type was inferred to be `KL13<T>` here
|
= note: Consider adding `#[derive(KnownLayout)]` to `T`
note: required for `KL13<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:62:10
|
62 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T` with trait `KnownLayout`
|
67 | fn test_kl13<T: zerocopy_renamed::KnownLayout>(t: T) -> impl KnownLayout {
| +++++++++++++++++++++++++++++++
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:32:15
|
31 | fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
| - this type parameter needs to be `Sized`
32 | assert_kl(kl);
| --------- ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
note: required because it appears within the type `KL04<T>`
--> $DIR/mid_compile_pass.rs:29:8
|
29 | struct KL04<T: ?Sized>(u8, T);
| ^^^^
note: required for `KL04<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:27:10
|
27 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
31 - fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
31 + fn test_kl04<T>(kl: &KL04<T>) {
|
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/mid_compile_pass.rs:43:15
|
42 | fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
| - this type parameter needs to be `Sized`
43 | assert_kl(kl);
| --------- ^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
note: required because it appears within the type `KL06<T>`
--> $DIR/mid_compile_pass.rs:40:8
|
40 | struct KL06<T: ?Sized + KnownLayout>(u8, T);
| ^^^^
note: required for `KL06<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:38:10
|
38 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
42 - fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
42 + fn test_kl06<T: KnownLayout>(kl: &KL06<T>) {
|
error[E0277]: the trait bound `KL12<T>: KnownLayout` is not satisfied
--> $DIR/mid_compile_pass.rs:55:15
|
55 | assert_kl(kl)
| --------- ^^ the trait `KnownLayout` is not implemented for `KL12<T>`
| |
| required by a bound introduced by this call
|
note: required for `KL12<T>` to implement `KnownLayout`
--> $DIR/mid_compile_pass.rs:49:10
|
49 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> $DIR/mid_compile_pass.rs:23:26
|
23 | fn assert_kl<T: ?Sized + KnownLayout>(_: &T) {}
| ^^^^^^^^^^^ required by this bound in `assert_kl`
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
|
55 | assert_kl(&kl)
| +
55 | assert_kl(&mut kl)
| ++++
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,29 @@
warning: unused `#[macro_use]` import
--> $DIR/msrv_specific.rs:12:1
|
12 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/msrv_specific.rs:37:9
|
37 | is_into_bytes_1::<IntoBytes1<AU16>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
|
note: required because of the requirements on the impl of `zerocopy_renamed::IntoBytes` for `IntoBytes1<AU16>`
--> $DIR/msrv_specific.rs:25:10
|
25 | #[derive(IntoBytes)]
| ^^^^^^^^^
note: required by a bound in `is_into_bytes_1`
--> $DIR/msrv_specific.rs:35:23
|
35 | fn is_into_bytes_1<T: IntoBytes>() {
| ^^^^^^^^^ 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)
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,45 @@
warning: unused `#[macro_use]` import
--> $DIR/msrv_specific.rs:12:1
|
12 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/msrv_specific.rs:37:27
|
37 | is_into_bytes_1::<IntoBytes1<AU16>>();
| ^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
note: required for `IntoBytes1<AU16>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/msrv_specific.rs:25:10
|
25 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `is_into_bytes_1`
--> $DIR/msrv_specific.rs:35:23
|
35 | fn is_into_bytes_1<T: IntoBytes>() {
| ^^^^^^^^^ 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)
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,40 @@
// Copyright 2024 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.
// 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_renamed;
#[path = "../include.rs"]
mod util;
use zerocopy_renamed::IntoBytes;
use self::util::util::AU16;
fn main() {}
// `repr(C, packed(2))` is not equivalent to `repr(C, packed)`.
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(2))]
struct IntoBytes1<T> {
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<T: IntoBytes>() {
if false {
is_into_bytes_1::<IntoBytes1<AU16>>();
//~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
}
}

View File

@@ -0,0 +1,45 @@
warning: unused `#[macro_use]` import
--> $DIR/msrv_specific.rs:12:1
|
12 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/msrv_specific.rs:37:27
|
37 | is_into_bytes_1::<IntoBytes1<AU16>>();
| ^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
note: required for `IntoBytes1<AU16>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/msrv_specific.rs:25:10
|
25 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `is_into_bytes_1`
--> $DIR/msrv_specific.rs:35:23
|
35 | fn is_into_bytes_1<T: IntoBytes>() {
| ^^^^^^^^^ 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)
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,147 @@
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:105:9
|
105 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:112:9
|
112 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:121:9
|
121 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:128:9
|
128 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:135:52
|
135 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type =
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:138:52
|
138 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type =
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:145:51
|
145 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(0) }>>::Type =
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:148:51
|
148 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(1) }>>::Type =
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:152:51
|
152 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type =
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:31:13
|
31 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:37:13
|
37 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:50:13
|
50 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:56:13
|
56 | _,
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:70:56
|
70 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type = 0u8;
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:72:56
|
72 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type = 0u16;
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:85:55
|
85 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(0) }>>::Type = 0u8;
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:87:55
|
87 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(1) }>>::Type = 0u16;
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0747]: type provided when a constant was expected
--> $DIR/privacy.rs:90:55
|
90 | let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type = 0u8;
| ^
|
= help: const arguments cannot yet be inferred with `_`
error: aborting due to 18 previous errors
For more information about this error, try `rustc --explain E0747`.

View File

@@ -0,0 +1,32 @@
warning: variants `A` and `B` are never constructed
--> $DIR/privacy.rs:80:9
|
79 | pub enum Enum {
| ---- variants in this enum
80 | A(u8, u16),
| ^
81 | B { a: u8, b: u16 },
| ^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
error: type `private::_::_::_::ẕb` is private
--> $DIR/privacy.rs:110:9
|
110 | _,
| ^ private type
error: type `private::_::_::_::ẕ1` is private
--> $DIR/privacy.rs:126:9
|
126 | _,
| ^ private type
error: type `private::_::_::_::ẕb` is private
--> $DIR/privacy.rs:138:49
|
138 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type =
| ^ private type
error: aborting due to 3 previous errors; 1 warning emitted

View File

@@ -0,0 +1,160 @@
// Copyright 2025 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.
#![allow(unused_braces)]
#[macro_use]
extern crate zerocopy_renamed;
fn main() {}
// These tests cause errors which are generated by a later compilation pass than
// the other errors we generate, and so if they're compiled in the same file,
// the compiler will never get to that pass, and so we won't get the errors.
mod private {
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
pub struct StructWithNamedFields {
pub a: u8,
pub(self) b: u16,
}
const _: () = {
let _: <StructWithNamedFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(a) },
>>::Type = 0u8;
let _: <StructWithNamedFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(b) },
>>::Type = 0u16;
};
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
pub struct StructWithAnonFields(pub u8, pub(self) u16);
const _: () = {
let _: <StructWithAnonFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(0) },
>>::Type = 0u8;
let _: <StructWithAnonFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(1) },
>>::Type = 0u16;
};
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
pub struct Union {
pub a: u8,
pub(self) b: u16,
}
const _: () = {
let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type = 0u8;
//~[msrv]^ ERROR: type provided when a constant was expected
let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type = 0u16;
//~[msrv]^ ERROR: type provided when a constant was expected
};
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
pub enum Enum {
A(u8, u16),
B { a: u8, b: u16 },
}
const _: () = {
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(0) }>>::Type = 0u8;
//~[msrv]^ ERROR: type provided when a constant was expected
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(1) }>>::Type = 0u16;
//~[msrv]^ ERROR: type provided when a constant was expected
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type = 0u8;
//~[msrv]^ ERROR: type provided when a constant was expected
let _: <Enum as zerocopy_renamed::HasField<
_,
{ zerocopy_renamed::ident_id!(B) },
{ zerocopy_renamed::ident_id!(b) },
>>::Type = 0u16;
};
}
use private::*;
const _: () = {
let _: <StructWithNamedFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(a) },
>>::Type = 0u8;
let _: <StructWithNamedFields as zerocopy_renamed::HasField<
_,
//~[stable, nightly]^ ERROR: type `private::_::_::_::ẕb` is private
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(b) },
>>::Type = 0u16;
};
const _: () = {
let _: <StructWithAnonFields as zerocopy_renamed::HasField<
_,
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(0) },
>>::Type = 0u8;
let _: <StructWithAnonFields as zerocopy_renamed::HasField<
_,
//~[stable, nightly]^ ERROR: type `private::_::_::_::ẕ1` is private
_,
//~[msrv]^ ERROR: type provided when a constant was expected
{ zerocopy_renamed::ident_id!(1) },
>>::Type = 0u16;
};
const _: () = {
let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type =
//~[msrv]^ ERROR: type provided when a constant was expected
0u8;
let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type =
//~[msrv]^ ERROR: type provided when a constant was expected
//~[stable, nightly]^^ ERROR: type `private::_::_::_::ẕb` is private
0u16;
};
const _: () = {
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(0) }>>::Type =
//~[msrv]^ ERROR: type provided when a constant was expected
0u8;
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(1) }>>::Type =
//~[msrv]^ ERROR: type provided when a constant was expected
0u16;
let _: <Enum as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(a) }>>::Type =
//~[msrv]^ ERROR: type provided when a constant was expected
0u8;
let _: <Enum as zerocopy_renamed::HasField<
_,
{ zerocopy_renamed::ident_id!(B) },
{ zerocopy_renamed::ident_id!(b) },
>>::Type = 0u16;
};

View File

@@ -0,0 +1,32 @@
warning: variants `A` and `B` are never constructed
--> $DIR/privacy.rs:80:9
|
79 | pub enum Enum {
| ---- variants in this enum
80 | A(u8, u16),
| ^
81 | B { a: u8, b: u16 },
| ^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
error: type `private::_::_::_::ẕb` is private
--> $DIR/privacy.rs:110:9
|
110 | _,
| ^ private type
error: type `private::_::_::_::ẕ1` is private
--> $DIR/privacy.rs:126:9
|
126 | _,
| ^ private type
error: type `private::_::_::_::ẕb` is private
--> $DIR/privacy.rs:138:49
|
138 | let _: <Union as zerocopy_renamed::HasField<_, _, { zerocopy_renamed::ident_id!(b) }>>::Type =
| ^ private type
error: aborting due to 3 previous errors; 1 warning emitted

View File

@@ -0,0 +1,87 @@
error: this conflicts with another representation hint
--> $DIR/struct.rs:210:11
|
210 | #[repr(C, C)] /$RUSTUP_TOOLCHAIN/lib/rustlib/src/rust/library/core/src/mem/mod.rs:303:22
|
303 | pub const fn size_of<T>() -> usize {
| ^ required by this bound in `std::mem::size_of`
error[E0277]: the trait bound `(): DynamicPaddingFree<IntoBytes5, true>` is not satisfied
--> $DIR/struct.rs:172:10
|
172 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `DynamicPaddingFree<IntoBytes5, true>` is not implemented for `()`
|
= help: the following implementations were found:
<() as DynamicPaddingFree<T, false>>
= 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 `(): DynamicPaddingFree<IntoBytes6, true>` is not satisfied
--> $DIR/struct.rs:184:10
|
184 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `DynamicPaddingFree<IntoBytes6, true>` is not implemented for `()`
|
= help: the following implementations were found:
<() as DynamicPaddingFree<T, false>>
= 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 `(): DynamicPaddingFree<IntoBytes7, true>` is not satisfied
--> $DIR/struct.rs:197:10
|
197 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `DynamicPaddingFree<IntoBytes7, true>` is not implemented for `()`
|
= help: the following implementations were found:
<() as DynamicPaddingFree<T, false>>
= 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 `(): DynamicPaddingFree<IntoBytes13, true>` is not satisfied
--> $DIR/struct.rs:260:10
|
260 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `DynamicPaddingFree<IntoBytes13, true>` is not implemented for `()`
|
= help: the following implementations were found:
<() as DynamicPaddingFree<T, false>>
= 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 `SplitAtNotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:328:10
|
328 | #[derive(SplitAt)]
| ^^^^^^^ the trait `zerocopy_renamed::KnownLayout` is not implemented for `SplitAtNotKnownLayout`
|
note: required by a bound in `SplitAt`
--> $WORKSPACE/src/split_at.rs:61:27
|
61 | pub unsafe trait SplitAt: KnownLayout<PointerMetadata = usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SplitAt`
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `u8: SplitAt` is not satisfied
--> $DIR/struct.rs:334:10
|
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ the trait `SplitAt` is not implemented for `u8`
|
= help: see issue #48214
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0271]: type mismatch resolving `<u8 as zerocopy_renamed::KnownLayout>::PointerMetadata == usize`
--> $DIR/struct.rs:334:10
|
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ expected `()`, found `usize`
|
= help: see issue #48214
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 31 previous errors
Some errors have detailed explanations: E0271, E0277, E0692.
For more information about an error, try `rustc --explain E0271`.

View File

@@ -0,0 +1,554 @@
error: this conflicts with another representation hint
--> $DIR/struct.rs:210:8
|
210 | #[repr(C, C)] // zerocopy-derive conservatively treats these as conflicting reprs
| ^^^^
error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
--> $DIR/struct.rs:216:10
|
216 | #[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 in order to guarantee this type's memory layout
--> $DIR/struct.rs:223:10
|
223 | #[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 in order to guarantee this type's memory layout
--> $DIR/struct.rs:250:10
|
250 | #[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
--> $DIR/struct.rs:273:11
|
273 | #[repr(C, align(2))]
| ^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:279:8
|
279 | #[repr(transparent, align(2))]
| ^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:288:8
|
288 | #[repr(packed, align(2))]
| ^^^^^^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:295:8
|
295 | #[repr(align(1), align(2))]
| ^^^^^^^^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:301:8
|
301 | #[repr(align(2), align(4))]
| ^^^^^^^^^^^^^^^^^^
error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
--> $DIR/struct.rs:305:10
|
305 | #[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
--> $DIR/struct.rs:310:10
|
310 | #[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
--> $DIR/struct.rs:320:19
|
320 | #[repr(packed(2), C)]
| ___________________^
321 | |
322 | | #[derive(Unaligned)]
323 | | #[zerocopy(crate = "zerocopy_renamed")]
324 | | #[repr(C, packed(2))]
| |________^
error[E0692]: transparent struct cannot have other repr hints
--> $DIR/struct.rs:279:8
|
279 | #[repr(transparent, align(2))]
| ^^^^^^^^^^^ ^^^^^^^^
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:31:10
|
31 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `KL00`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `KL00`
--> $DIR/struct.rs:34:8
|
34 | struct KL00(u8, NotKnownLayoutDst);
| ^^^^
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (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)]
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:38:10
|
38 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `KL02`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `KL02`
--> $DIR/struct.rs:41:8
|
41 | struct KL02(u8, [u8]);
| ^^^^
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (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)]
|
error[E0277]: the trait bound `NotKnownLayoutDst: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:45:10
|
45 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `NotKnownLayoutDst`
--> $DIR/struct.rs:27:1
|
27 | struct NotKnownLayoutDst([u8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `NotKnownLayoutDst`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (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)]
|
error[E0277]: the trait bound `NotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:53:10
|
53 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `NotKnownLayout`
--> $DIR/struct.rs:25:1
|
25 | struct NotKnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `NotKnownLayout`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (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)]
|
error[E0277]: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied
--> $DIR/struct.rs:63:10
|
63 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 130 others
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (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)]
|
error[E0277]: the trait bound `UnsafeCell<u8>: zerocopy_renamed::Immutable` is not satisfied
--> $DIR/struct.rs:70:10
|
70 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<u8>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 130 others
= note: required for `[UnsafeCell<u8>; 0]` to implement `zerocopy_renamed::Immutable`
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (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)]
|
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:84:1
|
84 | struct TryFromBytesPacked {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:92:1
|
92 | struct TryFromBytesPackedN {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:100:1
|
100 | struct TryFromBytesCPacked {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:108:1
|
108 | struct TryFromBytesCPackedN {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/struct.rs:120:10
|
120 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes2` has 1 total byte(s) of padding
--> $DIR/struct.rs:129:10
|
129 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes3` has 1 total byte(s) of padding
--> $DIR/struct.rs:139:10
|
139 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes3, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes3, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:158:10
|
158 | #[derive(IntoBytes)]
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `IntoBytes4`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `IntoBytes4`
--> $DIR/struct.rs:163:8
|
163 | struct IntoBytes4 {
| ^^^^^^^^^^
= note: required for `IntoBytes4` to implement `zerocopy_renamed::util::macro_util::__size_of::Sized`
note: required by a bound in `zerocopy_renamed::util::macro_util::__size_of::size_of`
--> src/util/macro_util.rs:306:4
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `[u8]` is unsized
--> $DIR/struct.rs:165:8
|
165 | b: SliceU8,
| ^^^^^^^ `IntoBytes` needs all field types to be `Sized` in order to determine whether there is padding
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: consider using `#[repr(packed)]` to remove padding
= note: `IntoBytes` does not require the fields of `#[repr(packed)]` types to be `Sized`
= note: required for `[u8]` to implement `zerocopy_renamed::util::macro_util::__size_of::Sized`
note: required by a bound in `zerocopy_renamed::util::macro_util::__size_of::size_of`
--> src/util/macro_util.rs:306:4
error[E0277]: `IntoBytes5` has one or more padding bytes
--> $DIR/struct.rs:172:10
|
172 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes5, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes5, false>` is implemented for it
--> src/util/macro_util.rs:80:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes6` has one or more padding bytes
--> $DIR/struct.rs:184:10
|
184 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes6, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes6, false>` is implemented for it
--> src/util/macro_util.rs:80:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes7` has one or more padding bytes
--> $DIR/struct.rs:197:10
|
197 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes7, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes7, false>` is implemented for it
--> src/util/macro_util.rs:80:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0277]: `IntoBytes13` has one or more padding bytes
--> $DIR/struct.rs:260:10
|
260 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes13, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes13, false>` is implemented for it
--> src/util/macro_util.rs:80:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0587]: type has conflicting packed and align representation hints
--> $DIR/struct.rs:290:1
|
290 | struct Unaligned3;
| ^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `SplitAtNotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:328:10
|
328 | #[derive(SplitAt)]
| ^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `SplitAtNotKnownLayout`
--> $DIR/struct.rs:332:1
|
332 | struct SplitAtNotKnownLayout([u8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `SplitAtNotKnownLayout`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
note: required by a bound in `SplitAt`
--> src/split_at.rs:61:0
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `u8: SplitAt` is not satisfied
--> $DIR/struct.rs:334:10
|
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ the trait `SplitAt` is not implemented for `u8`
|
= note: Consider adding `#[derive(SplitAt)]` to `u8`
help: the following other types implement trait `SplitAt`
--> $DIR/struct.rs:328:10
|
328 | #[derive(SplitAt)]
| ^^^^^^^ `SplitAtNotKnownLayout`
...
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ `SplitAtSized`
--> src/split_at.rs:251:0
|
= note: `[T]`
= help: see issue #48214
= note: this error originates in the derive macro `SplitAt` (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)]
|
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/struct.rs:244:28
|
244 | is_into_bytes_11::<IntoBytes11<AU16>>();
| ^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
note: required for `IntoBytes11<AU16>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/struct.rs:232:10
|
232 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `is_into_bytes_11`
--> $DIR/struct.rs:242:24
|
242 | fn is_into_bytes_11<T: IntoBytes>() {
| ^^^^^^^^^ 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)
error: aborting due to 36 previous errors
Some errors have detailed explanations: E0277, E0587, E0588, E0692.
For more information about an error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,339 @@
// Copyright 2019 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.
#[macro_use]
extern crate zerocopy_renamed;
#[path = "../include.rs"]
mod util;
use zerocopy_renamed::{IntoBytes, KnownLayout};
use self::util::util::AU16;
fn main() {}
//
// KnownLayout errors
//
struct NotKnownLayout;
struct NotKnownLayoutDst([u8]);
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| N | N | N | N | KL00 |
#[derive(KnownLayout)]
//~[msrv, stable, nightly]^ ERROR: the size for values of type `[u8]` cannot be known at compilation time
#[zerocopy(crate = "zerocopy_renamed")]
struct KL00(u8, NotKnownLayoutDst);
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| N | N | Y | N | KL02 |
#[derive(KnownLayout)]
//~[msrv, stable, nightly]^ ERROR: the size for values of type `[u8]` cannot be known at compilation time
#[zerocopy(crate = "zerocopy_renamed")]
struct KL02(u8, [u8]);
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| Y | N | N | N | KL08 |
#[derive(KnownLayout)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotKnownLayoutDst: zerocopy_renamed::KnownLayout` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct KL08(u8, NotKnownLayoutDst);
// -| `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// -| Y | N | N | Y | KL09 |
#[derive(KnownLayout)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `NotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct KL09(NotKnownLayout, NotKnownLayout);
//
// Immutable errors
//
#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
struct Immutable1 {
a: core::cell::UnsafeCell<()>,
}
#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<u8>: zerocopy_renamed::Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
struct Immutable2 {
a: [core::cell::UnsafeCell<u8>; 0],
}
//
// TryFromBytes errors
//
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed)]
struct TryFromBytesPacked {
//~[stable, nightly]^ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
foo: AU16,
}
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed(1))]
struct TryFromBytesPackedN {
//~[stable, nightly]^ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
foo: AU16,
}
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct TryFromBytesCPacked {
//~[stable, nightly]^ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
foo: AU16,
}
#[derive(TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(1))]
struct TryFromBytesCPackedN {
//~[stable, nightly]^ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
foo: AU16,
}
//
// IntoBytes errors
//
// Since `IntoBytes1` has at least one generic parameter, an `IntoBytes` impl is
// emitted in which each field type is given an `Unaligned` bound. Since `foo`'s
// type doesn't implement `Unaligned`, this should fail.
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes1<T> {
foo: AU16,
bar: T,
}
#[derive(IntoBytes)]
//~[stable, nightly]^ ERROR: `IntoBytes2` has 1 total byte(s) of padding
//~[msrv]^^ ERROR: the trait bound `(): PaddingFree<IntoBytes2, 1_usize>` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes2 {
foo: u8,
bar: AU16,
}
#[derive(IntoBytes)]
//~[stable, nightly]^ ERROR: `IntoBytes3` has 1 total byte(s) of padding
//~[msrv]^^ ERROR: the trait bound `(): PaddingFree<IntoBytes3, 1_usize>` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(2))]
struct IntoBytes3 {
foo: u8,
// We'd prefer to use AU64 here, but you can't use aligned types in
// packed structs.
bar: u64,
}
type SliceU8 = [u8];
// Padding between `u8` and `SliceU8`. `SliceU8` doesn't syntactically look like
// a slice, so this case is handled by our `Sized` support.
//
// NOTE(#1708): This exists to ensure that our error messages are good when a
// field is unsized.
#[derive(IntoBytes)]
//~[stable, nightly]^ ERROR: the size for values of type `[u8]` cannot be known at compilation time
//~[msrv]^^ ERROR: the size for values of type `[u8]` cannot be known at compilation time
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes4 {
a: u8,
b: SliceU8,
//~[stable, nightly]^ ERROR: `[u8]` is unsized
//~[msrv]^^ ERROR: the size for values of type `[u8]` cannot be known at compilation time
}
// Padding between `u8` and `[u16]`. `[u16]` is syntactically identifiable as a
// slice, so this case is handled by our `repr(C)` slice DST support.
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): DynamicPaddingFree<IntoBytes5, true>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes5` has one or more padding bytes
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes5 {
a: u8,
b: [u16],
}
// Trailing padding after `[u8]`. `[u8]` is syntactically identifiable as a
// slice, so this case is handled by our `repr(C)` slice DST support.
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): DynamicPaddingFree<IntoBytes6, true>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes6` has one or more padding bytes
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes6 {
a: u16,
b: [u8],
}
// Padding between `u8` and `u16` and also trailing padding after `[u8]`. `[u8]`
// is syntactically identifiable as a slice, so this case is handled by our
// `repr(C)` slice DST support.
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): DynamicPaddingFree<IntoBytes7, true>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes7` has one or more padding bytes
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct IntoBytes7 {
a: u8,
b: u16,
c: [u8],
}
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, C)] // zerocopy-derive conservatively treats these as conflicting reprs
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct IntoBytes8 {
a: u8,
}
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
struct IntoBytes9<T> {
t: T,
}
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed(2))]
struct IntoBytes10<T> {
t: T,
}
// `repr(C, packed(2))` is not equivalent to `repr(C, packed)`.
#[derive(IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(2))]
struct IntoBytes11<T> {
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<T: IntoBytes>() {
if false {
is_into_bytes_11::<IntoBytes11<AU16>>();
//~[stable, nightly]^ ERROR: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
}
}
// `repr(C, align(2))` is not sufficient to guarantee the layout of this type.
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
struct IntoBytes12<T> {
t: T,
}
// NOTE(#3063): This exists to ensure that our analysis for structs with
// syntactic DSTs accounts for `align(N)`.
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): DynamicPaddingFree<IntoBytes13, true>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes13` has one or more padding bytes
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
struct IntoBytes13([u8]);
//
// Unaligned errors
//
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
struct Unaligned1;
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(transparent, align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
//~[msrv, stable, nightly]^^ ERROR: transparent struct cannot have other repr hints
struct Unaligned2 {
foo: u8,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed, align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct Unaligned3;
//~[stable, nightly]^ ERROR: type has conflicting packed and align representation hints
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(1), align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct Unaligned4;
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(2), align(4))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct Unaligned5;
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
struct Unaligned6;
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed(2))]
struct Unaligned7;
// Test the error message emitted when conflicting reprs appear on different
// lines. On the nightly compiler, this emits a "joint span" that spans both
// problematic repr token trees and everything in between.
#[derive(Copy, Clone)]
#[repr(packed(2), C)]
//~[nightly]^ ERROR: this conflicts with another representation hint
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed(2))]
//~[msrv, stable]^ ERROR: this conflicts with another representation hint
struct WeirdReprSpan;
#[derive(SplitAt)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `SplitAtNotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct SplitAtNotKnownLayout([u8]);
#[derive(SplitAt, KnownLayout)]
//~[msrv]^ ERROR: type mismatch resolving `<u8 as zerocopy_renamed::KnownLayout>::PointerMetadata == usize`
//~[msrv, stable, nightly]^^ ERROR: the trait bound `u8: SplitAt` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct SplitAtSized(u8);

View File

@@ -0,0 +1,522 @@
error: this conflicts with another representation hint
--> $DIR/struct.rs:210:11
|
210 | #[repr(C, C)] // zerocopy-derive conservatively treats these as conflicting reprs
| ^
error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
--> $DIR/struct.rs:216:10
|
216 | #[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 in order to guarantee this type's memory layout
--> $DIR/struct.rs:223:10
|
223 | #[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 in order to guarantee this type's memory layout
--> $DIR/struct.rs:250:10
|
250 | #[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
--> $DIR/struct.rs:273:11
|
273 | #[repr(C, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:279:8
|
279 | #[repr(transparent, align(2))]
| ^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:288:16
|
288 | #[repr(packed, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:295:18
|
295 | #[repr(align(1), align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/struct.rs:301:18
|
301 | #[repr(align(2), align(4))]
| ^^^^^
error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
--> $DIR/struct.rs:305:10
|
305 | #[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
--> $DIR/struct.rs:310:10
|
310 | #[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
--> $DIR/struct.rs:324:8
|
324 | #[repr(C, packed(2))]
| ^
error[E0692]: transparent struct cannot have other repr hints
--> $DIR/struct.rs:279:8
|
279 | #[repr(transparent, align(2))]
| ^^^^^^^^^^^ ^^^^^^^^
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:31:10
|
31 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `KL00`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `KL00`
--> $DIR/struct.rs:34:8
|
34 | struct KL00(u8, NotKnownLayoutDst);
| ^^^^
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:38:10
|
38 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `KL02`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `KL02`
--> $DIR/struct.rs:41:8
|
41 | struct KL02(u8, [u8]);
| ^^^^
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotKnownLayoutDst: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:45:10
|
45 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `NotKnownLayoutDst`
--> $DIR/struct.rs:27:1
|
27 | struct NotKnownLayoutDst([u8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `NotKnownLayoutDst`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:53:10
|
53 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `NotKnownLayout`
--> $DIR/struct.rs:25:1
|
25 | struct NotKnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `NotKnownLayout`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
= help: see issue #48214
= note: this error originates in the derive macro `KnownLayout` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied
--> $DIR/struct.rs:63:10
|
63 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 130 others
= 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 `UnsafeCell<u8>: zerocopy_renamed::Immutable` is not satisfied
--> $DIR/struct.rs:70:10
|
70 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<u8>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<u8>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 130 others
= note: required for `[UnsafeCell<u8>; 0]` to implement `zerocopy_renamed::Immutable`
= 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[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:84:1
|
84 | struct TryFromBytesPacked {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:92:1
|
92 | struct TryFromBytesPackedN {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:100:1
|
100 | struct TryFromBytesCPacked {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/struct.rs:108:1
|
108 | struct TryFromBytesCPackedN {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/struct.rs:120:10
|
120 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
= 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]: `IntoBytes2` has 1 total byte(s) of padding
--> $DIR/struct.rs:129:10
|
129 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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]: `IntoBytes3` has 1 total byte(s) of padding
--> $DIR/struct.rs:139:10
|
139 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes3, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes3, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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 size for values of type `[u8]` cannot be known at compilation time
--> $DIR/struct.rs:158:10
|
158 | #[derive(IntoBytes)]
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `IntoBytes4`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `IntoBytes4`
--> $DIR/struct.rs:163:8
|
163 | struct IntoBytes4 {
| ^^^^^^^^^^
= note: required for `IntoBytes4` to implement `macro_util::__size_of::Sized`
note: required by a bound in `macro_util::__size_of::size_of`
--> $WORKSPACE/src/util/macro_util.rs:306:29
|
306 | pub const fn size_of<T: Sized + ?core::marker::Sized>() -> usize {
| ^^^^^ required by this bound in `size_of`
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `[u8]` is unsized
--> $DIR/struct.rs:165:8
|
165 | b: SliceU8,
| ^^^^^^^ `IntoBytes` needs all field types to be `Sized` in order to determine whether there is padding
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: consider using `#[repr(packed)]` to remove padding
= note: `IntoBytes` does not require the fields of `#[repr(packed)]` types to be `Sized`
= note: required for `[u8]` to implement `macro_util::__size_of::Sized`
note: required by a bound in `macro_util::__size_of::size_of`
--> $WORKSPACE/src/util/macro_util.rs:306:29
|
306 | pub const fn size_of<T: Sized + ?core::marker::Sized>() -> usize {
| ^^^^^ required by this bound in `size_of`
error[E0277]: `IntoBytes5` has one or more padding bytes
--> $DIR/struct.rs:172:10
|
172 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes5, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes5, false>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:80:1
|
80 | impl<T: ?Sized> DynamicPaddingFree<T, false> 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]: `IntoBytes6` has one or more padding bytes
--> $DIR/struct.rs:184:10
|
184 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes6, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes6, false>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:80:1
|
80 | impl<T: ?Sized> DynamicPaddingFree<T, false> 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]: `IntoBytes7` has one or more padding bytes
--> $DIR/struct.rs:197:10
|
197 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes7, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes7, false>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:80:1
|
80 | impl<T: ?Sized> DynamicPaddingFree<T, false> 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]: `IntoBytes13` has one or more padding bytes
--> $DIR/struct.rs:260:10
|
260 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `DynamicPaddingFree<IntoBytes13, true>` is not implemented for `()`
but trait `DynamicPaddingFree<IntoBytes13, false>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:80:1
|
80 | impl<T: ?Sized> DynamicPaddingFree<T, false> 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[E0587]: type has conflicting packed and align representation hints
--> $DIR/struct.rs:290:1
|
290 | struct Unaligned3;
| ^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `SplitAtNotKnownLayout: zerocopy_renamed::KnownLayout` is not satisfied
--> $DIR/struct.rs:328:10
|
328 | #[derive(SplitAt)]
| ^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::KnownLayout` is not implemented for `SplitAtNotKnownLayout`
--> $DIR/struct.rs:332:1
|
332 | struct SplitAtNotKnownLayout([u8]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(KnownLayout)]` to `SplitAtNotKnownLayout`
= help: the following other types implement trait `zerocopy_renamed::KnownLayout`:
&T
&mut T
()
*const T
*mut T
AU16
AtomicBool
AtomicI16
and 73 others
note: required by a bound in `SplitAt`
--> $WORKSPACE/src/split_at.rs:61:27
|
61 | pub unsafe trait SplitAt: KnownLayout<PointerMetadata = usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `SplitAt`
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `u8: SplitAt` is not satisfied
--> $DIR/struct.rs:334:10
|
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ the trait `SplitAt` is not implemented for `u8`
|
= note: Consider adding `#[derive(SplitAt)]` to `u8`
help: the following other types implement trait `SplitAt`
--> $DIR/struct.rs:328:10
|
328 | #[derive(SplitAt)]
| ^^^^^^^ `SplitAtNotKnownLayout`
...
334 | #[derive(SplitAt, KnownLayout)]
| ^^^^^^^ `SplitAtSized`
|
::: $WORKSPACE/src/split_at.rs:251:1
|
251 | unsafe impl<T> SplitAt for [T] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `[T]`
= help: see issue #48214
= note: this error originates in the derive macro `SplitAt` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `AU16: zerocopy_renamed::Unaligned` is not satisfied
--> $DIR/struct.rs:244:28
|
244 | is_into_bytes_11::<IntoBytes11<AU16>>();
| ^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `zerocopy_renamed::Unaligned` is not implemented for `AU16`
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
= note: Consider adding `#[derive(Unaligned)]` to `AU16`
= help: the following other types implement trait `zerocopy_renamed::Unaligned`:
()
AtomicBool
AtomicI8
AtomicU8
Cell<T>
F32<O>
F64<O>
I128<O>
and 26 others
note: required for `IntoBytes11<AU16>` to implement `zerocopy_renamed::IntoBytes`
--> $DIR/struct.rs:232:10
|
232 | #[derive(IntoBytes)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `is_into_bytes_11`
--> $DIR/struct.rs:242:24
|
242 | fn is_into_bytes_11<T: IntoBytes>() {
| ^^^^^^^^^ 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)
error: aborting due to 36 previous errors
Some errors have detailed explanations: E0277, E0587, E0588, E0692.
For more information about an error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,88 @@
error: unsupported on types with type parameters
--> $DIR/union.rs:36:10
|
36 | #[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)]
--> $DIR/union.rs:55:10
|
55 | #[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)]
--> $DIR/union.rs:63:10
|
63 | #[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
--> $DIR/union.rs:77:11
|
77 | #[repr(C, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:95:16
|
95 | #[repr(packed, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:104:18
|
104 | #[repr(align(1), align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:112:18
|
112 | #[repr(align(2), align(4))]
| ^^^^^
error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
--> $DIR/union.rs:118:10
|
118 | #[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
--> $DIR/union.rs:126:10
|
126 | #[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_renamed::Immutable` is not satisfied
--> $DIR/union.rs:25:10
|
25 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<()>`
|
= note: required because of the requirements on the impl of `zerocopy_renamed::Immutable` for `ManuallyDrop<UnsafeCell<()>>`
= 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 `(): PaddingFree<IntoBytes2, 1_usize>` is not satisfied
--> $DIR/union.rs:44:10
|
44 | #[derive(IntoBytes)]
| ^^^^^^^^^ the trait `PaddingFree<IntoBytes2, 1_usize>` is not implemented for `()`
|
= help: the following implementations were found:
<() as PaddingFree<T, 0_usize>>
= 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: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,130 @@
error: unsupported on types with type parameters
--> $DIR/union.rs:36:10
|
36 | #[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)]
--> $DIR/union.rs:55:10
|
55 | #[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)]
--> $DIR/union.rs:63:10
|
63 | #[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
--> $DIR/union.rs:77:11
|
77 | #[repr(C, align(2))]
| ^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:95:8
|
95 | #[repr(packed, align(2))]
| ^^^^^^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:104:8
|
104 | #[repr(align(1), align(2))]
| ^^^^^^^^^^^^^^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:112:8
|
112 | #[repr(align(2), align(4))]
| ^^^^^^^^^^^^^^^^^^
error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
--> $DIR/union.rs:118:10
|
118 | #[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
--> $DIR/union.rs:126:10
|
126 | #[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_renamed::Immutable` is not satisfied
--> $DIR/union.rs:25:10
|
25 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 129 others
= note: required for `ManuallyDrop<UnsafeCell<()>>` to implement `zerocopy_renamed::Immutable`
= help: see issue #48214
= note: this error originates in the derive macro `Immutable` (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)]
|
error[E0277]: `IntoBytes2` has 1 total byte(s) of padding
--> $DIR/union.rs:44:10
|
44 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> src/util/macro_util.rs:62:0
= 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
|
9 + #![feature(trivial_bounds)]
|
error[E0587]: type has conflicting packed and align representation hints
--> $DIR/union.rs:97:1
|
97 | union Unaligned3 {
| ^^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/union.rs:130:1
|
130 | union Unaligned7 {
| ^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error: aborting due to 13 previous errors
Some errors have detailed explanations: E0277, E0587, E0588.
For more information about an error, try `rustc --explain E0277`.

134
vendor/zerocopy-derive/tests/ui/union.rs vendored Normal file
View File

@@ -0,0 +1,134 @@
// Copyright 2019 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.
#[macro_use]
extern crate zerocopy_renamed;
#[path = "../include.rs"]
mod util;
use std::mem::ManuallyDrop;
use self::util::util::AU16;
fn main() {}
//
// Immutable errors
//
#[derive(Immutable)]
//~[msrv, stable, nightly]^ ERROR: the trait bound `UnsafeCell<()>: zerocopy_renamed::Immutable` is not satisfied
#[zerocopy(crate = "zerocopy_renamed")]
union Immutable1 {
a: ManuallyDrop<core::cell::UnsafeCell<()>>,
}
//
// IntoBytes errors
//
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: unsupported on types with type parameters
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union IntoBytes1<T> {
foo: ManuallyDrop<T>,
}
#[derive(IntoBytes)]
//~[msrv]^ ERROR: the trait bound `(): PaddingFree<IntoBytes2, 1_usize>` is not satisfied
//~[stable, nightly]^^ ERROR: `IntoBytes2` has 1 total byte(s) of padding
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union IntoBytes2 {
foo: u8,
bar: [u8; 2],
}
// Need a `repr` attribute
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)]
#[zerocopy(crate = "zerocopy_renamed")]
union IntoBytes3 {
foo: u8,
}
// `repr(packed(2))` isn't equivalent to `repr(packed)`
#[derive(IntoBytes)]
//~[msrv, stable, nightly]^ ERROR: must be #[repr(C)], #[repr(packed)], or #[repr(transparent)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed(2))]
union IntoBytes4 {
foo: u8,
}
//
// Unaligned errors
//
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
//~[msrv, stable, nightly]^ ERROR: cannot derive `Unaligned` on type with alignment greater than 1
union Unaligned1 {
foo: i16,
bar: AU16,
}
// Transparent unions are unstable; see issue #60405
// <https://github.com/rust-lang/rust/issues/60405> for more information.
// #[derive(Unaligned)]
// #[repr(transparent, align(2))]
// union Unaligned2 {
// foo: u8,
// }
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed, align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
union Unaligned3 {
//~[stable, nightly]^ ERROR: type has conflicting packed and align representation hints
foo: u8,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(1), align(2))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct Unaligned4 {
foo: u8,
}
#[derive(Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(align(2), align(4))]
//~[msrv, stable, nightly]^ ERROR: this conflicts with another representation hint
struct Unaligned5 {
foo: u8,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
union Unaligned6 {
foo: i16,
bar: AU16,
}
#[derive(Unaligned)]
//~[msrv, stable, nightly]^ ERROR: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed(2))]
union Unaligned7 {
//~[stable, nightly]^ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
foo: i16,
bar: AU16,
}

View File

@@ -0,0 +1,125 @@
error: unsupported on types with type parameters
--> $DIR/union.rs:36:10
|
36 | #[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)]
--> $DIR/union.rs:55:10
|
55 | #[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)]
--> $DIR/union.rs:63:10
|
63 | #[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
--> $DIR/union.rs:77:11
|
77 | #[repr(C, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:95:16
|
95 | #[repr(packed, align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:104:18
|
104 | #[repr(align(1), align(2))]
| ^^^^^
error: this conflicts with another representation hint
--> $DIR/union.rs:112:18
|
112 | #[repr(align(2), align(4))]
| ^^^^^
error: must have #[repr(C)], #[repr(transparent)], or #[repr(packed)] attribute in order to guarantee this type's alignment
--> $DIR/union.rs:118:10
|
118 | #[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
--> $DIR/union.rs:126:10
|
126 | #[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_renamed::Immutable` is not satisfied
--> $DIR/union.rs:25:10
|
25 | #[derive(Immutable)]
| ^^^^^^^^^ the trait `zerocopy_renamed::Immutable` is not implemented for `UnsafeCell<()>`
|
= note: Consider adding `#[derive(Immutable)]` to `UnsafeCell<()>`
= help: the following other types implement trait `zerocopy_renamed::Immutable`:
&T
&mut T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 129 others
= note: required for `ManuallyDrop<UnsafeCell<()>>` to implement `zerocopy_renamed::Immutable`
= 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]: `IntoBytes2` has 1 total byte(s) of padding
--> $DIR/union.rs:44:10
|
44 | #[derive(IntoBytes)]
| ^^^^^^^^^ 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 padding
help: the trait `PaddingFree<IntoBytes2, 1>` is not implemented for `()`
but trait `PaddingFree<IntoBytes2, 0>` is implemented for it
--> $WORKSPACE/src/util/macro_util.rs:62:1
|
62 | impl<T: ?Sized> PaddingFree<T, 0> 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[E0587]: type has conflicting packed and align representation hints
--> $DIR/union.rs:97:1
|
97 | union Unaligned3 {
| ^^^^^^^^^^^^^^^^
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/union.rs:130:1
|
130 | union Unaligned7 {
| ^^^^^^^^^^^^^^^^
|
note: `AU16` has a `#[repr(align)]` attribute
--> $DIR/../include.rs:64:5
|
64 | pub struct AU16(pub u16);
| ^^^^^^^^^^^^^^^
error: aborting due to 13 previous errors
Some errors have detailed explanations: E0277, E0587, E0588.
For more information about an error, try `rustc --explain E0277`.

View File

@@ -0,0 +1,89 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A union is `imp::FromBytes` if:
// - all fields are `imp::FromBytes`
#[derive(Clone, Copy, imp::Immutable, imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union Zst {
a: (),
}
util_assert_impl_all!(Zst: imp::FromBytes);
test_trivial_is_bit_valid!(Zst => test_zst_trivial_is_bit_valid);
#[derive(imp::Immutable, imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union One {
a: u8,
}
util_assert_impl_all!(One: imp::FromBytes);
test_trivial_is_bit_valid!(One => test_one_trivial_is_bit_valid);
#[derive(imp::Immutable, imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union Two {
a: u8,
b: Zst,
}
util_assert_impl_all!(Two: imp::FromBytes);
test_trivial_is_bit_valid!(Two => test_two_trivial_is_bit_valid);
#[derive(imp::Immutable, imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [u8]>,
f: imp::PhantomData<&'static str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::FromBytes);
test_trivial_is_bit_valid!(TypeParams<'static, (), imp::IntoIter<()>> => test_type_params_trivial_is_bit_valid);
// Deriving `imp::FromBytes` should work if the union has bounded parameters.
#[derive(imp::Immutable, imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::FromBytes, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Copy + imp::FromBytes,
{
a: [T; N],
b: imp::PhantomData<&'a &'b ()>,
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::FromBytes);
test_trivial_is_bit_valid!(WithParams<'static, 'static, u8, 42> => test_with_params_trivial_is_bit_valid);
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union UnsafeCellUnion {
a: imp::ManuallyDrop<imp::UnsafeCell<u8>>,
}
util_assert_impl_all!(UnsafeCellUnion: imp::FromBytes);
test_trivial_is_bit_valid!(UnsafeCellUnion => test_unsafe_cell_union_trivial_is_bit_valid);

View File

@@ -0,0 +1,83 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A union is `imp::FromZeros` if:
// - all fields are `imp::FromZeros`
#[derive(Clone, Copy, imp::Immutable, imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
union Zst {
a: (),
}
util_assert_impl_all!(Zst: imp::FromZeros);
#[derive(imp::Immutable, imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
union One {
a: bool,
}
util_assert_impl_all!(One: imp::FromZeros);
#[derive(imp::Immutable, imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
union Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::FromZeros);
#[derive(imp::Immutable, imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [u8]>,
f: imp::PhantomData<&'static str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::FromZeros);
// Deriving `imp::FromZeros` should work if the union has bounded parameters.
#[derive(imp::Immutable, imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::FromZeros, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Copy + imp::FromZeros,
{
a: [T; N],
b: imp::PhantomData<&'a &'b ()>,
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::FromZeros);
#[derive(imp::FromZeros)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union UnsafeCellUnion {
a: imp::ManuallyDrop<imp::UnsafeCell<u8>>,
}
util_assert_impl_all!(UnsafeCellUnion: imp::FromZeros);

View File

@@ -0,0 +1,71 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(Clone, Copy, imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
union Zst {
a: (),
}
util_assert_impl_all!(Zst: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
union One {
a: bool,
}
util_assert_impl_all!(One: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
union Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [u8]>,
f: imp::PhantomData<&'static str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::KnownLayout);
// Deriving `imp::KnownLayout` should work if the union has bounded parameters.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Copy + imp::KnownLayout,
{
a: [T; N],
b: imp::PhantomData<&'a &'b ()>,
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);

View File

@@ -0,0 +1,73 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
#[derive(Clone, Copy, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
union Zst {
a: (),
}
util_assert_impl_all!(Zst: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
union One {
a: bool,
}
util_assert_impl_all!(One: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
union Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::Immutable);
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [::core::primitive::u8]>,
f: imp::PhantomData<&'static ::core::primitive::str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::Immutable);
// Deriving `imp::Immutable` should work if the union has bounded parameters.
#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::Immutable, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::Copy + imp::Immutable,
{
a: [T; N],
b: imp::PhantomData<&'a &'b ()>,
c: imp::PhantomData<imp::UnsafeCell<()>>,
d: &'a imp::UnsafeCell<()>,
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable);

View File

@@ -0,0 +1,89 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A union is `imp::IntoBytes` if:
// - all fields are `imp::IntoBytes`
// - `repr(C)` or `repr(transparent)` and
// - no padding (size of union equals size of each field type)
// - `repr(packed)`
#[derive(imp::IntoBytes, Clone, Copy)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union CZst {
a: (),
}
util_assert_impl_all!(CZst: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union C {
a: u8,
b: u8,
}
util_assert_impl_all!(C: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(2))]
union Aligned {
a: [u8; 2],
}
util_assert_impl_all!(Aligned: imp::IntoBytes);
// Transparent unions are unstable; see issue #60405
// <https://github.com/rust-lang/rust/issues/60405> for more information.
// #[derive(imp::IntoBytes)]
// #[repr(transparent)]
// union Transparent {
// a: u8,
// b: CZst,
// }
// is_as_bytes!(Transparent);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
union CZstPacked {
a: (),
}
util_assert_impl_all!(CZstPacked: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
union CPacked {
a: u8,
b: i8,
}
util_assert_impl_all!(CPacked: imp::IntoBytes);
#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
union CMultibytePacked {
a: i32,
b: u32,
c: f32,
}
util_assert_impl_all!(CMultibytePacked: imp::IntoBytes);

View File

@@ -0,0 +1,140 @@
// Copyright 2023 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A struct is `imp::TryFromBytes` if:
// - any of its fields are `imp::TryFromBytes`
#[derive(imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union One {
a: u8,
}
util_assert_impl_all!(One: imp::TryFromBytes);
#[test]
fn one() {
crate::util::test_is_bit_valid::<One, _>([42u8], true);
crate::util::test_is_bit_valid::<One, _>([43u8], true);
}
#[derive(imp::Immutable, imp::TryFromBytes, imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union Two {
a: bool,
b: bool,
}
util_assert_impl_all!(Two: imp::TryFromBytes);
#[test]
fn two() {
crate::util::test_is_bit_valid::<Two, _>(Two { a: false }, true);
crate::util::test_is_bit_valid::<Two, _>(Two { b: true }, true);
crate::util::test_is_bit_valid::<Two, _>([2u8], false);
}
#[derive(imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union BoolAndZst {
a: bool,
b: (),
}
#[test]
fn bool_and_zst() {
crate::util::test_is_bit_valid::<BoolAndZst, _>([0u8], true);
crate::util::test_is_bit_valid::<BoolAndZst, _>([1u8], true);
crate::util::test_is_bit_valid::<BoolAndZst, _>([2u8], true);
}
#[derive(imp::FromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union MaybeFromBytes<T: imp::Copy> {
t: T,
}
#[test]
fn test_maybe_from_bytes() {
// When deriving `FromBytes` on a type with no generic parameters, we emit a
// trivial `is_bit_valid` impl that always returns true. This test confirms
// that we *don't* spuriously do that when generic parameters are present.
crate::util::test_is_bit_valid::<MaybeFromBytes<bool>, _>([2u8], false);
}
#[derive(imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [u8]>,
d: imp::PhantomData<&'static str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::TryFromBytes);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::TryFromBytes);
util_assert_impl_all!(TypeParams<'static, [util::AU16; 2], imp::IntoIter<()>>: imp::TryFromBytes);
// Deriving `imp::TryFromBytes` should work if the union has bounded parameters.
#[derive(imp::Immutable, imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::TryFromBytes, const N: usize>
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::TryFromBytes + imp::Copy,
{
a: imp::PhantomData<&'a &'b ()>,
b: T,
}
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::TryFromBytes);
#[derive(Clone, Copy, imp::TryFromBytes, imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
struct A;
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
union B {
a: A,
}
#[derive(imp::TryFromBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union UnsafeCellUnion {
a: imp::ManuallyDrop<imp::UnsafeCell<bool>>,
}
util_assert_impl_all!(UnsafeCellUnion: imp::TryFromBytes);
#[test]
fn unsafe_cell_union() {
crate::util::test_is_bit_valid::<UnsafeCellUnion, _>([0u8], true);
crate::util::test_is_bit_valid::<UnsafeCellUnion, _>([1u8], true);
crate::util::test_is_bit_valid::<UnsafeCellUnion, _>([2u8], false);
}

View File

@@ -0,0 +1,80 @@
// Copyright 2019 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// A union is `Unaligned` if:
// - `repr(align)` is no more than 1 and either
// - `repr(C)` or `repr(transparent)` and
// - all fields `Unaligned`
// - `repr(packed)`
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union Foo {
a: imp::u8,
}
util_assert_impl_all!(Foo: imp::Unaligned);
// Transparent unions are unstable; see issue #60405
// <https://github.com/rust-lang/rust/issues/60405> for more information.
// #[derive(Unaligned)]
// #[repr(transparent)]
// union Bar {
// a: u8,
// }
// is_unaligned!(Bar);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(packed)]
union Baz {
// NOTE: The `u16` type is not guaranteed to have alignment 2, although it
// does on many platforms. However, to fix this would require a custom type
// with a `#[repr(align(2))]` attribute, and `#[repr(packed)]` types are not
// allowed to transitively contain `#[repr(align(...))]` types. Thus, we
// have no choice but to use `u16` here. Luckily, these tests run in CI on
// platforms on which `u16` has alignment 2, so this isn't that big of a
// deal.
a: u16,
}
util_assert_impl_all!(Baz: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, align(1))]
union FooAlign {
a: imp::u8,
}
util_assert_impl_all!(FooAlign: imp::Unaligned);
#[derive(imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
where
I::Item: imp::Copy,
{
a: T,
c: I::Item,
d: u8,
e: imp::PhantomData<&'a [imp::u8]>,
f: imp::PhantomData<&'static imp::str>,
g: imp::PhantomData<imp::String>,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::Unaligned);

View File

@@ -0,0 +1,36 @@
// Copyright 2025 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.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
include!("include.rs");
// Test to make sure that all of our derives are compatible with `UnsafeCell`s.
//
// We test both `FromBytes` and `FromZeros`, as the `FromBytes` implied derive
// of `TryFromBytes` emits a trivial `is_bit_valid` impl - we want to test the
// non-trivial impl, which deriving `FromZeros` accomplishes.
#[derive(imp::FromBytes, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct StructFromBytes(imp::UnsafeCell<u8>);
#[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct StructFromZeros(imp::UnsafeCell<bool>);
#[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(u8)]
enum EnumFromZeros {
A(imp::UnsafeCell<bool>),
}