From 72c065a79fdf3110966710eb574c82300e8719e2 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Sun, 30 Nov 2025 00:23:19 -0500 Subject: [PATCH] clippy auto-fixes --- calc/expr.rs | 12 +++++------- datetime/cal.rs | 2 +- editors/vi/editor.rs | 2 +- fs/df.rs | 2 +- ftw/src/dir.rs | 4 ++-- mailx/mailbox.rs | 2 +- mailx/main.rs | 2 +- process/kill.rs | 2 +- text/comm.rs | 12 ++++-------- tree/chown.rs | 2 +- tree/common/copy.rs | 10 ++++------ tree/touch.rs | 9 +++------ users/newgrp.rs | 22 +++++++++++----------- users/pwd.rs | 6 ++---- users/talk.rs | 2 +- 15 files changed, 39 insertions(+), 52 deletions(-) diff --git a/calc/expr.rs b/calc/expr.rs index 58648a769..d6248c6f0 100644 --- a/calc/expr.rs +++ b/calc/expr.rs @@ -227,14 +227,12 @@ fn logop(lhs: &Token, rhs: &Token, is_and: bool) -> Token { } else { Token::Integer(0) } + } else if !lhs_zero { + lhs.clone() + } else if !rhs_zero { + rhs.clone() } else { - if !lhs_zero { - lhs.clone() - } else if !rhs_zero { - rhs.clone() - } else { - Token::Integer(0) - } + Token::Integer(0) } } diff --git a/datetime/cal.rs b/datetime/cal.rs index fdefbe9a5..3b701580c 100644 --- a/datetime/cal.rs +++ b/datetime/cal.rs @@ -102,7 +102,7 @@ fn main() -> Result<(), Box> { // If no arguments are provided, display the current month if args.month.is_none() && args.year.is_none() { let now = chrono::Local::now(); - args.month = Some(now.month() as u32); + args.month = Some(now.month()); args.year = Some(now.year() as u32); // If only one argument is provided, assume it is the entire year diff --git a/editors/vi/editor.rs b/editors/vi/editor.rs index 8416f8ae2..69a9068c5 100644 --- a/editors/vi/editor.rs +++ b/editors/vi/editor.rs @@ -2567,7 +2567,7 @@ impl Editor { if let Some('=') = ztype { // For '=', print separator line around current line let cols = self.terminal.size().cols as usize; - let separator: String = std::iter::repeat('-').take(40.min(cols / 2)).collect(); + let separator: String = "-".repeat(40.min(cols / 2)); let half = count / 2; let before_start = target_line.saturating_sub(half).max(1); diff --git a/fs/df.rs b/fs/df.rs index 76e14246f..8f8440cf5 100644 --- a/fs/df.rs +++ b/fs/df.rs @@ -238,7 +238,7 @@ impl Mount { let percentage_used = percentage_used.ceil() as u32; FieldsData { - fields: fields, + fields, source: &self.devname, size: total, used, diff --git a/ftw/src/dir.rs b/ftw/src/dir.rs index 991b1b462..4202960cb 100644 --- a/ftw/src/dir.rs +++ b/ftw/src/dir.rs @@ -16,7 +16,7 @@ pub struct EntryInternal<'a> { phantom: PhantomData<&'a libc::dirent>, } -impl<'a> EntryInternal<'a> { +impl EntryInternal<'_> { pub fn name_cstr(&self) -> &CStr { // Avoid dereferencing `dirent` when getting its fields. See note at: // https://github.com/rust-lang/rust/blob/1.80.1/library/std/src/sys/pal/unix/fs.rs#L725-L742 @@ -193,7 +193,7 @@ pub struct DeferredDirIterator<'a> { visited: RefMut<'a, HashSet>, } -impl<'a> Drop for DeferredDirIterator<'a> { +impl Drop for DeferredDirIterator<'_> { fn drop(&mut self) { unsafe { libc::closedir(self.dirp); diff --git a/mailx/mailbox.rs b/mailx/mailbox.rs index 78793a4ab..0ee261c00 100644 --- a/mailx/mailbox.rs +++ b/mailx/mailbox.rs @@ -230,7 +230,7 @@ impl Mailbox { // Decide whether to show To or From let address_field = if show_to && msg.from().contains(&user) { - format!("To {}", truncate(&msg.to().to_string(), 18)) + format!("To {}", truncate(msg.to(), 18)) } else { msg.from_short() }; diff --git a/mailx/main.rs b/mailx/main.rs index c62a4b5cc..1168e355d 100644 --- a/mailx/main.rs +++ b/mailx/main.rs @@ -98,7 +98,7 @@ fn run_receive_mode(args: &Args) -> i32 { } let mailbox_path = if args.read_mbox { - args.file.clone().unwrap_or_else(|| get_mbox_path()) + args.file.clone().unwrap_or_else(get_mbox_path) } else { args.file.clone().unwrap_or_else(get_system_mailbox) }; diff --git a/process/kill.rs b/process/kill.rs index ec897894a..6ce69aeb3 100644 --- a/process/kill.rs +++ b/process/kill.rs @@ -72,7 +72,7 @@ fn send_signal(prog_cfg: &Config, sig_no: i32) -> u32 { let mut exit_code = 0; for pid in &prog_cfg.pids { - let res = unsafe { libc::kill(*pid as libc::pid_t, sig_no as i32) }; + let res = unsafe { libc::kill(*pid as libc::pid_t, sig_no) }; if res != 0 { let err = std::io::Error::last_os_error(); eprintln!("kill pid {}: {}", pid, err); diff --git a/text/comm.rs b/text/comm.rs index 81a45cc1e..0312acb36 100644 --- a/text/comm.rs +++ b/text/comm.rs @@ -92,15 +92,11 @@ fn comm_file( let mut want2 = true; loop { - if want1 && buf1.is_empty() { - if rdr1.read_line(&mut buf1)? == 0 { - want1 = false; - } + if want1 && buf1.is_empty() && rdr1.read_line(&mut buf1)? == 0 { + want1 = false; } - if want2 && buf2.is_empty() { - if rdr2.read_line(&mut buf2)? == 0 { - want2 = false; - } + if want2 && buf2.is_empty() && rdr2.read_line(&mut buf2)? == 0 { + want2 = false; } if buf1.is_empty() && buf2.is_empty() { diff --git a/tree/chown.rs b/tree/chown.rs index 6762e47f1..5e374130e 100644 --- a/tree/chown.rs +++ b/tree/chown.rs @@ -72,7 +72,7 @@ enum ParseOwnerGroupResult { fn parse_owner_group(owner_group: &str) -> Result { if owner_group.is_empty() || owner_group == ":" { - return Ok(ParseOwnerGroupResult::EmptyOrColon); + Ok(ParseOwnerGroupResult::EmptyOrColon) } else { match owner_group.split_once(':') { None => { diff --git a/tree/common/copy.rs b/tree/common/copy.rs index f4afb221d..5974104d9 100644 --- a/tree/common/copy.rs +++ b/tree/common/copy.rs @@ -301,12 +301,10 @@ where return Ok(CopyResult::Skipped); } } - } else { - if cfg.interactive { - let is_affirm = prompt_fn(&gettext!("overwrite '{}'?", target.display())); - if !is_affirm { - return Ok(CopyResult::Skipped); - } + } else if cfg.interactive { + let is_affirm = prompt_fn(&gettext!("overwrite '{}'?", target.display())); + if !is_affirm { + return Ok(CopyResult::Skipped); } } diff --git a/tree/touch.rs b/tree/touch.rs index c7812edf4..08b9b4cdf 100644 --- a/tree/touch.rs +++ b/tree/touch.rs @@ -54,12 +54,9 @@ fn parse_tm_posix(time: &str) -> Result, Box { - tmp_time = t.to_string(); - seconds = secs.to_string(); - } - None => {} + if let Some((t, secs)) = time.split_once('.') { + tmp_time = t.to_string(); + seconds = secs.to_string(); } if !tmp_time.is_empty() { time = tmp_time; diff --git a/users/newgrp.rs b/users/newgrp.rs index a9623f0d0..83c88163f 100644 --- a/users/newgrp.rs +++ b/users/newgrp.rs @@ -76,18 +76,18 @@ fn newgrp(args: Args) -> Result<(), io::Error> { let groups = plib::group::load(); // Retrieve current user information - let pwd = get_password().or_else(|_| { - Err(io::Error::new( + let pwd = get_password().map_err(|_| { + io::Error::new( io::ErrorKind::NotFound, "Could not retrieve current user information.", - )) + ) })?; let user_name = unsafe { CStr::from_ptr(pwd.pw_name) } .to_str() - .unwrap_or_else(|_| "???"); + .unwrap_or("???"); if args.login { - set_login_environment(&user_name)?; + set_login_environment(user_name)?; } let group_identifier = args.group.trim(); @@ -126,12 +126,12 @@ fn newgrp(args: Args) -> Result<(), io::Error> { if new_gid_in_supplementary { // New GID is also in the supplementary list; change the effective GID change_effective_gid_and_uid(group.gid, group_identifier)?; - logger(&user_name, group.gid); + logger(user_name, group.gid); } else { // New GID is not in the supplementary list; add it if possible add_gid_to_groups(group.gid); change_effective_gid_and_uid(group.gid, group_identifier)?; - logger(&user_name, group.gid); + logger(user_name, group.gid); } } else { // The effective GID is not in the supplementary list @@ -143,7 +143,7 @@ fn newgrp(args: Args) -> Result<(), io::Error> { add_gid_to_groups(current_gid); } change_gid_and_uid(group.gid, group_identifier)?; - logger(&user_name, group.gid); + logger(user_name, group.gid); } Ok(()) @@ -755,11 +755,11 @@ fn read_password() -> io::Result { /// fn set_login_environment(user: &str) -> Result<(), io::Error> { // Get the user's shell from the password entry - let pwd = get_password().or_else(|_| { - Err(io::Error::new( + let pwd = get_password().map_err(|_| { + io::Error::new( io::ErrorKind::NotFound, "Could not retrieve user information.", - )) + ) })?; let user_shell = unsafe { CStr::from_ptr(pwd.pw_shell) } diff --git a/users/pwd.rs b/users/pwd.rs index 48fb74a4a..10374a9a8 100644 --- a/users/pwd.rs +++ b/users/pwd.rs @@ -41,10 +41,8 @@ fn dirname_valid(name: &OsStr) -> bool { if component != Component::RootDir { return false; } - } else { - if component == Component::CurDir || component == Component::ParentDir { - return false; - } + } else if component == Component::CurDir || component == Component::ParentDir { + return false; } } diff --git a/users/talk.rs b/users/talk.rs index 3521970d2..6fe7b472c 100644 --- a/users/talk.rs +++ b/users/talk.rs @@ -595,7 +595,7 @@ fn spawn_input_thread( '\n' => { if let Err(e) = handle_newline( &mut line_buffer, - &mut *bottom_line, + &mut bottom_line, split_row, &mut handle, ) {