rust-lang / rust-lang/rust-analyzer

Find all usages skips usages in derives

Open
#15,501 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider the following minimal example:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct X {
    x: i32,
}

fn main() {
    println!("Hello, world!");
}

Use f12 on Deserialize to go to definition, then shift-alt-f12 to find all references. Note that the only reference in main.rs is in the use, not on the derive. This was initially found at https://github.com/rust-lang/rust-analyzer/pull/14723#issuecomment-1674760317. I believe the bug holds more generally with usages in proc-macros. This causes issues when running remove unused imports in a file which has serde derives in it.

rust-analyzer version: rust-analyzer version: 0.3.1631-standalone (83b3ba1b8 2023-08-19)

rustc version: rustc 1.73.0-nightly (0d95f9132 2023-07-26)

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 report in main.rs using the minimal serde example, then compare F12 definition results with Shift-Alt-F12 references for Deserialize. Done means usages inside the derive are included alongside the use statement, and removing unused imports no longer treats the serde import as unused.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.