← ClaudeAtlas

rust-macroslisted

Use when you write or debug a Rust macro — a macro_rules! declarative macro, a derive macro, an attribute macro, or the crate split that ships one. Covers textual scope, macro_use and macro_export, $crate, macro hygiene, fragment specifiers and follow-set restrictions, the recursion limit, format strings from concat! and stringify!, proc-macro crate rules, compile_error! instead of a panic, helper attributes, the two-crate facade and derive split, absolute paths, and narrow generic bounds. Triggers on "macro_rules", "declarative macro", "write a derive macro", "proc macro", "procedural macro", "attribute macro", "macro hygiene", "fragment specifier", "cannot find macro in this scope", "recursion limit reached while expanding", "proc-macro derive panicked", "cyclic package dependency", "cargo expand", "token stream", "quote!", or "syn".
po4yka/rust-skills · ★ 2 · AI & Automation · score 76
Install: claude install-skill po4yka/rust-skills
# Rust macros ## Purpose Write and debug a `macro_rules!` macro, a derive macro, or an attribute macro. Three rules decide whether a macro compiles at all: textual scope, hygiene, and the follow-set restrictions on fragment specifiers. This skill covers those three, the crate split a procedural macro needs, and the paths and bounds its output must emit. It stops at the macro. Which crates a workspace holds and which way its normal dependencies point belong to `rust-crate-architecture`. Every error message and every number below comes from rustc 1.97.0, edition 2024. ## Decide whether you need a macro | You want | Reach for | Why not a macro | | --- | --- | --- | | One body, many types | A generic function, or a blanket impl | Monomorphization already does this | | A constant computed at build time | `const fn`, or a `const { }` block | You add no syntax | | Code generated from a schema or a data file | `build.rs` plus `include!` | The input is not Rust tokens | | Repeated syntax inside one crate | `macro_rules!` | — | | The same trait impl per type, derived from the type's shape | A derive macro | — | | An item rewritten or wrapped | An attribute macro | — | A macro costs compile time, a second crate in the procedural case, diagnostics that point at the invocation instead of the defect, and an IDE that cannot look inside. Take a non-macro row when one fits. ## Route the symptom | Symptom or task | Section | | --- | --- | | `error: cannot find macro ... in this scope`