diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 1db5b9a3c98..ab283aa2481 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -1581,20 +1581,21 @@ impl GlobalContext { where F: FnMut(&Path) -> CargoResult<()>, { - let mut stash: HashSet = HashSet::new(); + let mut seen_dir = HashSet::new(); for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) { - if let Some(path) = self.get_file_path(¤t.join(".cargo"), "config", true)? { + let config_root = current.join(".cargo"); + if let Some(path) = self.get_file_path(&config_root, "config", true)? { walk(&path)?; - stash.insert(path); } + seen_dir.insert(config_root); } // Once we're done, also be sure to walk the home directory even if it's not // in our history to be sure we pick up that standard location for // information. - if let Some(path) = self.get_file_path(home, "config", true)? { - if !stash.contains(&path) { + if !seen_dir.contains(home) { + if let Some(path) = self.get_file_path(home, "config", true)? { walk(&path)?; } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 6d0a3ff8ef2..8f9092c2fb2 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -16,7 +16,7 @@ use cargo::CargoResult; use cargo_test_support::compare::assert_e2e; use cargo_test_support::prelude::*; use cargo_test_support::str; -use cargo_test_support::{paths, project, symlink_supported, t}; +use cargo_test_support::{paths, project, project_in_home, symlink_supported, t}; use cargo_util_schemas::manifest::TomlTrimPaths; use cargo_util_schemas::manifest::TomlTrimPathsValue; use cargo_util_schemas::manifest::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; @@ -299,6 +299,26 @@ f1 = 1 assert_e2e().eq(&output, expected); } +#[cargo_test] +fn home_config_works_without_extension() { + write_config_at( + paths::cargo_home().join("config"), + "\ +[foo] +f1 = 1 +", + ); + let p = project_in_home("foo").file("src/lib.rs", "").build(); + + p.cargo("-vV") + .with_stderr_data(str![[r#" +[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml` +[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml` + +"#]]) + .run(); +} + #[cargo_test] fn config_ambiguous_filename_symlink_doesnt_warn() { // Windows requires special permissions to create symlinks.