Validation tests: bin_exe! takes CARGO_BIN_EXE_<name> through option_env! without unwrapping it, which clippy denies

56cf3dbd1b called .expect on option_env!(...), and clippy::option_env_unwrap ("this will panic at
run-time if the environment variable doesn't exist at compile-time") is denied under -D warnings:
m3-max-78487's run at 01d80f2d65 failed five of them. The compile-time path is now one more fallback
after nextest's NEXTEST_BIN_EXE_<name>, and a test that finds neither panics naming both.

Verified: the next msi job runs clippy over the validation crate as CI does (CI=1, so
scripts/rustc-wrapper runs the compiler itself, and a fresh target), at the old macro and at this one.
This commit is contained in:
Anees Iqbal committed 2026-12-02 06:53:35 -08:00
1 parent a3cfe0be7c
commit 5d62e2079a
1 file changed
+9 -8
@@ -15,16 +15,17 @@
macro_rules! bin_exe {
($name:literal) => {
std::env::var_os(concat!("NEXTEST_BIN_EXE_", $name))
// `option_env!`, not `env!`: Cargo sets `CARGO_BIN_EXE_<name>` for a build of the test,
// not for `cargo clippy --all-targets`, which only checks it.
.or_else(|| option_env!(concat!("CARGO_BIN_EXE_", $name)).map(std::ffi::OsString::from))
.map(std::path::PathBuf::from)
.unwrap_or_else(|| {
// `option_env!`, not `env!`: Cargo sets `CARGO_BIN_EXE_<name>` for a build of the
// test, but not for `cargo clippy --all-targets`, which only checks it.
std::path::PathBuf::from(option_env!(concat!("CARGO_BIN_EXE_", $name)).expect(
concat!(
"Cargo sets CARGO_BIN_EXE_",
$name,
" when it builds this test"
),
panic!(concat!(
"neither NEXTEST_BIN_EXE_",
$name,
" nor CARGO_BIN_EXE_",
$name,
" is set"
))
})
};