Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1,40 @@
// 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;
#[path = "../util.rs"]
mod util;
use core::marker::PhantomData;
use {
static_assertions::assert_impl_all,
zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned},
};
use self::util::NotZerocopy;
fn main() {}
// Test generic transparent structs
#[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
#[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.
assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeroes);
assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);

View file

@ -0,0 +1,111 @@
error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied
--> tests/ui-stable/derive_transparent.rs:37:18
|
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeroes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `FromZeroes`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
note: required for `TransparentStruct<NotZerocopy>` to implement `FromZeroes`
--> tests/ui-stable/derive_transparent.rs:27:19
|
27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
| ^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-stable/derive_transparent.rs:37:1
|
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeroes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `FromZeroes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
--> tests/ui-stable/derive_transparent.rs:38:18
|
38 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `FromBytes`:
isize
i8
i16
i32
i64
i128
usize
u8
and $N others
note: required for `TransparentStruct<NotZerocopy>` to implement `FromBytes`
--> tests/ui-stable/derive_transparent.rs:27:31
|
27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-stable/derive_transparent.rs:38:1
|
38 | 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 `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied
--> tests/ui-stable/derive_transparent.rs:39:18
|
39 | assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `AsBytes`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
note: required for `TransparentStruct<NotZerocopy>` to implement `AsBytes`
--> tests/ui-stable/derive_transparent.rs:27:10
|
27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
| ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-stable/derive_transparent.rs:39:1
|
39 | assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl_all`
= note: this error originates in the derive macro `AsBytes` which comes from the expansion of the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: Unaligned` is not satisfied
--> tests/ui-stable/derive_transparent.rs:40:18
|
40 | assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `Unaligned`:
bool
i8
u8
TransparentStruct<T>
U16<O>
U32<O>
U64<O>
U128<O>
and $N others
note: required for `TransparentStruct<NotZerocopy>` to implement `Unaligned`
--> tests/ui-stable/derive_transparent.rs:27:42
|
27 | #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
| ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-stable/derive_transparent.rs:40:1
|
40 | 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 `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -0,0 +1,194 @@
// 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;
fn main() {}
//
// Generic errors
//
#[derive(FromZeroes, FromBytes)]
#[repr("foo")]
enum Generic1 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(foo)]
enum Generic2 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(transparent)]
enum Generic3 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(u8, u16)]
enum Generic4 {
A,
}
#[derive(FromZeroes, FromBytes)]
enum Generic5 {
A,
}
//
// FromZeroes errors
//
#[derive(FromZeroes)]
enum FromZeroes1 {
A(u8),
}
#[derive(FromZeroes)]
enum FromZeroes2 {
A,
B(u8),
}
#[derive(FromZeroes)]
enum FromZeroes3 {
A = 1,
B,
}
//
// FromBytes errors
//
#[derive(FromZeroes, FromBytes)]
#[repr(C)]
enum FromBytes1 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(usize)]
enum FromBytes2 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(isize)]
enum FromBytes3 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(u32)]
enum FromBytes4 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(i32)]
enum FromBytes5 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(u64)]
enum FromBytes6 {
A,
}
#[derive(FromZeroes, FromBytes)]
#[repr(i64)]
enum FromBytes7 {
A,
}
//
// Unaligned errors
//
#[derive(Unaligned)]
#[repr(C)]
enum Unaligned1 {
A,
}
#[derive(Unaligned)]
#[repr(u16)]
enum Unaligned2 {
A,
}
#[derive(Unaligned)]
#[repr(i16)]
enum Unaligned3 {
A,
}
#[derive(Unaligned)]
#[repr(u32)]
enum Unaligned4 {
A,
}
#[derive(Unaligned)]
#[repr(i32)]
enum Unaligned5 {
A,
}
#[derive(Unaligned)]
#[repr(u64)]
enum Unaligned6 {
A,
}
#[derive(Unaligned)]
#[repr(i64)]
enum Unaligned7 {
A,
}
#[derive(Unaligned)]
#[repr(usize)]
enum Unaligned8 {
A,
}
#[derive(Unaligned)]
#[repr(isize)]
enum Unaligned9 {
A,
}
#[derive(Unaligned)]
#[repr(u8, align(2))]
enum Unaligned10 {
A,
}
#[derive(Unaligned)]
#[repr(i8, align(2))]
enum Unaligned11 {
A,
}
#[derive(Unaligned)]
#[repr(align(1), align(2))]
enum Unaligned12 {
A,
}
#[derive(Unaligned)]
#[repr(align(2), align(4))]
enum Unaligned13 {
A,
}

View file

@ -0,0 +1,201 @@
error: unrecognized representation hint
--> tests/ui-stable/enum.rs:19:8
|
19 | #[repr("foo")]
| ^^^^^
error: unrecognized representation hint
--> tests/ui-stable/enum.rs:25:8
|
25 | #[repr(foo)]
| ^^^
error: unsupported representation for deriving FromBytes, AsBytes, or Unaligned on an enum
--> tests/ui-stable/enum.rs:31:8
|
31 | #[repr(transparent)]
| ^^^^^^^^^^^
error: conflicting representation hints
--> tests/ui-stable/enum.rs:37:1
|
37 | #[repr(u8, u16)]
| ^
error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
--> tests/ui-stable/enum.rs:42:22
|
42 | #[derive(FromZeroes, FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: only C-like enums can implement FromZeroes
--> tests/ui-stable/enum.rs:52:1
|
52 | / enum FromZeroes1 {
53 | | A(u8),
54 | | }
| |_^
error: only C-like enums can implement FromZeroes
--> tests/ui-stable/enum.rs:57:1
|
57 | / enum FromZeroes2 {
58 | | A,
59 | | B(u8),
60 | | }
| |_^
error: FromZeroes only supported on enums with a variant that has a discriminant of `0`
--> tests/ui-stable/enum.rs:63:1
|
63 | / enum FromZeroes3 {
64 | | A = 1,
65 | | B,
66 | | }
| |_^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:73:8
|
73 | #[repr(C)]
| ^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:79:8
|
79 | #[repr(usize)]
| ^^^^^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:85:8
|
85 | #[repr(isize)]
| ^^^^^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:91:8
|
91 | #[repr(u32)]
| ^^^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:97:8
|
97 | #[repr(i32)]
| ^^^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:103:8
|
103 | #[repr(u64)]
| ^^^
error: FromBytes requires repr of "u8", "u16", "i8", or "i16"
--> tests/ui-stable/enum.rs:109:8
|
109 | #[repr(i64)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:119:8
|
119 | #[repr(C)]
| ^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:125:8
|
125 | #[repr(u16)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:131:8
|
131 | #[repr(i16)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:137:8
|
137 | #[repr(u32)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:143:8
|
143 | #[repr(i32)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:149:8
|
149 | #[repr(u64)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:155:8
|
155 | #[repr(i64)]
| ^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:161:8
|
161 | #[repr(usize)]
| ^^^^^
error: Unaligned requires repr of "u8" or "i8", and no alignment (i.e., repr(align(N > 1)))
--> tests/ui-stable/enum.rs:167:8
|
167 | #[repr(isize)]
| ^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/enum.rs:173:12
|
173 | #[repr(u8, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/enum.rs:179:12
|
179 | #[repr(i8, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/enum.rs:185:18
|
185 | #[repr(align(1), align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/enum.rs:191:8
|
191 | #[repr(align(2), align(4))]
| ^^^^^^^^
error[E0565]: meta item in `repr` must be an identifier
--> tests/ui-stable/enum.rs:19:8
|
19 | #[repr("foo")]
| ^^^^^
error[E0552]: unrecognized representation hint
--> tests/ui-stable/enum.rs:25:8
|
25 | #[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`
error[E0566]: conflicting representation hints
--> tests/ui-stable/enum.rs:37:8
|
37 | #[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)]` on by default

