Skip to content

Commit

Permalink
Fix type arity error in padding check
Browse files Browse the repository at this point in the history
Use `Self` in padding check instead of type name.

Fixes #1642

Makes progress towards #671
  • Loading branch information
jswrenn committed Oct 7, 2024
1 parent 1271aa0 commit 100668b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
4 changes: 2 additions & 2 deletions zerocopy-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,10 @@ fn impl_block<D: DataExt>(
let t = tag.iter();
parse_quote! {
(): ::zerocopy::util::macro_util::PaddingFree<
#type_ident,
Self,
{
#validator_context
::zerocopy::#validator_macro!(#type_ident, #(#t,)* #(#variant_types),*)
::zerocopy::#validator_macro!(Self, #(#t,)* #(#variant_types),*)
}
>
}
Expand Down
21 changes: 21 additions & 0 deletions zerocopy-derive/tests/ui-msrv/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this
|
= 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
--> tests/ui-msrv/enum.rs:576:7
|
576 | 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
--> tests/ui-msrv/enum.rs:136:9
|
Expand Down Expand Up @@ -383,3 +391,16 @@ error[E0277]: the trait bound `(): PaddingFree<IntoBytes3, true>` is not satisfi
<() as PaddingFree<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: generic `Self` types are currently not permitted in anonymous constants
--> tests/ui-msrv/enum.rs:573:10
|
573 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> tests/ui-msrv/enum.rs:573:10
|
573 | #[derive(IntoBytes)]
| ^^^^^^^^^
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 6 additions & 0 deletions zerocopy-derive/tests/ui-nightly/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,9 @@ enum IntoBytes4 {
enum IntoBytes5 {
A(u32),
}

#[derive(IntoBytes)]
#[repr(u8)]
enum IntoBytes6<T> {
A(T),
}
22 changes: 22 additions & 0 deletions zerocopy-derive/tests/ui-nightly/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this
|
= 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
--> tests/ui-nightly/enum.rs:576:7
|
576 | 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
--> tests/ui-nightly/enum.rs:19:8
|
Expand Down Expand Up @@ -487,6 +496,19 @@ 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
--> tests/ui-nightly/enum.rs:573:10
|
573 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> tests/ui-nightly/enum.rs:573:10
|
573 | #[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 `bool: FromBytes` is not satisfied
--> tests/ui-nightly/enum.rs:191:10
|
Expand Down
7 changes: 4 additions & 3 deletions zerocopy-derive/tests/ui-nightly/struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> tests/ui-nightly/struct.rs:127:8
--> tests/ui-nightly/struct.rs:125:10
|
127 | struct IntoBytes4 {
| ^^^^^^^^^^ doesn't have a size known at compile-time
125 | #[derive(IntoBytes)]
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `IntoBytes4`, the trait `Sized` is not implemented for `[u8]`, which is required by `IntoBytes4: macro_util::__size_of::Sized`
note: required because it appears within the type `IntoBytes4`
Expand All @@ -350,6 +350,7 @@ note: required by a bound in `macro_util::__size_of::size_of`
|
| 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
--> tests/ui-nightly/struct.rs:129:8
Expand Down
21 changes: 21 additions & 0 deletions zerocopy-derive/tests/ui-stable/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ error: must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this
|
= 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
--> tests/ui-stable/enum.rs:576:7
|
576 | 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
--> tests/ui-stable/enum.rs:19:8
|
Expand Down Expand Up @@ -451,6 +459,19 @@ error[E0277]: `IntoBytes3` has inter-field padding
= 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
--> tests/ui-stable/enum.rs:573:10
|
573 | #[derive(IntoBytes)]
| ^^^^^^^^^
|
note: not a concrete type
--> tests/ui-stable/enum.rs:573:10
|
573 | #[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 `bool: FromBytes` is not satisfied
--> tests/ui-stable/enum.rs:191:10
|
Expand Down
7 changes: 4 additions & 3 deletions zerocopy-derive/tests/ui-stable/struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ error[E0277]: `IntoBytes3` has inter-field padding
= 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
--> tests/ui-stable/struct.rs:127:8
--> tests/ui-stable/struct.rs:125:10
|
127 | struct IntoBytes4 {
| ^^^^^^^^^^ doesn't have a size known at compile-time
125 | #[derive(IntoBytes)]
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `IntoBytes4`, the trait `Sized` is not implemented for `[u8]`, which is required by `IntoBytes4: macro_util::__size_of::Sized`
note: required because it appears within the type `IntoBytes4`
Expand All @@ -311,6 +311,7 @@ note: required by a bound in `macro_util::__size_of::size_of`
|
| 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
--> tests/ui-stable/struct.rs:129:8
Expand Down

0 comments on commit 100668b

Please sign in to comment.