Skip to content

Commit

Permalink
[derive] Overhaul repr parsing
Browse files Browse the repository at this point in the history
Represent the result of parsing all `#[repr(...)]` attributes on a type
as a high-level type which is only capable of representing valid
combinations of `#[repr(...)]` attributes and processes them into a
concise representation that's easier for high-level code to work with.

This prepares us to more easily fix #1748
  • Loading branch information
joshlf committed Sep 25, 2024
1 parent 6b7a012 commit c0e3471
Show file tree
Hide file tree
Showing 4 changed files with 635 additions and 14 deletions.
4 changes: 4 additions & 0 deletions zerocopy-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod ext;
#[cfg(test)]
mod output_tests;
mod repr;
mod repr2;

use proc_macro2::{TokenStream, TokenTree};
use quote::ToTokens;
Expand Down Expand Up @@ -790,6 +791,9 @@ fn derive_from_bytes_union(ast: &DeriveInput, unn: &DataUnion) -> proc_macro2::T
}

fn derive_into_bytes_struct(ast: &DeriveInput, strct: &DataStruct) -> proc_macro2::TokenStream {
let _repr =
try_or_print!(repr2::StructUnionRepr::from_attrs(&ast.attrs).map_err(|e| vec![e.into()]));

let reprs = try_or_print!(STRUCT_UNION_INTO_BYTES_CFG.validate_reprs(ast));
let is_transparent = reprs.contains(&StructRepr::Transparent);
let is_packed = reprs.contains(&StructRepr::Packed);
Expand Down
Loading

0 comments on commit c0e3471

Please sign in to comment.