Skip to content

Weird interaction with decl macros when automock attribute is forwarded #680

@Nekrolm

Description

@Nekrolm

Hi, I've encountered weird error for cases when automock attribute is forwarded or added by declarative macro:

The minimal example is following:

macro_rules! decl_trait {
    (
        
        #[$attr:meta]
        $($t:tt)*
        
    ) => {
        #[$attr]
        $($t)* 

    };
}

decl_trait!(
    #[async_trait::async_trait] // this works as expected
    trait Foo {
        async fn bar(&self);
    }

);

decl_trait!(
    #[mockall::automock] // compilation error: misparsing?
    trait Bar {
        fn bar(&self);
    }
);

an error:

3 |           #[$attr]
   |           ^^^^^^^^
   |           |
   |           `self` value is a keyword only available in methods with a `self` parameter
   |           this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
rustc 1.92.0 (ded5c06cf 2025-12-08)
mockall = '0.14'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions