Spiritually, this is a good overview, but I have two nits to pick:
This is not true of macros in general.
panic works everywhere because it is in
std, which is special. Macros you define are only visible inside the module where they are defined, unless the module is declared with the
#[macro_use] attribute. Example
(In order to be imported by another crate with
#[macro_use], macros also have to be defined with the
This overstates things a little. A macro can use local variables as long as they are in scope at the point where the macro is defined. But a macro can’t use a variable that will be defined later, nor define a variable that will be used later outside the macro (unless the variable name is passed in as a parameter, as you note).
Side note: Macros defined inside functions can’t be exported with
#[macro_use], which is only meaningful on modules.