rust-lang / rust-lang/rust-analyzer

Range hover inside macro is wrong

Open
#13,931 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-hover A-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer version: 0.3.1348-standalone (643bc02de 2023-01-01)

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

macro_rules! test_macro {
    ($e: expr) => {
        {
            let _ = $e;
            ()
        }
    };
}

fn test() {
    let a = test_macro!(5 + 5);
    //                  ^^^^^    hover show ()
    let b = 5 + 5;
    //      ^^^^^ hover show i32
}

Actual:

When I hover over 5 + 5, RA shows error type (), it seems that RA marks the whole test_macro!(5 + 5) as a hover range.

image
image

Excepted:

Show i32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hover behavior with the Rust macro example in the issue, comparing the macro argument with the direct expression. Trace rust-analyzer's hover range handling across macro expansion, and consider the issue complete when hovering 5 + 5 inside test_macro! reports i32 rather than ().

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.