I am working on a compiler plugin that uses custom attributes to annotate functions and needs to later use information of those attributes in the LintPass.
So for the following code, when visiting the function test()
in a LintPass, I need to know that the function was annotated with foo="bar"
.
#[foo="bar"]
fn test() {}
My first attempt to solve this was to use a global hashmap that maps function names to those attributes. This hashmap was populated in the syntax extension phase of the plugin. However using function names as keys won't work when working with ImplItem
, because during the syntax expansion stage, the plugin has no access to the name of the implemented trait or struct, so for the follwing code, it can distinguish between the two test()
functions
#[foo="bar"]
fn test() {}
impl MyStruct {
#[foo="yo"]
fn test(){}
}
I also tried using ast node ids as keys to the hashmap, but the node ids change between the expansion and lint stage.
Any ideas how to solve this problem?