rust-lang / rust-lang/rust-analyzer
Incorrect Codelens Function Reference Count
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Summary
Codelens reference count for a function is incorrect when #[post("/hello")] attribute is used. Clicking on the codelens reference count link (opening the expanded view) shows a smaller number of references and yet still incorrect. Removing the post attribute shows the correct reference count.
Information
OS / VSCode: win11/vscode1.79.1(user setup)
rust-analyzer version: 0.3.1549-standalone (d567091f4 2023-06-11)
rustc: 1.70.0 (90c541806 2023-05-31)
Link to the repository that reproduces this issue: https://github.com/jpnws/example
Before proceeding, enable Rust-analyzer > Lens > References > Method.
In the end, you will see the following Rust workspace folder structure.
Dependencies: just actix-web and tokio.
Steps to reproduce
- Create a folder called
exampleand createexample/Cargo.tomlfile. - In
example/Cargo.toml, write:
[workspace]
members = ["main", "lib"]
- Create
example/main/Cargo.tomlandexample/main/src/main.rs. - In
example/main/Cargo.toml, write:
[package]
name = "main"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
lib = { path = "../lib" }
- In
example/main/src/main.rs, write:
use actix_web::{web, App, HttpResponse, HttpServer};
#[tokio::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(HttpResponse::Ok))
.service(lib::hello)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
- Create
example/lib/Cargo.tomlandexample/lib/src/lib.rs. - In
example/lib/Cargo.toml, write:
[package]
name = "lib"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4"
- In
example/lib/src/lib.rs, write:
use actix_web::{post, HttpRequest};
#[post("/hello")]
pub async fn hello(_req: HttpRequest) -> String {
"Hello".to_owned()
}
- In
examplefolder, runcargo build. - Open
example/lib/src/lib.rsand observe the codelens reference count above thehellofunction.
Expected
The number of references to the lib::hello function should be 1.
Actual
The numer of references to the lib::hello function is 6.
Thoughts
- Clicking on the codelens "6 references" link shows 2 references in the expanded view, one in
example/main/src/main.rsand one to the function definition itself. It is odd to see that the expanded view shows 2 references when it claimed the function has 6. Also, including the function itself as a reference seems odd.
- After removing
#[post("/hello")]attribute, the codelens shows1 reference. Clicking it shows the correct reference:lib::helloinexample/main/src/main.rs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the workspace from main/src/main.rs, lib/src/lib.rs, and the two Cargo.toml files, then run cargo build and inspect the references codelens on lib::hello with and without #[post("/hello")]. Done means the attributed function reports one reference and the expanded view lists only its use in main/src/main.rs, without counting the definition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100