Skip to content

Declarative attribute/derive macros are not supported #21043

@Zalathar

Description

@Zalathar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionB-unstableunstable featureC-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions