From dc72ad9242310a98356f71d7f39600d9331332a3 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Mon, 16 Jun 2025 23:22:28 +0200 Subject: [PATCH 01/10] fix(clippy): explicit_iter_loop --- src/uucore/src/lib/features/parser/num_parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/parser/num_parser.rs b/src/uucore/src/lib/features/parser/num_parser.rs index 35a8892e8..894982c75 100644 --- a/src/uucore/src/lib/features/parser/num_parser.rs +++ b/src/uucore/src/lib/features/parser/num_parser.rs @@ -363,7 +363,7 @@ fn parse_special_value<'a>( ("nan", ExtendedBigDecimal::Nan), ]; - for (str, ebd) in MATCH_TABLE.iter() { + for (str, ebd) in MATCH_TABLE { if input_lc.starts_with(str) { let mut special = ebd.clone(); if negative { From a7ae477a7ecb87010b76acb7748d015639b64bd9 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Mon, 16 Jun 2025 23:32:08 +0200 Subject: [PATCH 02/10] fix(clippy): if_not_else --- src/uu/ls/src/ls.rs | 6 +++--- src/uu/ptx/src/ptx.rs | 20 +++++++++---------- .../src/lib/features/format/num_format.rs | 6 +++--- .../src/lib/features/parser/num_parser.rs | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index f3884f302..a9c9597bb 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1091,13 +1091,13 @@ impl Config { Dereference::DirArgs }; - let tab_size = if !needs_color { + let tab_size = if needs_color { + Some(0) + } else { options .get_one::(options::format::TAB_SIZE) .and_then(|size| size.parse::().ok()) .or_else(|| std::env::var("TABSIZE").ok().and_then(|s| s.parse().ok())) - } else { - Some(0) } .unwrap_or(SPACES_IN_TAB); diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 856183a54..4d460d715 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -736,16 +736,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .flatten() .cloned(); - if !config.gnu_ext { - input_files = vec![files.next().unwrap_or("-".to_string())]; - output_file = files.next().unwrap_or("-".to_string()); - if let Some(file) = files.next() { - return Err(UUsageError::new( - 1, - format!("extra operand {}", file.quote()), - )); - } - } else { + if config.gnu_ext { input_files = { let mut files = files.collect::>(); if files.is_empty() { @@ -754,6 +745,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { files }; output_file = "-".to_string(); + } else { + input_files = vec![files.next().unwrap_or("-".to_string())]; + output_file = files.next().unwrap_or("-".to_string()); + if let Some(file) = files.next() { + return Err(UUsageError::new( + 1, + format!("extra operand {}", file.quote()), + )); + } } let word_filter = WordFilter::new(&matches, &config)?; diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 52065c8b1..ea635230e 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -328,14 +328,14 @@ impl Formatter<&ExtendedBigDecimal> for Float { } fn get_sign_indicator(sign: PositiveSign, negative: bool) -> String { - if !negative { + if negative { + String::from("-") + } else { match sign { PositiveSign::None => String::new(), PositiveSign::Plus => String::from("+"), PositiveSign::Space => String::from(" "), } - } else { - String::from("-") } } diff --git a/src/uucore/src/lib/features/parser/num_parser.rs b/src/uucore/src/lib/features/parser/num_parser.rs index 894982c75..30d7760a9 100644 --- a/src/uucore/src/lib/features/parser/num_parser.rs +++ b/src/uucore/src/lib/features/parser/num_parser.rs @@ -638,13 +638,13 @@ pub(crate) fn parse<'a>( // Return what has been parsed so far. If there are extra characters, mark the // parsing as a partial match. - if !rest.is_empty() { + if rest.is_empty() { + ebd_result + } else { Err(ExtendedParserError::PartialMatch( ebd_result.unwrap_or_else(|e| e.extract()), rest, )) - } else { - ebd_result } } From 4afeb628a4c260abdc875c9a81e3d11219d3bc38 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Mon, 16 Jun 2025 23:56:15 +0200 Subject: [PATCH 03/10] fix(clippy): inefficient_to_string --- src/uu/tsort/src/tsort.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 4f273e621..abff7e89b 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -218,7 +218,7 @@ impl<'input> Graph<'input> { let cycle = self.detect_cycle(); show!(TsortError::Loop(self.name.clone())); for node in &cycle { - show!(TsortError::LoopNode(node.to_string())); + show!(TsortError::LoopNode((*node).to_string())); } let u = cycle[0]; let v = cycle[1]; From 2e1c09951e6ba396b5383387a9c9169eff92650f Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Mon, 16 Jun 2025 23:58:19 +0200 Subject: [PATCH 04/10] fix(clippy): manual_let_else --- src/uucore/src/lib/features/parser/num_parser.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/uucore/src/lib/features/parser/num_parser.rs b/src/uucore/src/lib/features/parser/num_parser.rs index 30d7760a9..1eda08ae8 100644 --- a/src/uucore/src/lib/features/parser/num_parser.rs +++ b/src/uucore/src/lib/features/parser/num_parser.rs @@ -516,11 +516,8 @@ fn construct_extended_big_decimal<'a>( // pow_with_context "only" supports i64 values. Just overflow/underflow if the value provided // is > 2**64 or < 2**-64. - let exponent = match exponent.to_i64() { - Some(exp) => exp, - None => { - return Err(make_error(exponent.is_positive(), negative)); - } + let Some(exponent) = exponent.to_i64() else { + return Err(make_error(exponent.is_positive(), negative)); }; // Confusingly, exponent is in base 2 for hex floating point numbers. From 9319c4f8cf283190ec9809698e173ebe110ed1aa Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:00:22 +0200 Subject: [PATCH 05/10] fix(clippy): manual_string_new --- src/uucore/src/lib/features/format/num_format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index ea635230e..e899ff7c2 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -154,7 +154,7 @@ impl Formatter for UnsignedInt { }; s = format!("{prefix}{s:0>width$}", width = self.precision); - write_output(writer, "".to_string(), s, self.width, self.alignment) + write_output(writer, String::new(), s, self.width, self.alignment) } fn try_from_spec(s: Spec) -> Result { From edfcc2b400e225af4953e5fba95e71bc8e23fec8 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:02:13 +0200 Subject: [PATCH 06/10] fix(clippy): match_wildcard_for_single_variants --- src/uucore/src/lib/features/checksum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 001e3237e..ed615baa9 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -671,7 +671,7 @@ impl LineInfo { match cached_format { LineFormat::Untagged => LineFormat::parse_untagged(line_bytes), LineFormat::SingleSpace => LineFormat::parse_single_space(line_bytes), - _ => unreachable!("we never catch the algo based format"), + LineFormat::AlgoBased => unreachable!("we never catch the algo based format"), } } else if let Some(info) = LineFormat::parse_untagged(line_bytes) { *cached_line_format = Some(LineFormat::Untagged); From e8b6561d4c71dac3522f1c9d1dcaf9f69950e17d Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:06:01 +0200 Subject: [PATCH 07/10] fix(clippy): needless_continue --- src/uu/dd/src/dd.rs | 4 ++-- src/uu/expand/src/expand.rs | 1 - src/uu/head/src/parse.rs | 1 - src/uu/head/src/take.rs | 2 +- src/uu/ls/src/ls.rs | 1 - src/uu/shred/src/shred.rs | 1 - src/uu/sum/src/sum.rs | 4 ++-- src/uu/tail/src/follow/watch.rs | 2 +- src/uu/tail/src/tail.rs | 2 +- src/uu/wc/src/count_fast.rs | 4 ++-- src/uucore/src/lib/features/checksum.rs | 4 ++-- src/uucore/src/lib/features/entries.rs | 1 - 12 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index c0e37263f..7351ded39 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -437,7 +437,7 @@ impl Read for Input<'_> { } } Ok(len) => return Ok(len), - Err(e) if e.kind() == io::ErrorKind::Interrupted => continue, + Err(e) if e.kind() == io::ErrorKind::Interrupted => (), Err(_) if self.settings.iconv.noerror => return Ok(base_idx), Err(e) => return Err(e), } @@ -861,7 +861,7 @@ impl<'a> Output<'a> { return Ok(base_idx); } } - Err(e) if e.kind() == io::ErrorKind::Interrupted => continue, + Err(e) if e.kind() == io::ErrorKind::Interrupted => (), Err(e) => return Err(e), } } diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 2e8d1b296..c8551115e 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -464,7 +464,6 @@ fn expand(options: &Options) -> UResult<()> { Err(e) => { show_error!("{e}"); set_exit_code(1); - continue; } } } diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index a4ce6e710..aa2a56f7d 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -26,7 +26,6 @@ pub fn parse_obsolete(src: &str) -> Option, ParseError>> { } else if c == '+' && plus_possible { plus_possible = false; num_start += 1; - continue; } else { num_end = n; last_char = c; diff --git a/src/uu/head/src/take.rs b/src/uu/head/src/take.rs index 1a303bbd4..de8831cc9 100644 --- a/src/uu/head/src/take.rs +++ b/src/uu/head/src/take.rs @@ -31,7 +31,7 @@ impl TakeAllBuffer { self.buffer.truncate(n); return Ok(n); } - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return Err(e), } } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a9c9597bb..7301766b7 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2366,7 +2366,6 @@ fn enter_directory( err, e.command_line )); - continue; } Ok(rd) => { if listed_ancestors diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 0cfafd862..691e36bc2 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -138,7 +138,6 @@ impl Iterator for FilenameIter { if *index == NAME_CHARSET.len() - 1 { // Carry the 1 *index = 0; - continue; } else { *index += 1; return Some(ret); diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 41ab702e5..21c35c76c 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -29,7 +29,7 @@ fn bsd_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { rotated.wrapping_add(u16::from(byte)) }); } - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return Err(e), } } @@ -53,7 +53,7 @@ fn sysv_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { .iter() .fold(ret, |acc, &byte| acc.wrapping_add(u32::from(byte))); } - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return Err(e), } } diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 87db5aa02..19c419cd4 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -284,7 +284,7 @@ impl Observer { if let Some(watcher_rx) = &mut self.watcher_rx { for input in inputs { match input.kind() { - InputKind::Stdin => continue, + InputKind::Stdin => (), InputKind::File(path) => { #[cfg(all(unix, not(target_os = "linux")))] if !path.is_file() { diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 63dd7389b..aa74f08c6 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -393,7 +393,7 @@ fn forwards_thru_file( } total += n; } - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return Err(e), } } diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index a8f5dd432..d70ba9f7c 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -192,7 +192,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti Ok(n) => { byte_count += n; } - Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Err(ref e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return (byte_count, Some(e)), } } @@ -246,7 +246,7 @@ pub(crate) fn count_bytes_chars_and_lines_fast< total.lines += bytecount::count(&buf[..n], b'\n'); } } - Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Err(ref e) if e.kind() == ErrorKind::Interrupted => (), Err(e) => return (total, Some(e)), } } diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index ed615baa9..70cd6796c 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -1063,7 +1063,7 @@ fn process_checksum_file( } Err(CantOpenFile | FileIsDirectory) => res.failed_open_file += 1, Err(FileNotFound) if !opts.ignore_missing => res.failed_open_file += 1, - _ => continue, + _ => (), }; } @@ -1132,7 +1132,7 @@ where match process_checksum_file(filename_input, algo_name_input, length_input, opts) { Err(UError(e)) => return Err(e), Err(Failed | CantOpenChecksumFile) => failed = true, - Ok(_) => continue, + Ok(_) => (), } } diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index 9fa7b94ab..ccf4b3751 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -82,7 +82,6 @@ pub fn get_groups() -> IOResult> { let err = IOError::last_os_error(); if err.raw_os_error() == Some(libc::EINVAL) { // Number of groups has increased, retry - continue; } else { return Err(err); } From 05735887b9a8fb6852da84699761508cf25e10ae Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:17:10 +0200 Subject: [PATCH 08/10] fix(clippy): uninlined_format_args --- src/uu/date/src/date.rs | 2 +- src/uu/more/src/more.rs | 4 ++-- src/uu/numfmt/src/format.rs | 2 +- src/uu/tail/src/args.rs | 2 +- src/uu/tr/src/operation.rs | 2 +- src/uucore/src/lib/mods/locale.rs | 5 ++--- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 9f8b4c095..379aba67f 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -270,7 +270,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Err(e) => { return Err(USimpleError::new( 1, - format!("invalid format {} ({e})", format_string), + format!("invalid format {format_string} ({e})"), )); } }, diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index fc2689448..3ab8474dd 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -745,7 +745,7 @@ impl<'a> Pager<'a> { &format!("{}{pattern}{}", Attribute::Reverse, Attribute::Reset), ); }; - self.stdout.write_all(format!("\r{}\n", line).as_bytes())?; + self.stdout.write_all(format!("\r{line}\n").as_bytes())?; lines_printed += 1; index += 1; } @@ -792,7 +792,7 @@ impl<'a> Pager<'a> { if percentage >= 100 { " (END)".to_string() } else { - format!(" ({}%)", percentage) + format!(" ({percentage}%)") } } } else { diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index f74317c39..085beadc0 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -390,7 +390,7 @@ fn format_and_print_whitespace(s: &str, options: &NumfmtOptions) -> Result<()> { } let eol = if options.zero_terminated { '\0' } else { '\n' }; - print!("{}", eol); + print!("{eol}"); Ok(()) } diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index e4e1c4224..f7131b319 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -81,7 +81,7 @@ impl FilterMode { 1, get_message_with_args( "tail-error-invalid-number-of-bytes", - HashMap::from([("arg".to_string(), format!("'{}'", e))]), + HashMap::from([("arg".to_string(), format!("'{e}'"))]), ), )); } diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index fde766e49..dbade6b46 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -72,7 +72,7 @@ impl Display for BadSequence { "{}", get_message_with_args( "tr-error-invalid-repeat-count", - HashMap::from([("count".to_string(), format!("'{}'", count))]) + HashMap::from([("count".to_string(), format!("'{count}'"))]) ) ) } diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs index d48df652f..3bce3a3d7 100644 --- a/src/uucore/src/lib/mods/locale.rs +++ b/src/uucore/src/lib/mods/locale.rs @@ -174,8 +174,7 @@ fn create_bundle( bundle.add_resource(resource).map_err(|errs| { LocalizationError::Bundle(format!( - "Failed to add resource to bundle for {}: {:?}", - locale, errs + "Failed to add resource to bundle for {locale}: {errs:?}", )) })?; @@ -276,7 +275,7 @@ fn detect_system_locale() -> Result { .unwrap_or(DEFAULT_LOCALE) .to_string(); LanguageIdentifier::from_str(&locale_str).map_err(|_| { - LocalizationError::ParseLocale(format!("Failed to parse locale: {}", locale_str)) + LocalizationError::ParseLocale(format!("Failed to parse locale: {locale_str}")) }) } From d64fcb1826444ad681eea6fab4a93d987ac0ee04 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:18:19 +0200 Subject: [PATCH 09/10] fix(clippy): unnested_or_patterns --- src/uu/sort/src/sort.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index faef098d9..49df12487 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1808,9 +1808,11 @@ fn general_bd_parse(a: &str) -> GeneralBigDecimalParseResult { // Parse digits, and fold in recoverable errors let ebd = match ExtendedBigDecimal::extended_parse(a) { Err(ExtendedParserError::NotNumeric) => return GeneralBigDecimalParseResult::Invalid, - Err(ExtendedParserError::PartialMatch(ebd, _)) - | Err(ExtendedParserError::Overflow(ebd)) - | Err(ExtendedParserError::Underflow(ebd)) + Err( + ExtendedParserError::PartialMatch(ebd, _) + | ExtendedParserError::Overflow(ebd) + | ExtendedParserError::Underflow(ebd), + ) | Ok(ebd) => ebd, }; From 35f3975e174f081afb5f62e3d8ce003c243df292 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Tue, 17 Jun 2025 00:24:53 +0200 Subject: [PATCH 10/10] fix(clippy): redundant_else --- src/uu/cp/src/cp.rs | 36 ++++---- src/uu/cut/src/cut.rs | 3 +- src/uu/cut/src/matcher.rs | 3 +- src/uu/date/src/date.rs | 132 +++++++++++++-------------- src/uu/dirname/src/dirname.rs | 36 ++++---- src/uu/env/src/env.rs | 8 +- src/uu/fmt/src/linebreak.rs | 3 +- src/uu/pr/src/pr.rs | 3 +- src/uu/sort/src/chunks.rs | 12 +-- src/uu/split/src/split.rs | 42 ++++----- src/uu/tail/src/chunks.rs | 14 +-- src/uucore/src/lib/features/perms.rs | 89 +++++++++--------- 12 files changed, 189 insertions(+), 192 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index d2966c5c4..3385e27c1 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1150,9 +1150,8 @@ impl Options { CpError::Error("SELinux was not enabled during the compile time!".to_owned()); if required { return Err(selinux_disabled_error); - } else { - show_error_if_needed(&selinux_disabled_error); } + show_error_if_needed(&selinux_disabled_error); } // Extract the SELinux related flags and options @@ -1925,10 +1924,9 @@ fn handle_existing_dest( source.quote() ) .into()); - } else { - is_dest_removed = dest.is_symlink(); - backup_dest(dest, &backup_path, is_dest_removed)?; } + is_dest_removed = dest.is_symlink(); + backup_dest(dest, &backup_path, is_dest_removed)?; } if !is_dest_removed { delete_dest_if_needed_and_allowed( @@ -2195,21 +2193,21 @@ fn handle_copy_mode( let dest_time = dest_metadata.modified()?; if src_time <= dest_time { return Ok(PerformedAction::Skipped); - } else { - options.overwrite.verify(dest, options.debug)?; - - copy_helper( - source, - dest, - options, - context, - source_is_symlink, - source_is_fifo, - symlinked_files, - #[cfg(unix)] - source_is_stream, - )?; } + + options.overwrite.verify(dest, options.debug)?; + + copy_helper( + source, + dest, + options, + context, + source_is_symlink, + source_is_fifo, + symlinked_files, + #[cfg(unix)] + source_is_stream, + )?; } } } else { diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 0c47cfada..c97a6b595 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -429,9 +429,8 @@ fn get_delimiters(matches: &ArgMatches) -> UResult<(Delimiter, Option<&[u8]>)> { 1, get_message("cut-error-delimiter-must-be-single-character"), )); - } else { - Delimiter::from(os_string) } + Delimiter::from(os_string) } } None => { diff --git a/src/uu/cut/src/matcher.rs b/src/uu/cut/src/matcher.rs index bb0c44d5b..b42941294 100644 --- a/src/uu/cut/src/matcher.rs +++ b/src/uu/cut/src/matcher.rs @@ -34,9 +34,8 @@ impl Matcher for ExactMatcher<'_> { || haystack[match_idx + 1..].starts_with(&self.needle[1..]) { return Some((match_idx, match_idx + self.needle.len())); - } else { - pos = match_idx + 1; } + pos = match_idx + 1; } None => { return None; diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 379aba67f..5e72c87cf 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -204,81 +204,81 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; return set_system_datetime(date); - } else { - // Get the current time, either in the local time zone or UTC. - let now = if settings.utc { - Timestamp::now().to_zoned(TimeZone::UTC) - } else { - Zoned::now() - }; + } - // Iterate over all dates - whether it's a single date or a file. - let dates: Box> = match settings.date_source { - DateSource::Custom(ref input) => { - let date = parse_date(input); - let iter = std::iter::once(date); - Box::new(iter) - } - DateSource::Human(relative_time) => { - // Double check the result is overflow or not of the current_time + relative_time - // it may cause a panic of chrono::datetime::DateTime add - match now.checked_add(relative_time) { - Ok(date) => { - let iter = std::iter::once(Ok(date)); - Box::new(iter) - } - Err(_) => { - return Err(USimpleError::new( - 1, - format!("invalid date {relative_time}"), - )); - } + // Get the current time, either in the local time zone or UTC. + let now = if settings.utc { + Timestamp::now().to_zoned(TimeZone::UTC) + } else { + Zoned::now() + }; + + // Iterate over all dates - whether it's a single date or a file. + let dates: Box> = match settings.date_source { + DateSource::Custom(ref input) => { + let date = parse_date(input); + let iter = std::iter::once(date); + Box::new(iter) + } + DateSource::Human(relative_time) => { + // Double check the result is overflow or not of the current_time + relative_time + // it may cause a panic of chrono::datetime::DateTime add + match now.checked_add(relative_time) { + Ok(date) => { + let iter = std::iter::once(Ok(date)); + Box::new(iter) } - } - DateSource::Stdin => { - let lines = BufReader::new(std::io::stdin()).lines(); - let iter = lines.map_while(Result::ok).map(parse_date); - Box::new(iter) - } - DateSource::File(ref path) => { - if path.is_dir() { + Err(_) => { return Err(USimpleError::new( - 2, - format!("expected file, got directory {}", path.quote()), + 1, + format!("invalid date {relative_time}"), )); } - let file = File::open(path) - .map_err_context(|| path.as_os_str().to_string_lossy().to_string())?; - let lines = BufReader::new(file).lines(); - let iter = lines.map_while(Result::ok).map(parse_date); - Box::new(iter) } - DateSource::Now => { - let iter = std::iter::once(Ok(now)); - Box::new(iter) + } + DateSource::Stdin => { + let lines = BufReader::new(std::io::stdin()).lines(); + let iter = lines.map_while(Result::ok).map(parse_date); + Box::new(iter) + } + DateSource::File(ref path) => { + if path.is_dir() { + return Err(USimpleError::new( + 2, + format!("expected file, got directory {}", path.quote()), + )); } - }; + let file = File::open(path) + .map_err_context(|| path.as_os_str().to_string_lossy().to_string())?; + let lines = BufReader::new(file).lines(); + let iter = lines.map_while(Result::ok).map(parse_date); + Box::new(iter) + } + DateSource::Now => { + let iter = std::iter::once(Ok(now)); + Box::new(iter) + } + }; - let format_string = make_format_string(&settings); + let format_string = make_format_string(&settings); - // Format all the dates - for date in dates { - match date { - // TODO: Switch to lenient formatting. - Ok(date) => match strtime::format(format_string, &date) { - Ok(s) => println!("{s}"), - Err(e) => { - return Err(USimpleError::new( - 1, - format!("invalid format {format_string} ({e})"), - )); - } - }, - Err((input, _err)) => show!(USimpleError::new( - 1, - format!("invalid date {}", input.quote()) - )), - } + // Format all the dates + for date in dates { + match date { + // TODO: Switch to lenient formatting. + Ok(date) => match strtime::format(format_string, &date) { + Ok(s) => println!("{s}"), + Err(e) => { + return Err(USimpleError::new( + 1, + format!("invalid format {format_string} ({e})"), + )); + } + }, + Err((input, _err)) => show!(USimpleError::new( + 1, + format!("invalid date {}", input.quote()) + )), } } diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index e7ff417db..a7ae457b6 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -33,27 +33,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if dirnames.is_empty() { return Err(UUsageError::new(1, get_message("dirname-missing-operand"))); - } else { - for path in &dirnames { - let p = Path::new(path); - match p.parent() { - Some(d) => { - if d.components().next().is_none() { - print!("."); - } else { - print_verbatim(d).unwrap(); - } - } - None => { - if p.is_absolute() || path == "/" { - print!("/"); - } else { - print!("."); - } + } + + for path in &dirnames { + let p = Path::new(path); + match p.parent() { + Some(d) => { + if d.components().next().is_none() { + print!("."); + } else { + print_verbatim(d).unwrap(); + } + } + None => { + if p.is_absolute() || path == "/" { + print!("/"); + } else { + print!("."); } } - print!("{line_ending}"); } + print!("{line_ending}"); } Ok(()) diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index dbf5f1d56..7bb877b72 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -594,9 +594,11 @@ impl EnvAppData { match cmd.status() { Ok(exit) if !exit.success() => { #[cfg(unix)] - if let Some(exit_code) = exit.code() { - return Err(exit_code.into()); - } else { + { + if let Some(exit_code) = exit.code() { + return Err(exit_code.into()); + } + // `exit.code()` returns `None` on Unix when the process is terminated by a signal. // See std::os::unix::process::ExitStatusExt for more information. This prints out // the interrupted process and the signal it received. diff --git a/src/uu/fmt/src/linebreak.rs b/src/uu/fmt/src/linebreak.rs index 6c34b0808..143228373 100644 --- a/src/uu/fmt/src/linebreak.rs +++ b/src/uu/fmt/src/linebreak.rs @@ -175,9 +175,8 @@ fn break_knuth_plass<'a, T: Clone + Iterator>>( fresh = true; } break; - } else { - write_with_spaces(word, slen, args.ostream)?; } + write_with_spaces(word, slen, args.ostream)?; } Ok((prev_punct, fresh)) }, diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 4ca97e784..5219851df 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -1086,9 +1086,8 @@ fn write_columns( } if not_found_break && feed_line_present { break; - } else { - out.write_all(line_separator)?; } + out.write_all(line_separator)?; } Ok(lines_printed) diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 18b2547dc..4b8ad4785 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -287,13 +287,13 @@ fn read_to_buffer( let end = last_line_end.unwrap(); // We want to include the separator here, because it shouldn't be carried over. return Ok((end + 1, true)); - } else { - // We need to read more lines - let len = buffer.len(); - // resize the vector to 10 KB more - buffer.resize(len + 1024 * 10, 0); - read_target = &mut buffer[len..]; } + + // We need to read more lines + let len = buffer.len(); + // resize the vector to 10 KB more + buffer.resize(len + 1024 * 10, 0); + read_target = &mut buffer[len..]; } else { // This file has been fully read. let mut leftover_len = read_target.len(); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index e026aaa2e..8736927a1 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -763,28 +763,28 @@ impl Write for ByteChunkWriter<'_> { let num_bytes_written = custom_write(buf, &mut self.inner, self.settings)?; self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64; return Ok(carryover_bytes_written + num_bytes_written); - } else { - // Write enough bytes to fill the current chunk. - // - // Conversion to usize is safe because we checked that - // self.num_bytes_remaining_in_current_chunk is lower than - // n, which is already usize. - let i = self.num_bytes_remaining_in_current_chunk as usize; - let num_bytes_written = custom_write(&buf[..i], &mut self.inner, self.settings)?; - self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64; - - // It's possible that the underlying writer did not - // write all the bytes. - if num_bytes_written < i { - return Ok(carryover_bytes_written + num_bytes_written); - } else { - // Move the window to look at only the remaining bytes. - buf = &buf[i..]; - - // Remember for the next iteration that we wrote these bytes. - carryover_bytes_written += num_bytes_written; - } } + + // Write enough bytes to fill the current chunk. + // + // Conversion to usize is safe because we checked that + // self.num_bytes_remaining_in_current_chunk is lower than + // n, which is already usize. + let i = self.num_bytes_remaining_in_current_chunk as usize; + let num_bytes_written = custom_write(&buf[..i], &mut self.inner, self.settings)?; + self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64; + + // It's possible that the underlying writer did not + // write all the bytes. + if num_bytes_written < i { + return Ok(carryover_bytes_written + num_bytes_written); + } + + // Move the window to look at only the remaining bytes. + buf = &buf[i..]; + + // Remember for the next iteration that we wrote these bytes. + carryover_bytes_written += num_bytes_written; } } fn flush(&mut self) -> io::Result<()> { diff --git a/src/uu/tail/src/chunks.rs b/src/uu/tail/src/chunks.rs index 7d53b95d4..0811b4306 100644 --- a/src/uu/tail/src/chunks.rs +++ b/src/uu/tail/src/chunks.rs @@ -582,13 +582,13 @@ impl LinesChunkBuffer { if self.chunks.is_empty() { // chunks is empty when a file is empty so quitting early here return Ok(()); - } else { - let length = &self.chunks.len(); - let last = &mut self.chunks[length - 1]; - if !last.get_buffer().ends_with(&[self.delimiter]) { - last.lines += 1; - self.lines += 1; - } + } + + let length = &self.chunks.len(); + let last = &mut self.chunks[length - 1]; + if !last.get_buffer().ends_with(&[self.delimiter]) { + last.lines += 1; + self.lines += 1; } // skip unnecessary chunks and save the first chunk which may hold some lines we have to diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index d044fce81..52da95cd1 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -113,51 +113,52 @@ pub fn wrap_chown>( } } return Err(out); - } else { - let changed = dest_uid != meta.uid() || dest_gid != meta.gid(); - if changed { - match verbosity.level { - VerbosityLevel::Changes | VerbosityLevel::Verbose => { - let gid = meta.gid(); - out = if verbosity.groups_only { - format!( - "changed group of {} from {} to {}", - path.quote(), - entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()), - entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) - ) - } else { - let gid = meta.gid(); - let uid = meta.uid(); - format!( - "changed ownership of {} from {}:{} to {}:{}", - path.quote(), - entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()), - entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()), - entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()), - entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) - ) - }; - } - _ => (), - }; - } else if verbosity.level == VerbosityLevel::Verbose { - out = if verbosity.groups_only { - format!( - "group of {} retained as {}", - path.quote(), - entries::gid2grp(dest_gid).unwrap_or_default() - ) - } else { - format!( - "ownership of {} retained as {}:{}", - path.quote(), - entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()), - entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) - ) - }; - } } + + let changed = dest_uid != meta.uid() || dest_gid != meta.gid(); + if changed { + match verbosity.level { + VerbosityLevel::Changes | VerbosityLevel::Verbose => { + let gid = meta.gid(); + out = if verbosity.groups_only { + format!( + "changed group of {} from {} to {}", + path.quote(), + entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()), + entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) + ) + } else { + let gid = meta.gid(); + let uid = meta.uid(); + format!( + "changed ownership of {} from {}:{} to {}:{}", + path.quote(), + entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()), + entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()), + entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()), + entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) + ) + }; + } + _ => (), + }; + } else if verbosity.level == VerbosityLevel::Verbose { + out = if verbosity.groups_only { + format!( + "group of {} retained as {}", + path.quote(), + entries::gid2grp(dest_gid).unwrap_or_default() + ) + } else { + format!( + "ownership of {} retained as {}:{}", + path.quote(), + entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()), + entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) + ) + }; + } + Ok(out) }