Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn open_enum_impl(

// To make `match` seamless, derive(PartialEq, Eq) if they aren't already.
let mut extra_derives = vec![quote!(::core::cmp::PartialEq), quote!(::core::cmp::Eq)];
let mut extra_attrs: Vec<TokenStream> = Vec::with_capacity(enum_.attrs.len());

let mut make_custom_debug_impl = false;
for attr in &enum_.attrs {
Expand Down Expand Up @@ -204,7 +205,7 @@ fn open_enum_impl(
_ => {}
}
if include_in_struct {
struct_attrs.push(attr.to_token_stream());
extra_attrs.push(attr.to_token_stream());
}
}

Expand All @@ -228,6 +229,7 @@ fn open_enum_impl(
if !extra_derives.is_empty() {
struct_attrs.push(quote!(#[derive(#(#extra_derives),*)]));
}
struct_attrs.append(&mut extra_attrs);

let alias_check = if allow_alias {
TokenStream::default()
Expand Down
7 changes: 7 additions & 0 deletions tests/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ fn extended_embedded_enum_struct_debug() {
);
assert!(debug_str.contains("Red"), "{debug_str}");
}

// Fails to build if `#[zerocopy(...)]` is re-ordered above derive attrs.
#[repr(u8)]
#[open_enum]
#[derive(zerocopy::IntoBytes)]
#[zerocopy(crate = "zerocopy")]
enum AttrOrder {}
Loading