The Rust compiler has unstable support for using macro_rules! macros in attribute position or as derives, by prefixing individual rules with attr() or derive():
#![feature(macro_attr)]
#![feature(macro_derive)]
macro_rules! my_macro {
attr() ( $($tt:tt)* ) => { /* TODO */ };
derive() ( $($tt:tt)* ) => { /* TODO */ };
( $($tt:tt)* ) => { /* TODO */ };
}
// Use as bang macro:
my_macro!(...);
// Use as attribute macro:
#[my_macro]
struct MyStructA;
// Use as derive macro:
#[derive(my_macro)]
struct MyStructB;
rust-analyzer hasn't added support for this macro_rules! syntax, so trying to use it results in a cryptic “expected subtree” error on the macro's name, not on the offending rules.
Furthermore, because rust-analyzer doesn't know how to expand declarative attribute/derive macros, any items declared by those expansions are not visible to r-a, making autocomplete and other IDE features much less helpful.
macro_rules!attribute macros" (macro_attr) rust#143547macro_rules!derive macros" (macro_derive) rust#143549The Rust compiler has unstable support for using
macro_rules!macros in attribute position or as derives, by prefixing individual rules withattr()orderive():rust-analyzer hasn't added support for this
macro_rules!syntax, so trying to use it results in a cryptic “expected subtree” error on the macro's name, not on the offending rules.Furthermore, because rust-analyzer doesn't know how to expand declarative attribute/derive macros, any items declared by those expansions are not visible to r-a, making autocomplete and other IDE features much less helpful.