From d36894f425614bcb41ad42b0fd2ed17f1eaded09 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 13 Oct 2024 12:11:56 +0400 Subject: [PATCH] fix: clippy lints please --- brush-core/src/builtins/echo.rs | 6 +++--- brush-core/src/builtins/kill.rs | 2 +- brush-core/src/builtins/printf.rs | 2 +- brush-core/src/builtins/umask.rs | 6 ++++-- brush-core/src/interp.rs | 22 +++++++++------------- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/brush-core/src/builtins/echo.rs b/brush-core/src/builtins/echo.rs index a4df5b7..d3f08d4 100644 --- a/brush-core/src/builtins/echo.rs +++ b/brush-core/src/builtins/echo.rs @@ -25,8 +25,8 @@ pub(crate) struct EchoCommand { } impl builtins::Command for EchoCommand { - /// Override the default [builtins::Command::new] function to handle clap's limitation related - /// to `--`. See [crate::builtins::parse_known] for more information + /// Override the default [`builtins::Command::new`] function to handle clap's limitation related + /// to `--`. See [`builtins::parse_known`] for more information /// TODO: we can safely remove this after the issue is resolved fn new(args: I) -> Result where @@ -74,6 +74,6 @@ impl builtins::Command for EchoCommand { write!(context.stdout(), "{s}")?; context.stdout().flush()?; - return Ok(builtins::ExitCode::Success); + Ok(builtins::ExitCode::Success) } } diff --git a/brush-core/src/builtins/kill.rs b/brush-core/src/builtins/kill.rs index 6188710..f94b978 100644 --- a/brush-core/src/builtins/kill.rs +++ b/brush-core/src/builtins/kill.rs @@ -37,7 +37,7 @@ impl builtins::Command for KillCommand { } if self.list_signals { - return error::unimp("kill -l"); + error::unimp("kill -l") } else { if self.args.len() != 1 { writeln!(context.stderr(), "{}: invalid usage", context.command_name)?; diff --git a/brush-core/src/builtins/printf.rs b/brush-core/src/builtins/printf.rs index a539099..248d24a 100644 --- a/brush-core/src/builtins/printf.rs +++ b/brush-core/src/builtins/printf.rs @@ -30,7 +30,7 @@ impl builtins::Command for PrintfCommand { context.stdout().flush()?; } - return Ok(builtins::ExitCode::Success); + Ok(builtins::ExitCode::Success) } } diff --git a/brush-core/src/builtins/umask.rs b/brush-core/src/builtins/umask.rs index 8a2ce74..ffc6823 100644 --- a/brush-core/src/builtins/umask.rs +++ b/brush-core/src/builtins/umask.rs @@ -63,17 +63,19 @@ cfg_if! { status.umask.ok_or_else(|| error::Error::InvalidUmask) } } else { + #[allow(clippy::unnecessary_wraps)] fn get_umask() -> Result { let u = nix::sys::stat::umask(Mode::empty()); nix::sys::stat::umask(u); - Ok(u.bits() as u32) + Ok(u32::from(u.bits())) } } } fn set_umask(value: u32) -> Result<(), error::Error> { let mode = - nix::sys::stat::Mode::from_bits(value as _).ok_or_else(|| error::Error::InvalidUmask)?; + nix::sys::stat::Mode::from_bits(value.try_into().map_err(|_| error::Error::InvalidUmask)?) + .ok_or_else(|| error::Error::InvalidUmask)?; nix::sys::stat::umask(mode); Ok(()) } diff --git a/brush-core/src/interp.rs b/brush-core/src/interp.rs index 1b986b0..bacdf0e 100644 --- a/brush-core/src/interp.rs +++ b/brush-core/src/interp.rs @@ -1048,19 +1048,15 @@ async fn expand_assignment_value( ast::AssignmentValue::Array(arr) => { let mut expanded_values = vec![]; for (key, value) in arr { - match key { - Some(k) => { - let expanded_key = expansion::basic_expand_word(shell, k).await?.into(); - let expanded_value = - expansion::basic_expand_word(shell, value).await?.into(); - expanded_values.push((Some(expanded_key), expanded_value)); - } - None => { - let split_expanded_value = - expansion::full_expand_and_split_word(shell, value).await?; - for expanded_value in split_expanded_value { - expanded_values.push((None, expanded_value.into())); - } + if let Some(k) = key { + let expanded_key = expansion::basic_expand_word(shell, k).await?.into(); + let expanded_value = expansion::basic_expand_word(shell, value).await?.into(); + expanded_values.push((Some(expanded_key), expanded_value)); + } else { + let split_expanded_value = + expansion::full_expand_and_split_word(shell, value).await?; + for expanded_value in split_expanded_value { + expanded_values.push((None, expanded_value.into())); } } }