rust-analyzer: Rust analyzer incorrectly analyzes file as "Does not belong to any crate"

rust-analyzer version: (eg. output of “Rust Analyzer: Show RA Version” command) rust-analyzer version: 5d5bbec9b 2022-05-08 nightly

rustc version: (eg. output of rustc -V) rustc 1.62.0-nightly (52ca603da 2022-04-12)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME) Unknown.

In my project here: https://github.com/spacestation13/BYONDDiffBots

Rust Analyzer won’t load crates/mapdiffbot2/src/github_processor.rs as part of the mapdiffbot2 crate. Instead, it just reports “File info: Does not belong to any crate”, as seen below.

Problem shown in VSCode

This doesn’t happen with any other files in the repository. crates/mapdiffbot2/src/rendering.rs loads fine:

Example of problem not occuring

Furthermore, on the idb2 branch, crates/icondiffbot2/src/github_processor.rs does not have the issue, while crates/mapdiffbot2/src/github_processor.rs does, despite having the same file name, and being included with the same mod statement in the respective main.rs.

Example of problem not occuring Example of problem occuring in file of the same name

Please let me know if there is any more information I can provide, I’m not familiar with how to debug rust-analyzer.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Keeps happening to me too… I noticed its most often when I create a new file and copy paste some code. Can’t tell which part does that exactly, but either way very annoying.

EDIT : use "rust-analyzer.showUnlinkedFileNotification": false, in your settings JSON to make this issue go byebye

Make sure to check your vscode workspace settings don’t have any linkedProjects settings configured. Other than that, please open a new issue ideally with a repo that reproduces this.

Can confirm that what @nngeorgiy noticed it true. There is an issue here, please reopen.

I’m being bombarded by the same file does not belong to prompts, but my circumstances are different. First, there’s an additional error right after starting VS Code:

[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/jammy/Workspace/notes/./Cargo.toml, Some(Version { major: 1, minor: 68, patch: 2 }): Failed to run `cd "/home/jammy/Workspace/notes" && "cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/jammy/Workspace/notes/./Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: manifest path `/home/jammy/Workspace/notes/./Cargo.toml` does not exist

The difference is, unlike posters above, I use multiple root folders in my workspace, and the notes folder is just a bunch of .md files. The only Rust code is in the hello folder, and it’s just an empty project courtesy of cargo. When I reorder the two folders in VS Code so that the hello folder is first, all the errors vanish. When I reorder them back, they reappear. It looks to me that the VS Code extension just grabs the first root folder in the workspace and ignores the rest?

I use rust-analyzer v0.3.1481 with rustc 1.68.2. The issue reproduces with all extensions other than rust-analyzer disabled and VS Code restarted.

Also keeps happening to me for some reason. whenever I open Cargo.toml. This didn’t happen a few months ago. image