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 adabb75
Show file tree
Hide file tree
Showing 4 changed files with 646 additions and 14 deletions.
3 changes: 3 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,8 @@ 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]));

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 adabb75

Please sign in to comment.