Skip to content

Commit 148486b

Browse files
Timmmmdjc
authored andcommitted
refactor: improve binary suffix stripping
Use `strip_suffix()` which is clearer, shorter, and won't break if the suffix is in the middle of the filename (unlikely, but still). I also renamed `binary_prefix` to something clearer, since it isn't actually a prefix; it's the main part.
1 parent 83d0901 commit 148486b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub fn is_proxyable_tools(tool: &str) -> Result<()> {
5353
fn component_for_bin(binary: &str) -> Option<&'static str> {
5454
use std::env::consts::EXE_SUFFIX;
5555

56-
let binary_prefix = match binary.find(EXE_SUFFIX) {
57-
_ if EXE_SUFFIX.is_empty() => binary,
58-
Some(i) => &binary[..i],
59-
None => binary,
60-
};
56+
let binary_without_suffix = binary.strip_suffix(EXE_SUFFIX).unwrap_or(binary);
6157

62-
match binary_prefix {
58+
match binary_without_suffix {
6359
"rustc" | "rustdoc" => Some("rustc"),
6460
"cargo" => Some("cargo"),
6561
"rust-lldb" | "rust-gdb" | "rust-gdbgui" => Some("rustc"), // These are not always available

0 commit comments

Comments
 (0)