View file

@ -0,0 +1,272 @@
// 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;
fn main() {}
#[derive(FromBytes)]
#[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,11 @@
error: FromBytes only supported on repr(u8) enum with 256 variants
--> tests/ui-stable/enum_from_bytes_u8_too_few.rs:15:1
|
15 | / #[repr(u8)]
16 | | enum Foo {
17 | | Variant0,
18 | | Variant1,
... |
271 | | Variant254,
272 | | }
| |_^

View file

@ -0,0 +1,75 @@
// 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;
#[path = "../util.rs"]
mod util;
use self::util::{NotZerocopy, AU16};
use zerocopy::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.
//
// FromZeroes errors
//
#[derive(FromZeroes)]
struct FromZeroes1 {
value: NotZerocopy,
}
//
// FromBytes errors
//
#[derive(FromBytes)]
struct FromBytes1 {
value: NotZerocopy,
}
//
// AsBytes errors
//
#[derive(AsBytes)]
#[repr(C)]
struct AsBytes1 {
value: NotZerocopy,
}
//
// Unaligned errors
//
#[derive(Unaligned)]
#[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)]
#[repr(C)]
struct Unaligned2 {
unaligned: u8,
aligned: AU16,
}
#[derive(Unaligned)]
#[repr(transparent)]
struct Unaligned3 {
aligned: AU16,
}

