rust-lang / rust-lang/rust-analyzer

rust-analyzer doesn't fully respect CARGO_TARGET_DIR set with rust-analyzer.server.extraEnv

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

Nobody has claimed this yet.

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

Description

Rust-analyzer seems to kick off a cargo command in such a way that a CARGO_TARGET_DIR override set with rust-analyzer.server.extraEnv set in rust-analyzer.json in the project root. This issue popped up in trying to address issue #5828 , where rust-analyzer is invalidating my cargo cache during code analysis in a Cargo workspace with sub-crates that have different build targets.

I've made a fairly small repro case to demonstrate the issue at https://github.com/willhodges/rabug. Simply clone into the repo and then open it in VSCode (with the rust-analyzer extension) or Atom (with the ide-rust extension). The target/debug directory is immediately populated during the first rust-analyzer run despite an override of CARGO_TARGET_DIR in the project's .cargo/config. target/check is also populated, so it would seem at least some of the cargo commands rust-analyzer is running do see the override.

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

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

relevant settings: See .cargo/config.toml and rust-analyzer.json in the repository above

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

Clone the linked rabug reproduction and inspect its .cargo/config.toml and rust-analyzer.json settings. Open it in VSCode or Atom, observe which target directories are populated during the first rust-analyzer run, and trace the cargo commands involved. Done means CARGO_TARGET_DIR is respected consistently and the reproduction no longer populates target/debug unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.