aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_toolchain/src/lib.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_toolchain/src/lib.rs b/crates/ra_toolchain/src/lib.rs
index 9532fb255..9916e52c4 100644
--- a/crates/ra_toolchain/src/lib.rs
+++ b/crates/ra_toolchain/src/lib.rs
@@ -46,22 +46,23 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
46 path.push(".cargo"); 46 path.push(".cargo");
47 path.push("bin"); 47 path.push("bin");
48 path.push(executable_name); 48 path.push(executable_name);
49 if path.is_file() { 49 if let Some(path) = probe(path) {
50 return path; 50 return path;
51 } 51 }
52 } 52 }
53
53 executable_name.into() 54 executable_name.into()
54} 55}
55 56
56fn lookup_in_path(exec: &str) -> bool { 57fn lookup_in_path(exec: &str) -> bool {
57 let paths = env::var_os("PATH").unwrap_or_default(); 58 let paths = env::var_os("PATH").unwrap_or_default();
58 let mut candidates = env::split_paths(&paths).flat_map(|path| { 59 env::split_paths(&paths).map(|path| path.join(exec)).find_map(probe).is_some()
59 let candidate = path.join(&exec); 60}
60 let with_exe = match env::consts::EXE_EXTENSION { 61
61 "" => None, 62fn probe(path: PathBuf) -> Option<PathBuf> {
62 it => Some(candidate.with_extension(it)), 63 let with_extension = match env::consts::EXE_EXTENSION {
63 }; 64 "" => None,
64 iter::once(candidate).chain(with_exe) 65 it => Some(path.with_extension(it)),
65 }); 66 };
66 candidates.any(|it| it.is_file()) 67 iter::once(path).chain(with_extension).find(|it| it.is_file())
67} 68}