From 45cd3e8e566dc0a27d2a02f8af892ccbb0339c21 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 7 Aug 2025 15:06:19 +0200 Subject: [PATCH] clippy: fix warnings from unnecessary_unwrap lint --- src/uu/install/src/install.rs | 12 ++-- src/uucore/src/lib/features/selinux.rs | 90 ++++++++++++-------------- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 10717c659..ac1948c51 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -362,11 +362,13 @@ fn behavior(matches: &ArgMatches) -> UResult { } // Check if compare is used with non-permission mode bits - if compare && specified_mode.is_some() { - let mode = specified_mode.unwrap(); - let non_permission_bits = 0o7000; // setuid, setgid, sticky bits - if mode & non_permission_bits != 0 { - show_error!("{}", translate!("install-warning-compare-ignored")); + // TODO use a let chain once we have a MSRV of 1.88 or greater + if compare { + if let Some(mode) = specified_mode { + let non_permission_bits = 0o7000; // setuid, setgid, sticky bits + if mode & non_permission_bits != 0 { + show_error!("{}", translate!("install-warning-compare-ignored")); + } } } diff --git a/src/uucore/src/lib/features/selinux.rs b/src/uucore/src/lib/features/selinux.rs index 939210ae8..3e6929053 100644 --- a/src/uucore/src/lib/features/selinux.rs +++ b/src/uucore/src/lib/features/selinux.rs @@ -474,57 +474,53 @@ mod tests { let result = get_selinux_security_context(path, false); - if result.is_ok() { - let context = result.unwrap(); - println!("Retrieved SELinux context: {context}"); + match result { + Ok(context) => { + println!("Retrieved SELinux context: {context}"); - assert!( - is_selinux_enabled(), - "Got a successful context result but SELinux is not enabled" - ); - - if !context.is_empty() { assert!( - context.contains(':'), - "SELinux context '{context}' doesn't match expected format" + is_selinux_enabled(), + "Got a successful context result but SELinux is not enabled" + ); + + if !context.is_empty() { + assert!( + context.contains(':'), + "SELinux context '{context}' doesn't match expected format" + ); + } + } + Err(SeLinuxError::SELinuxNotEnabled) => { + assert!( + !is_selinux_enabled(), + "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true" ); } - } else { - let err = result.unwrap_err(); - - match err { - SeLinuxError::SELinuxNotEnabled => { - assert!( - !is_selinux_enabled(), - "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true" - ); - } - SeLinuxError::ContextRetrievalFailure(e) => { - assert!( - is_selinux_enabled(), - "Got ContextRetrievalFailure when SELinux is not enabled" - ); - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context retrieval failure: {e}"); - } - SeLinuxError::ContextConversionFailure(ctx, e) => { - assert!( - is_selinux_enabled(), - "Got ContextConversionFailure when SELinux is not enabled" - ); - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context conversion failure for '{ctx}': {e}"); - } - SeLinuxError::ContextSetFailure(ctx, e) => { - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context conversion failure for '{ctx}': {e}"); - } - SeLinuxError::FileOpenFailure(e) => { - assert!( - Path::new(path).exists(), - "File open failure occurred despite file being created: {e}" - ); - } + Err(SeLinuxError::ContextRetrievalFailure(e)) => { + assert!( + is_selinux_enabled(), + "Got ContextRetrievalFailure when SELinux is not enabled" + ); + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context retrieval failure: {e}"); + } + Err(SeLinuxError::ContextConversionFailure(ctx, e)) => { + assert!( + is_selinux_enabled(), + "Got ContextConversionFailure when SELinux is not enabled" + ); + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context conversion failure for '{ctx}': {e}"); + } + Err(SeLinuxError::ContextSetFailure(ctx, e)) => { + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context conversion failure for '{ctx}': {e}"); + } + Err(SeLinuxError::FileOpenFailure(e)) => { + assert!( + Path::new(path).exists(), + "File open failure occurred despite file being created: {e}" + ); } } }