Skip to content

Commit 301a162

Browse files
committed
Define path environment variable with a const
Using `#[cfg(...)]` attributes on expressions is unstable, so switch to defining a constant with the relevant value behind a `cfg_if!()`, as we do elsewhere.
1 parent a3b2c57 commit 301a162

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Cargo.lock

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/volta-core/src/tool/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,28 +229,35 @@ fn registry_fetch_error(
229229
|| ErrorKind::RegistryFetchError { tool, from_url }
230230
}
231231

232+
cfg_if!(
233+
if #[cfg(windows)] {
234+
const PATH_VAR_NAME: &str = "Path";
235+
} else {
236+
const PATH_VAR_NAME: &str = "PATH";
237+
}
238+
);
239+
232240
pub fn check_shim_reachable(shim_name: &str) {
233241
let home = match volta_home() {
234242
Ok(home) => home,
235243
Err(_) => return,
236244
};
237245

238246
let shim = home.shim_file(shim_name);
239-
let path_var_name = cfg_if!(if #[cfg(windows)] { "Path" } else { "PATH" });
240247
let resolved = match which::which(shim_name) {
241248
Ok(resolved) => resolved,
242249
Err(_) => {
243250
info!(
244251
"{} cannot find command {}. Please ensure that {} is available on your {}.",
245252
note_prefix(),
246253
shim_name,
247-
home.shim_dir(),
248-
path_var_name,
254+
home.shim_dir().display(),
255+
PATH_VAR_NAME,
249256
);
250257
return;
251258
}
252259
};
253260
if resolved != shim {
254-
info!("{} {} is shadowed by another binary of the same name at {}. To ensure your commands work as expected, please move {} to the start of your {}.", note_prefix(), shim_name, resolved.display(), home.shim_dir(), path_var_name);
261+
info!("{} {} is shadowed by another binary of the same name at {}. To ensure your commands work as expected, please move {} to the start of your {}.", note_prefix(), shim_name, resolved.display(), home.shim_dir().display(), PATH_VAR_NAME);
255262
}
256263
}

0 commit comments

Comments
 (0)