In a proc_macro_attribute procedural macro, how to get the full TypePath of some Type?

Is it possible to get the full TypePath inside a procedural macro for a some type in the context of the macro?

For example how to check of the return value is of my_crate::SomeType, so far I only manged to get the SomeType path.

use some_other_create::SomeType;

#[<my_macro_name>]
pub trait SomeTrait {
    fn do() -> SomeType; // here I only get the partial type info
}

You can't, macros only get to see the tokens that the user wrote.

Macros are able to create types, or prevent types from being created, so they have to finish running before types start to exist. If macros were able to see the types, that would create chicken-egg problems.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.