Split finding and processing proc macro attributes
We're going to add another attribute that can't be combined with this one.
This commit is contained in:
parent
b91a02baa6
commit
a9185dff21
|
@ -33,17 +33,30 @@ pub fn derive_params(input: TokenStream) -> TokenStream {
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We'll add another attribute for persistent fields later, and that's going to be mutually
|
||||||
|
// exclusive with this id attribute
|
||||||
|
let mut id_attr = None;
|
||||||
for attr in field.attrs {
|
for attr in field.attrs {
|
||||||
let list = match attr.parse_meta() {
|
match attr.parse_meta() {
|
||||||
Ok(syn::Meta::List(list)) if list.path.is_ident("id") => list,
|
Ok(syn::Meta::List(list)) if list.path.is_ident("id") => {
|
||||||
_ => continue,
|
if id_attr.is_none() {
|
||||||
|
id_attr = Some(list);
|
||||||
|
} else {
|
||||||
|
return syn::Error::new(attr.span(), "Duplicate id attribute")
|
||||||
|
.to_compile_error()
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(list) = id_attr {
|
||||||
let param_id =
|
let param_id =
|
||||||
match list.nested.first() {
|
match list.nested.first() {
|
||||||
Some(syn::NestedMeta::Lit(syn::Lit::Str(s))) => s.value(),
|
Some(syn::NestedMeta::Lit(syn::Lit::Str(s))) => s.value(),
|
||||||
_ => return syn::Error::new(
|
_ => return syn::Error::new(
|
||||||
attr.span(),
|
list.span(),
|
||||||
"The id attribute should have a single string argument: #[id(\"foo_bar\")]",
|
"The id attribute should have a single string argument: #[id(\"foo_bar\")]",
|
||||||
)
|
)
|
||||||
.to_compile_error()
|
.to_compile_error()
|
||||||
|
|
Loading…
Reference in a new issue