I understand most of how macro hygiene works in terms of identifiers defined within a macro, however, i don't quite understand how identifier resolution works.
this fails because it looks for an identifier in the calling crate:
So the first one will place the identifier X in the crate it is called from, which could lead to an error if no X is defined.
The second one is executing the quote! macro, and placing the result 10 in the calling crate.
So it would appear that consts are not "inlined" into a macro (as expected), but (proc?) macros are executed within a macro definition... If and only if they are imported by the crate defining the macro?.
What happens if you remove the use quote from the second example?
What happens if you use a macro rules macro?
I think it will run inside of the macro defining crate and its output will be placed into the calling crate, the same as a proc macro, if it's defined. And place the raw tokens if it is not, same as a proc macro.
No, not at all. The macro call to quote::quote! succeeded because the quote crate is in scope for your doctest code.
(If you're thinking "I didn't use quote; in the test" â the line use quote; has almost no effect, and the effect that it does have is irrelevant in this case.)