Skip to content

Invalid macro expansion when async-trait and duplicate_item macros are used together #13499

Closed
@Veetaha

Description

@Veetaha

I think this is a regression. I don't know when it happened, but judging by the commit date of the code where I see this broken today, it was 5 months ago (May 26th, 2022). I wouldn't leave it like this if it didn't work at that time for sure.

Reproduction repository.

Screenshot image

Code:

use async_trait::async_trait;
use duplicate::duplicate_item;

#[async_trait]
pub trait Foo {
    #[duplicate_item(
        var;
        [foo];
    )]
    async fn foo(&self);
}

pub fn foo(val: &dyn Foo) {


    let _ = val.foo();
}

Result of "Expand macro recursively":

// Recursive expansion of async_trait! macro
// ==========================================

pub trait Foo {
    compile_error! {
      "Unexpected token. Expected substitution identifier or ';' instead."
    }
}

Expected

The usage of duplicate_item here is actually noop. I.e. it just leaves the decorated trait method as is. Rust-analyzer should see this, and correctly resolve the trait method.

Actual

Rust-analyzer fails to expand the macro, so the trait method isn't seen in completions and isn't highlighted.

Meta

rust-analyzer version: 0.3.1258-standalone

rustc version: 1.64.0 (a55dd71d5 2022-09-19)

relevant settings:

This works both with async-trait macro enabled and disabled in the settings via:

"rust-analyzer.procMacro.ignored": {
    "async-trait": ["async_trait"]
}

I have it disabled in the settings during regular development

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions