diff --git a/src/uucore/src/lib/mods/panic.rs b/src/uucore/src/lib/mods/panic.rs index 2a67a10ba8d..b2e2c8cfcbb 100644 --- a/src/uucore/src/lib/mods/panic.rs +++ b/src/uucore/src/lib/mods/panic.rs @@ -17,12 +17,9 @@ use std::panic::{self, PanicHookInfo}; /// Decide whether a panic was caused by a broken pipe (SIGPIPE) error. fn is_broken_pipe(info: &PanicHookInfo) -> bool { - if let Some(res) = info.payload().downcast_ref::() { - if res.contains("BrokenPipe") || res.contains("Broken pipe") { - return true; - } - } - false + info.payload() + .downcast_ref::() + .is_some_and(|res| res.contains("BrokenPipe") || res.contains("Broken pipe")) } /// Terminate without error on panics that occur due to broken pipe errors. @@ -55,14 +52,12 @@ pub fn preserve_inherited_sigpipe() { use nix::libc; // Check if parent specified that SIGPIPE should be default - if let Ok(val) = std::env::var("RUST_SIGPIPE") { - if val == "default" { - unsafe { - libc::signal(libc::SIGPIPE, libc::SIG_DFL); - // Remove the environment variable so child processes don't inherit it incorrectly - std::env::remove_var("RUST_SIGPIPE"); - } - } + if let Ok(val) = std::env::var("RUST_SIGPIPE") + && val == "default" + { + unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) }; + // Remove the environment variable so child processes don't inherit it incorrectly + unsafe { std::env::remove_var("RUST_SIGPIPE") }; } }