Replies: 3 comments 6 replies
-
Could you give an example? It has to do with the order in which macros are applied- from the outside in. So maybe. |
Beta Was this translation helpful? Give feedback.
-
#[proc_macro_attribute]
pub fn add_field(_attr: TokenStream, item: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(item as ItemEnum);
let new_variant = syn::Variant {
attrs: vec![],
ident: Ident::new("Foo", proc_macro2::Span::call_site()),
fields: Fields::Unit,
discriminant: None,
};
input.variants.push(new_variant);
quote!(#input).into()
} error_set! {
#[add_field]
Error = {
Bar
};
} |
Beta Was this translation helpful? Give feedback.
-
I think this may be a limitation of Rust's macro system, since the outside macro is applied first. Which is desired if you don't want to add a field, since the enum will be resolved before the macro is applied. A possible solution for the reverse would be to move #[error_set]
#[add_field]
mod x {
// #[parts(...)] // new syntax for merging error parts
#[add_field_marker]
enum Error {
Bar
}
} This would be a pretty big change to this crate. Before considering such a change, I would like to see a real use case that would benefit from this. Also , off the top of my head, it would likely require a different marker attribute to handle generics in the same way. |
Beta Was this translation helpful? Give feedback.
-
Might there be a way to work with attribute macros that add variants? Currently it's generating impl blocks before applying the attribute macro, resulting in missing match arms.
Beta Was this translation helpful? Give feedback.
All reactions