Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1745,8 +1745,13 @@ impl Config {
.env_config
.try_borrow_with(|| self.get::<EnvConfig>("env"))?;

if env_config.get("CARGO_HOME").is_some() {
bail!("setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
for disallowed in &["CARGO_HOME", "RUSTUP_HOME"] {
if env_config.contains_key(*disallowed) {
bail!(
"setting the `{disallowed}` environment variable is not supported \
in the `[env]` configuration table"
);
}
}

Ok(env_config)
Expand Down
42 changes: 22 additions & 20 deletions tests/testsuite/cargo_env_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,31 @@ fn env_invalid() {
}

#[cargo_test]
fn env_no_cargo_home() {
fn env_no_disallowed() {
// Checks for keys that are not allowed in the [env] table.
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file(
"src/main.rs",
r#"
fn main() {
}
"#,
)
.file(
".cargo/config",
r#"
[env]
CARGO_HOME = "/"
"#,
)
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
.file("src/lib.rs", "")
.build();

p.cargo("check")
.with_status(101)
.with_stderr_contains("[..]setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
.run();
for disallowed in &["CARGO_HOME", "RUSTUP_HOME"] {
p.change_file(
".cargo/config",
&format!(
r#"
[env]
{disallowed} = "foo"
"#
),
);
p.cargo("check")
.with_status(101)
.with_stderr(&format!(
"[ERROR] setting the `{disallowed}` environment variable \
is not supported in the `[env]` configuration table"
))
.run();
}
}

#[cargo_test]
Expand Down