View file

@ -0,0 +1,144 @@
warning: unused import: `zerocopy::KnownLayout`
--> tests/ui-stable/late_compile_pass.rs:16:5
|
16 | use zerocopy::KnownLayout;
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:28:10
|
28 | #[derive(FromZeroes)]
| ^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `FromZeroes`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `FromZeroes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:37:10
|
37 | #[derive(FromBytes)]
| ^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `FromBytes`:
isize
i8
i16
i32
i64
i128
usize
u8
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:37:10
|
37 | #[derive(FromBytes)]
| ^^^^^^^^^ the trait `FromZeroes` is not implemented for `FromBytes1`
|
= help: the following other types implement trait `FromZeroes`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
note: required by a bound in `FromBytes`
--> $WORKSPACE/src/lib.rs
|
| pub unsafe trait FromBytes: FromZeroes {
| ^^^^^^^^^^ required by this bound in `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 `NotZerocopy: AsBytes` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:46:10
|
46 | #[derive(AsBytes)]
| ^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy`
|
= help: the following other types implement trait `AsBytes`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
= help: see issue #48214
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `AU16: Unaligned` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:56:10
|
56 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16`
|
= help: the following other types implement trait `Unaligned`:
bool
i8
u8
Unaligned1
Unaligned2
Unaligned3
U16<O>
U32<O>
and $N 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: Unaligned` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:64:10
|
64 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16`
|
= help: the following other types implement trait `Unaligned`:
bool
i8
u8
Unaligned1
Unaligned2
Unaligned3
U16<O>
U32<O>
and $N 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: Unaligned` is not satisfied
--> tests/ui-stable/late_compile_pass.rs:71:10
|
71 | #[derive(Unaligned)]
| ^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16`
|
= help: the following other types implement trait `Unaligned`:
bool
i8
u8
Unaligned1
Unaligned2
Unaligned3
U16<O>
U32<O>
and $N 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)

View file

@ -0,0 +1,61 @@
// 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;
use zerocopy::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)]
struct KL04<T: ?Sized>(u8, T);
fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
assert_kl(kl);
}
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | Y | Y | N | KL06 |
#[derive(KnownLayout)]
struct KL06<T: ?Sized + KnownLayout>(u8, T);
fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
assert_kl(kl);
}
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | Y | Y | N | N | KL12 |
#[derive(KnownLayout)]
#[repr(C)]
struct KL12<T: ?Sized>(u8, T);
fn test_kl12<T: ?Sized>(kl: &KL12<T>) {
assert_kl(kl)
}
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | Y | Y | N | Y | KL13 |
#[derive(KnownLayout)]
#[repr(C)]
struct KL13<T>(u8, T);
fn test_kl13<T>(t: T) -> impl KnownLayout {
KL13(0u8, t)
}

View file

