Skip to content

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

@willhodges

Description

@willhodges

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 (5342f47 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-supportCategory: support questions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions