Skip to content

Macros that operate on attributes #8393

Closed
@nikomatsakis

Description

@nikomatsakis

There is no way to write a macro that takes a list of attributes as input, like e.g. this one:


macro_rules! test ( ($nm:ident,
                     $a:inner_attr,
                     $i:item) => (mod $nm { $a $i }); )

test!(a,
      #[cfg(qux)],
      pub fn bar() { })

test!(b,
      #[cfg(not(qux))],
      pub fn bar() { })

#[qux]
fn main() {
    a::bar();
    //~^ ERROR use of undeclared module `a`
    //~^^ ERROR unresolved name
    //~^^^ ERROR unresovled name `a::bar`
    b::bar();
}

I need this for #3678, since I have a macro there for generating wrappers around extern fns and it needs attributes. Pull request forthcoming.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions