rust-lang / rust-lang/rust-analyzer

Finding references confused by having both main.rs and lib.rs

Open
#12,767 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer 0.0.0 (5342f47f4 2022-07-09)

rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)

relevant settings: Neovim with coc-rust-analyzer

I have a binary crate with a main.rs, but in order to add benchmarks I needed to add a lib.rs to expose a few methods. I noticed that if I try to find usages of a symbol inside the library from inside a module included in the library, it won't find usages outside of the library's module tree.

a.rs

pub struct A;

main.rs

mod a;

fn main() {
    let aa = a::A;
}

lib.rs

mod a;

From a.rs I cannot find the usage of a::A in main.rs. If I remove the lib.rs file then finding usages works as expected. If I try to find usages from main.rs I get all of the usages I expect, though if I add any in lib.rs they won't be found. Maybe the proper solution would be to make my project into a workspace, but I really don't want to restructure everything and expose a bunch of disparate internal methods publicly just to make this work. I wasn't able to figure out a way to tell it to ignore lib.rs or prioritize main.rs.

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 issue with the shown a.rs, main.rs, and lib.rs files using Neovim with coc-rust-analyzer. Start by tracing how rust-analyzer resolves references when both crate targets exist; done means finding usages from a.rs includes the use in main.rs without requiring the crate to be restructured.

Written by the indexing model from the issue text.

Assessment

Tech stack
neovim, rust
Domain
devtools
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.