rust-syntax-macros-declarative
Installation
SKILL.md
rust-syntax-macros-declarative
The mechanics of declarative macros (macro_rules!) in Rust: matcher and transcriber syntax, every fragment specifier, repetition operators, follow-set restrictions, mixed-site hygiene, $crate, TT-munching recursion, #[macro_export] and #[macro_use] scoping, and the edition 2024 expr widening.
Cross-references: [[rust-syntax-macros-procedural]] (when to graduate to proc-macros) [[rust-syntax-edition-2024]] (edition 2024 expr widening, pat 2021 widening) [[rust-syntax-pattern-matching]] (same matcher-style mindset).
When to use this skill
- User writes a
macro_rules! my_macro { ... }and the matcher does not compile or does not match the call site - User asks "which fragment specifier should I use for X" (ident vs expr vs tt vs path)
- User writes a repetition
$( ... )*and gets E0617 ("ambiguity") or duplicate-binding errors - User writes
#[macro_export]and the macro fails to find its own helper items from a downstream crate - User implements a counter / TT-muncher and hits "recursion limit reached"
- User upgrades to edition 2024 and an
exprfragment now matches_orconst { ... }where it did not before - User asks "what is
$crate", "what is$tt", "why does my macro see my outerxand not the caller'sx" - User mixes
#[macro_use]with the 2018+ path-based import and is confused which one to use