Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Attribute (inner) macro on a Rust module losing all hygiene
I have an attribute macro that is invoked as an inner attribute of a module. The problem is that all the macro hygiene points not to the module actual content, but to the module declaration in the parent module. This applies even to individual statements, function declarations etc., if you parse the module content and inspect the spans.
This obviously becomes a problem if there's an error in the module content, b/c as soon as it is processed by my macro all spans are lost essentially. It happens even if you just
#[proc_macro_attribute]
pub fn my_macro(attr: TokenStream, item: TokenStream) -> TokenStream {
return item;
}
Thing is, what I need to do is to parse the module content and do stuff with it, with module as a whole. If I use this as an inner attribute, I get module.content
, but the spans are all just pointing to the module declaration, and if I try to apply it as an outer attribute, then module.content
is None
.
Is this an expected behavior or a bug? Is there anything I can do?
2 posts - 1 participant
🏷️ Rust_feed