Skip to content

Commit 9a4d02f

Browse files
bors[bot]matklad
andauthored
Merge #5088
5088: Better exe probing r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents b1a4e81 + f89722f commit 9a4d02f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

crates/ra_toolchain/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
4646
path.push(".cargo");
4747
path.push("bin");
4848
path.push(executable_name);
49-
if path.is_file() {
49+
if let Some(path) = probe(path) {
5050
return path;
5151
}
5252
}
53+
5354
executable_name.into()
5455
}
5556

5657
fn lookup_in_path(exec: &str) -> bool {
5758
let paths = env::var_os("PATH").unwrap_or_default();
58-
let mut candidates = env::split_paths(&paths).flat_map(|path| {
59-
let candidate = path.join(&exec);
60-
let with_exe = match env::consts::EXE_EXTENSION {
61-
"" => None,
62-
it => Some(candidate.with_extension(it)),
63-
};
64-
iter::once(candidate).chain(with_exe)
65-
});
66-
candidates.any(|it| it.is_file())
59+
env::split_paths(&paths).map(|path| path.join(exec)).find_map(probe).is_some()
60+
}
61+
62+
fn probe(path: PathBuf) -> Option<PathBuf> {
63+
let with_extension = match env::consts::EXE_EXTENSION {
64+
"" => None,
65+
it => Some(path.with_extension(it)),
66+
};
67+
iter::once(path).chain(with_extension).find(|it| it.is_file())
6768
}

0 commit comments

Comments
 (0)