Skip to content

#[proc_macro_attribute] doesn't work on trait methods #42493

Closed
@alexcrichton

Description

@alexcrichton

Given this procedural macro:

#![feature(proc_macro)]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn foo(attr: TokenStream, item: TokenStream) -> TokenStream {
    println!("attr: {}", attr);
    println!("item: {}", item);
    item
}

and this crate:

#![feature(proc_macro)]

extern crate foo;

use foo::foo;

trait Trait {
    #[foo]
    fn trait_function(&self);
    #[foo]
    fn trait_function_default(&self) {}
}

fn main() {}

Building:

$ cargo +nightly build
   Compiling foo v0.1.0 (file:///home/alex/code/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.73 secs

I saw no output :(

I find that #[foo] is resolved, it just doesn't seem to get expanded!

Metadata

Metadata

Assignees

Labels

A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions