Skip to content

Fix [env] in .cargo/config.toml overriding process environment variables#21995

Merged
ChayimFriedman2 merged 3 commits intorust-lang:masterfrom
smihica:fix/cargo-config-env-override
Apr 9, 2026
Merged

Fix [env] in .cargo/config.toml overriding process environment variables#21995
ChayimFriedman2 merged 3 commits intorust-lang:masterfrom
smihica:fix/cargo-config-env-override

Conversation

@smihica
Copy link
Copy Markdown
Contributor

@smihica smihica commented Apr 8, 2026

Fixes #21994

cargo_config_env() only checked extra_env (from 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 [env] 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.

The existing test used generic variable names like CARGO_WORKSPACE_DIR and TEST which could collide with real process environment variables (rust-analyzer's own .cargo/config.toml sets CARGO_WORKSPACE_DIR). Renamed them to use the RA_TEST_ prefix.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2026
@rustbot

This comment has been minimized.

@smihica smihica force-pushed the fix/cargo-config-env-override branch 2 times, most recently from 7d225ce to 69ba5b6 Compare April 8, 2026 07:49
smihica added 2 commits April 8, 2026 08:33
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
@smihica smihica force-pushed the fix/cargo-config-env-override branch from 69ba5b6 to 057a2f6 Compare April 8, 2026 08:34
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 9, 2026
Merged via the queue into rust-lang:master with commit ea8c16c Apr 9, 2026
17 of 18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[env] in .cargo/config.toml overrides process environment variables

3 participants