From 17924e04d5d79fe4e08cceff4f375375d47b7060 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 22 Sep 2021 14:56:16 +0200 Subject: [PATCH] Fix search for Cargo configuration --- src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cd62740..5601db3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,8 +78,18 @@ impl Project { // parse .cargo/config let mut target = None; let mut target_dir = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from); - if let Some(path) = search(root, &cargo_config).map(|path| path.join(cargo_config)).or_else(|| { - search(root, &cargo_config_toml).map(|path| path.join(cargo_config_toml)) + if let Some(path) = path.ancestors().find_map(|dir| { + let path = dir.join(&cargo_config); + if path.exists() { + return Some(path); + } + + let path = dir.join(&cargo_config_toml); + if path.exists() { + return Some(path); + } + + None }) { let config: Config = parse(&path)?;