diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index ec49e48cb..9028d5dae 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -213,15 +213,14 @@ impl Config { }) .collect(); - let mut upper_case_env: HashMap = HashMap::new(); - - if !cfg!(windows) { - upper_case_env = env - .clone() + let upper_case_env = if cfg!(windows) { + HashMap::new() + } else { + env.clone() .into_iter() .map(|(k, _)| (k.to_uppercase().replace("-", "_"), k)) - .collect(); - } + .collect() + }; let cache_rustc_info = match env.get("CARGO_CACHE_RUSTC_INFO") { Some(cache) => cache != "0", @@ -568,13 +567,16 @@ impl Config { fn check_environment_key_case_mismatch(&self, key: &ConfigKey) { if cfg!(windows) { + // In the case of windows the check for case mismatch in keys can be skipped + // as windows already converts its environment keys into the desired format. return; } + match self.upper_case_env.get(key.as_env_key()) { Some(env_key) => { let _ = self.shell().warn(format!( - "Variables in environment require uppercase, - but given variable: {}, contains lowercase or dash.", + "Environment variables require uppercase letters, \ + but the variable: `{}` contains lowercase letters or dashes.", env_key )); } diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index c8dec87a0..5d7d89d5e 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -368,14 +368,32 @@ fn target_in_environment_contains_lower_case() { .env(target_key, "nonexistent-linker") .with_status(101) .with_stderr_contains(format!( - "warning: Variables in environment require uppercase, - but given variable: {}, contains lowercase or dash.", + "warning: Environment variables require uppercase letters, \ + but the variable: `{}` contains lowercase letters or dashes.", target_key )) .run(); } } +#[cargo_test] +#[cfg(windows)] +fn target_in_environment_contains_lower_case_on_windows() { + let p = project().file("src/main.rs", "fn main() {}").build(); + + let target_keys = [ + "CARGO_TARGET_X86_64_UNKNOWN_LINUX_musl_LINKER", + "CARGO_TARGET_x86_64_unknown_linux_musl_LINKER", + ]; + + for target_key in &target_keys { + p.cargo("build -v --target x86_64-unknown-linux-musl") + .env(target_key, "nonexistent-linker") + .without_status() + .run(); + } +} + #[cargo_test] fn cfg_ignored_fields() { // Test for some ignored fields in [target.'cfg()'] tables.