rust-lang / rust-lang/rust-analyzer

Spurious "does not belong to a cargo project" when files are cfg'd out

Open
#15,998 2 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

When a file is opened that belongs to a project but iscfg-disabled on the current configuration, RA shows a warning:

"This rust file does not belong to a loaded cargo project. It looks like it might belong to the workspace at /home/r/src/rust/compiler-builtins/Cargo.toml, do you want to add it to the linked Projects?"

However clicking the "yes" button does not help; it will add the project and then still show the same warning again next time. It will even show the warning when that exact project file has already been added, or when it is the "root" project file that is added by default when the list is empty.

This is easily reproduced for instance in the compiler-builtins crate, in files like src/mem/impls.rs or src/arm_linux.rs.

Maybe it would make sense to do a quick check whether the Cargo.toml file it suggests is already loaded, and only show the warning when it is not?

rust-analyzer version: rust-analyzer version: 0.3.1748-standalone

rustc version: rustc 1.76.0-nightly (b10cfcd65 2023-11-29)

relevant settings: -

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 warning with compiler-builtins files such as src/mem/impls.rs or src/arm_linux.rs under the reported rust-analyzer version and inspect the linked-project warning path. Verify the behavior with the suggested Cargo.toml both loaded and absent; done means cfg-disabled files no longer trigger the warning when their project is already loaded.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.