rust-lang / rust-lang/rust-analyzer

`ref` snippet shadowed by `ref` keyword in macro

Open
#20,263 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion 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: 0.3.2539-standalone

rustc version: rustc 1.90.0-nightly (a84ab0ce6 2025-07-06)

editor or extension: Vscode, Rust Analyzer

relevant settings: N/A

code snippet to reproduce:

use std::convert::identity;

fn main() {
    let num = 42;
    println!("{}", identity(num.re))
}

Rust Analyzer Suggestions:

Image

After writing the whole keyword:

Image

This issue is kind of difficult to reproduce, as everything works as expected in e.g. the dbg! macro, outside of a macro, or when removing the outer identity function. I am not sure exactly what triggers it, but this combination of a println! and the identity function is enough to trigger it.

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 snippet in rust-analyzer using VS Code, comparing the println! case with dbg!, code outside a macro, and the version without the outer identity function. Trace the completion behavior for ref in the macro context; done means the ref snippet is no longer incorrectly shadowed or suggested as the ref keyword.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.