rust-lang / rust-lang/rust-analyzer

New files in `tests/` give "This file is not included in any crates"

Open
#18,279 9 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When I open a new file in tests/ (e.g. tests/my_test.rs), rust-analyzer gives an unlinked file diagnostic:

This file is not included in any crates, so rust-analyzer can't offer IDE services.

If you're intentionally working on unowned files, you can silence this warning by adding "unlinked-file" to rust-analyzer.diagnostics.disabled in your settings. [unlinked-file]

Once I restart the rust-analyzer process, the file is loaded correctly. This may be related to #9910, but I only have this issue with files under the tests/ directory.

rust-analyzer version: rust-analyzer 2024-09-02

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: Neovim with native LSP

relevant settings: https://github.com/9999years/dotfiles/blob/205a5d1738c5520759512bf82454d04059b3b1b3/config/nvim/init.lua#L911-L949

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 by creating a new tests/my_test.rs file with rust-analyzer and observe the unlinked-file diagnostic before and after restarting the process. Trace how files under tests/ are discovered and included, then verify that a newly created test file is loaded without requiring a restart.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.