diff --git a/fish-rust/src/common.rs b/fish-rust/src/common.rs index ac42cd33b..cb154f08b 100644 --- a/fish-rust/src/common.rs +++ b/fish-rust/src/common.rs @@ -1419,20 +1419,11 @@ pub fn read_blocked(fd: RawFd, buf: &mut [u8]) -> isize { /// Test if the string is a valid function name. pub fn valid_func_name(name: &wstr) -> bool { - if name.is_empty() { - return false; - }; - if name.char_at(0) == '-' { - return false; - }; + !(name.is_empty() + || name.starts_with('-') // A function name needs to be a valid path, so no / and no NULL. - if name.find_char('/').is_some() { - return false; - }; - if name.find_char('\0').is_some() { - return false; - }; - true + || name.contains('/') + || name.contains('\0')) } /// A rusty port of the C++ `write_loop()` function from `common.cpp`. This should be deprecated in @@ -1720,7 +1711,7 @@ fn get_executable_path(argv0: &str) -> PathBuf { /// the replacement value. Useful to avoid errors about multiple references (`&mut T` for `old` then /// `&T` again in the `new` expression). pub fn replace_with T>(old: &mut T, with: F) -> T { - let new = with(&*old); + let new = with(old); std::mem::replace(old, new) }