@ -0,0 +1,104 @@
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> tests/ui-stable/mid_compile_pass.rs:59:26
|
59 | fn test_kl13<T>(t: T) -> impl KnownLayout {
| ^^^^^^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `T`
|
note: required for `KL13<T>` to implement `KnownLayout`
--> tests/ui-stable/mid_compile_pass.rs:55:10
|
55 | #[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`
|
59 | fn test_kl13<T: zerocopy::KnownLayout>(t: T) -> impl KnownLayout {
| +++++++++++++++++++++++
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> tests/ui-stable/mid_compile_pass.rs:31:15
|
30 | fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
| - this type parameter needs to be `Sized`
31 | 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>`
--> tests/ui-stable/mid_compile_pass.rs:28:8
|
28 | struct KL04<T: ?Sized>(u8, T);
| ^^^^
note: required for `KL04<T>` to implement `KnownLayout`
--> tests/ui-stable/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`
--> tests/ui-stable/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`
|
30 - fn test_kl04<T: ?Sized>(kl: &KL04<T>) {
30 + fn test_kl04<T>(kl: &KL04<T>) {
|
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> tests/ui-stable/mid_compile_pass.rs:40:15
|
39 | fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
| - this type parameter needs to be `Sized`
40 | 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>`
--> tests/ui-stable/mid_compile_pass.rs:37:8
|
37 | struct KL06<T: ?Sized + KnownLayout>(u8, T);
| ^^^^
note: required for `KL06<T>` to implement `KnownLayout`
--> tests/ui-stable/mid_compile_pass.rs:36:10
|
36 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> tests/ui-stable/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`
|
39 - fn test_kl06<T: ?Sized + KnownLayout>(kl: &KL06<T>) {
39 + fn test_kl06<T: KnownLayout>(kl: &KL06<T>) {
|
error[E0277]: the trait bound `T: KnownLayout` is not satisfied
--> tests/ui-stable/mid_compile_pass.rs:50:15
|
50 | assert_kl(kl)
| --------- ^^ the trait `KnownLayout` is not implemented for `T`
| |
| required by a bound introduced by this call
|
note: required for `KL12<T>` to implement `KnownLayout`
--> tests/ui-stable/mid_compile_pass.rs:45:10
|
45 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
note: required by a bound in `assert_kl`
--> tests/ui-stable/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 further restricting this bound
|
49 | fn test_kl12<T: ?Sized + zerocopy::KnownLayout>(kl: &KL12<T>) {
| +++++++++++++++++++++++

View file

@ -0,0 +1,99 @@
// 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;
#[path = "../util.rs"]
mod util;
use zerocopy::KnownLayout;
use self::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)]
struct KL00(u8, NotKnownLayoutDst);
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | N | N | Y | N | KL02 |
#[derive(KnownLayout)]
struct KL02(u8, [u8]);
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | Y | N | N | N | KL08 |
#[derive(KnownLayout)]
#[repr(C)]
struct KL08(u8, NotKnownLayoutDst);
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name |
// | Y | N | N | Y | KL09 |
#[derive(KnownLayout)]
#[repr(C)]
struct KL09(NotKnownLayout, NotKnownLayout);
//
// AsBytes errors
//
#[derive(AsBytes)]
#[repr(C)]
struct AsBytes1<T>(T);
#[derive(AsBytes)]
#[repr(C)]
struct AsBytes2 {
foo: u8,
bar: AU16,
}
#[derive(AsBytes)]
#[repr(C, packed(2))]
struct AsBytes3 {
foo: u8,
// We'd prefer to use AU64 here, but you can't use aligned types in
// packed structs.
bar: u64,
}
//
// Unaligned errors
//
#[derive(Unaligned)]
#[repr(C, align(2))]
struct Unaligned1;
#[derive(Unaligned)]
#[repr(transparent, align(2))]
struct Unaligned2 {
foo: u8,
}
#[derive(Unaligned)]
#[repr(packed, align(2))]
struct Unaligned3;
#[derive(Unaligned)]
#[repr(align(1), align(2))]
struct Unaligned4;
#[derive(Unaligned)]
#[repr(align(2), align(4))]
struct Unaligned5;

View file

@ -0,0 +1,131 @@
error: unsupported on generic structs that are not repr(transparent) or repr(packed)
--> tests/ui-stable/struct.rs:55:10
|
55 | #[derive(AsBytes)]
| ^^^^^^^
|
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/struct.rs:80:11
|
80 | #[repr(C, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/struct.rs:84:21
|
84 | #[repr(transparent, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/struct.rs:90:16
|
90 | #[repr(packed, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/struct.rs:94:18
|
94 | #[repr(align(1), align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/struct.rs:98:8
|
98 | #[repr(align(2), align(4))]
| ^^^^^^^^
error[E0692]: transparent struct cannot have other repr hints
--> tests/ui-stable/struct.rs:84:8
|
84 | #[repr(transparent, align(2))]
| ^^^^^^^^^^^ ^^^^^^^^
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> tests/ui-stable/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`
--> tests/ui-stable/struct.rs:32:8
|
32 | 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
--> tests/ui-stable/struct.rs:36:10
|
36 | #[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`
--> tests/ui-stable/struct.rs:37:8
|
37 | 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: KnownLayout` is not satisfied
--> tests/ui-stable/struct.rs:41:10
|
41 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `NotKnownLayoutDst`
|
= help: the following other types implement trait `KnownLayout`:
bool
char
isize
i8
i16
i32
i64
i128
and $N 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: KnownLayout` is not satisfied
--> tests/ui-stable/struct.rs:47:10
|
47 | #[derive(KnownLayout)]
| ^^^^^^^^^^^ the trait `KnownLayout` is not implemented for `NotKnownLayout`
|
= help: the following other types implement trait `KnownLayout`:
bool
char
isize
i8
i16
i32
i64
i128
and $N 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 `HasPadding<AsBytes2, true>: ShouldBe<false>` is not satisfied
--> tests/ui-stable/struct.rs:59:10
|
59 | #[derive(AsBytes)]
| ^^^^^^^ the trait `ShouldBe<false>` is not implemented for `HasPadding<AsBytes2, true>`
|
= help: the trait `ShouldBe<VALUE>` is implemented for `HasPadding<T, VALUE>`
= help: see issue #48214
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `HasPadding<AsBytes3, true>: ShouldBe<false>` is not satisfied
--> tests/ui-stable/struct.rs:66:10
|
66 | #[derive(AsBytes)]
| ^^^^^^^ the trait `ShouldBe<false>` is not implemented for `HasPadding<AsBytes3, true>`
|
= help: the trait `ShouldBe<VALUE>` is implemented for `HasPadding<T, VALUE>`
= help: see issue #48214
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -0,0 +1,73 @@
// 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;
#[path = "../util.rs"]
mod util;
use self::util::AU16;
use std::mem::ManuallyDrop;
fn main() {}
//
// AsBytes errors
//
#[derive(AsBytes)]
#[repr(C)]
union AsBytes1<T> {
foo: ManuallyDrop<T>,
}
#[derive(AsBytes)]
#[repr(C)]
union AsBytes2 {
foo: u8,
bar: [u8; 2],
}
//
// Unaligned errors
//
#[derive(Unaligned)]
#[repr(C, align(2))]
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)]
#[repr(packed, align(2))]
union Unaligned3 {
foo: u8,
}
#[derive(Unaligned)]
#[repr(align(1), align(2))]
struct Unaligned4 {
foo: u8,
}
#[derive(Unaligned)]
#[repr(align(2), align(4))]
struct Unaligned5 {
foo: u8,
}

View file

@ -0,0 +1,41 @@
error: unsupported on types with type parameters
--> tests/ui-stable/union.rs:24:10
|
24 | #[derive(AsBytes)]
| ^^^^^^^
|
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/union.rs:42:11
|
42 | #[repr(C, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/union.rs:58:16
|
58 | #[repr(packed, align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/union.rs:64:18
|
64 | #[repr(align(1), align(2))]
| ^^^^^^^^
error: cannot derive Unaligned with repr(align(N > 1))
--> tests/ui-stable/union.rs:70:8
|
70 | #[repr(align(2), align(4))]
| ^^^^^^^^
error[E0277]: the trait bound `HasPadding<AsBytes2, true>: ShouldBe<false>` is not satisfied
--> tests/ui-stable/union.rs:30:10
|
30 | #[derive(AsBytes)]
| ^^^^^^^ the trait `ShouldBe<false>` is not implemented for `HasPadding<AsBytes2, true>`
|
= help: the trait `ShouldBe<VALUE>` is implemented for `HasPadding<T, VALUE>`
= help: see issue #48214
= note: this error originates in the derive macro `AsBytes` (in Nightly builds, run with -Z macro-backtrace for more info)