Can macros match against constant arguments instead of literals?

No.

Macros operate on the Abstract Syntax Tree, so they reason at the syntactic level: they reason about tokens and their spelling.

For example:

fn main() {
    let v = 3;
}

In this case, the AST will look something like:

fn main
    \_ let-binding v
        \_ literal 3

If you ask a macro whether v is 3, it will look at you funny, and wonder why you would try comparing a variable name and a literal.

Leave a Comment