Skip to content

Commit

Permalink
[derive] Test TryFromBytes output on dataful enums
Browse files Browse the repository at this point in the history
Makes progress on #367, #1634
  • Loading branch information
joshlf committed Sep 16, 2024
1 parent 558843e commit 760e46f
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 9 deletions.
3 changes: 2 additions & 1 deletion zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ syn = "2.0.46"
once_cell = "=1.9"
rustversion = "1.0"
static_assertions = "1.1"
synstructure = "0.13.1"
#synstructure = "0.13.1"
synstructure = { path = "../../synstructure" }
testutil = { path = "../testutil" }
# Pinned to a specific version so that the version used for local development
# and the version used in CI are guaranteed to be the same. Future versions
Expand Down
8 changes: 4 additions & 4 deletions zerocopy-derive/src/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) fn generate_tag_enum(repr: &EnumRepr, data: &DataEnum) -> TokenStream
#[repr(#repr)]
#[allow(dead_code)]
enum ___ZerocopyTag {
#(#variants),*
#(#variants,)*
}
}
}
Expand Down Expand Up @@ -305,9 +305,9 @@ pub(crate) fn derive_is_bit_valid(

#tag_enum

type ___ZerocopyTagPrimitive = ::zerocopy::util::macro_util::SizeToTag<{
core_reexport::mem::size_of::<___ZerocopyTag>()
}>;
type ___ZerocopyTagPrimitive = ::zerocopy::util::macro_util::SizeToTag<
{ core_reexport::mem::size_of::<___ZerocopyTag>() },
>;

#tag_consts

Expand Down
2 changes: 1 addition & 1 deletion zerocopy-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ fn derive_try_from_bytes_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_m
// validities of its fields, so this is a sound implementation of
// `is_bit_valid`.
fn is_bit_valid<A: ::zerocopy::pointer::invariant::Aliasing + ::zerocopy::pointer::invariant::AtLeast<::zerocopy::pointer::invariant::Shared> >(
mut candidate: ::zerocopy::Maybe<Self, A>
mut candidate: ::zerocopy::Maybe<Self, A>,
) -> bool {
true #(&& {
// SAFETY:
Expand Down
Loading

0 comments on commit 760e46f

Please sign in to comment.