Skip to content

Commit c85990a

Browse files
committed
Be more robust regarding attribute ordering in proc macros.
1 parent 0db4f8e commit c85990a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

macros/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ pub fn phf_map(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
9494
/// Panic if the first attribute isn’t `#[foo(…)]` with the given name,
9595
/// or return the parameters.
9696
fn list_attr<'a>(input: &'a syn::DeriveInput, expected_name: &str) -> &'a [syn::NestedMetaItem] {
97-
match input.attrs[0].value {
98-
syn::MetaItem::List(ref name, ref nested) if name == expected_name => {
99-
nested
100-
}
101-
_ => {
102-
panic!("expected a {} attribute", expected_name)
97+
for attr in &input.attrs {
98+
match attr.value {
99+
syn::MetaItem::List(ref name, ref nested) if name == expected_name => {
100+
return nested
101+
}
102+
_ => {}
103103
}
104104
}
105+
panic!("expected a {} attribute", expected_name)
105106
}
106107

107108
/// Panic if `sub_attr` is not a name-value like `foo = "…"` with the given name,

0 commit comments

Comments
 (0)