Fix [env] in .cargo/config.toml overriding process environment variables#21995
Merged
ChayimFriedman2 merged 3 commits intorust-lang:masterfrom Apr 9, 2026
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
7d225ce to
69ba5b6
Compare
cargo_config_env() only checked extra_env (rust-analyzer.cargo.extraEnv) when deciding whether to skip an existing variable, but never checked the actual process environment via std::env::var. This caused config.toml values to unconditionally override real environment variables even without force = true, diverging from Cargo's behavior. Additionally, plain string entries (e.g. `KEY = "value"`) skipped the force check entirely. When a process env var takes precedence, its value is now inserted into the Env so that env!/option_env! resolution stays correct. Fixes rust-lang#21994
69ba5b6 to
057a2f6
Compare
ChayimFriedman2
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21994
cargo_config_env()only checkedextra_env(fromrust-analyzer.cargo.extraEnv) when deciding whether to skip an existing variable, but never checked the actual process environment viastd::env::var. This caused config.toml[env]values to unconditionally override real environment variables even withoutforce = true, diverging from Cargo's behavior.Additionally, plain string entries (e.g.
KEY = "value") skipped the force check entirely.The existing test used generic variable names like
CARGO_WORKSPACE_DIRandTESTwhich could collide with real process environment variables (rust-analyzer's own.cargo/config.tomlsetsCARGO_WORKSPACE_DIR). Renamed them to use theRA_TEST_prefix.