Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error messages and zerocopy #403

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -30,7 +30,7 @@ rustversion = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_test = "1.0"
zerocopy = "0.6"
zerocopy = { version = "0.7", features = ["derive"] }
arbitrary = { version = "1.0", features = ["derive"] }
bytemuck = { version = "1.0", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_derive.rs
Expand Up @@ -6,7 +6,7 @@ use bitflags::bitflags;

// Define a flags type outside of the `bitflags` macro as a newtype
// It can accept custom derives for libaries `bitflags` doesn't support natively
#[derive(zerocopy::AsBytes, zerocopy::FromBytes)]
#[derive(zerocopy::AsBytes, zerocopy::FromBytes, zerocopy::FromZeroes)]
#[repr(transparent)]
pub struct ManualFlags(u32);

Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/bitflags_custom_bits.rs
Expand Up @@ -124,7 +124,7 @@ impl ParseHex for MyInt {
}

impl WriteHex for MyInt {
fn write_hex<W: fmt::Write>(&self, writer: W) -> fmt::Result {
fn write_hex<W: fmt::Write>(&self, mut writer: W) -> fmt::Result {
write!(writer, "{:x}", self.0)
}
}
Expand Down
320 changes: 320 additions & 0 deletions tests/compile-fail/bitflags_custom_bits.stderr
Expand Up @@ -19,3 +19,323 @@ note: required by a bound in `PublicFlags::Primitive`
|
| type Primitive: Primitive;
| ^^^^^^^^^ required by this bound in `PublicFlags::Primitive`

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:42:1
|
42 | impl BitOr for MyInt {
| ^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:26:23
|
26 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
| ^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:34:1
|
34 | impl BitAnd for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:26:23
|
26 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
| ^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:42:1
|
42 | impl BitOr for MyInt {
| ^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:26:23
|
26 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
| ^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:34:1
|
34 | impl BitAnd for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:26:23
|
26 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
| ^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:34:1
|
34 | impl BitAnd for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:26:23
|
26 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
| ^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:34:1
|
34 | impl BitAnd for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:42:1
|
42 | impl BitOr for MyInt {
| ^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:76:1
|
76 | impl Not for MyInt {
| ^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:34:1
|
34 | impl BitAnd for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:50:1
|
50 | impl BitXor for MyInt {
| ^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
136 | | const C = MyInt(0b0000_0100u8);
137 | | }
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
--> tests/compile-fail/bitflags_custom_bits.rs:76:1
|
76 | impl Not for MyInt {
| ^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)