diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 1db5b9a3c987..ec75cc02e77c 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -1577,25 +1577,27 @@ impl GlobalContext { } } - fn walk_tree(&self, pwd: &Path, home: &Path, mut walk: F) -> CargoResult<()> + fn walk_tree(&self, pwd: &Path, cargo_home: &Path, mut walk: F) -> CargoResult<()> where F: FnMut(&Path) -> CargoResult<()>, { let mut stash: HashSet = HashSet::new(); for current in paths::ancestors(pwd, self.search_stop_path.as_deref()) { + // Be aware `current` may be the parent of the `$CARGO_HOME`, in this case the next line also walk the `$CARGO_HOME`. if let Some(path) = self.get_file_path(¤t.join(".cargo"), "config", true)? { walk(&path)?; stash.insert(path); } } - // 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) { - walk(&path)?; + let cargo_home_parent = cargo_home.parent().unwrap_or(cargo_home); + // If we haven't walked the $CARGO_HOME directory yet, walk it to pick up that standard location for information. + if !pwd.starts_with(cargo_home_parent) { + if let Some(path) = self.get_file_path(cargo_home, "config", true)? { + if !stash.contains(&path) { + walk(&path)?; + } } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index aba4e2552b58..1c6eff4477f7 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -315,8 +315,6 @@ f1 = 1 .with_stderr_data(str![[r#" [WARNING] `[ROOT]/.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` -[WARNING] `[ROOT]/.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();