Skip to content

Resolving variable references is not working as expected in function that is annotated with proc macro #12050

@FylmTM

Description

@FylmTM

rust-analyzer version: 65fbe0a 2022-04-18 stable
rustc version: rustc 1.60.0 (7737e0b5c 2022-04-04)
relevant settings: -

When annotating function with proc-macro, resolving references inside such a function does not behaves as expected:

  • Variable references are no longer highlighted
  • Pressing "Go to definition" on variable declaration does not open reference list

In my case, this is tracing::instrument proc macro.

Code example:

struct Struct { field: i32 }


#[tracing::instrument]
fn test_with_instrumentation() {
    let variable = Struct { field: 42 };

    variable.field;
    variable.field;

}

fn test_without_instrumentation() {
    let variable = Struct { field: 42 };

    variable.field;
    variable.field;
}

Here how it looks like in function that is not annotated:
image

You can see that I can get a list of references (when executing go to definition on variable declaration) and references are highlighted with gray box.

Here how it looks like in function that is annotated:
image
Go to definition does nothing, and references are not highlighted.

However if I try go to definition on one of usages, it will jump me to declaration.

I tried to add this configuration in VS Code, but it did not made any difference:

    "rust-analyzer.procMacro.ignored": {
        "tracing": [
            "instrument"
        ]
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-idegeneral IDE featuresA-macromacro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions