Skip to content

Commit

Permalink
Merge pull request #403 from KodrAus/chore/fix-msgs
Browse files Browse the repository at this point in the history
Update error messages and zerocopy
  • Loading branch information
KodrAus committed Mar 21, 2024
2 parents 9c92890 + a1b2612 commit aa84edf
Show file tree
Hide file tree
Showing 6 changed files with 2,946 additions and 11 deletions.
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)

0 comments on commit aa84edf

Please sign in to comment.