diff --git a/Cargo.toml b/Cargo.toml index 75b6b07c855..8c4a71824d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -720,7 +720,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [ unused_qualifications = "warn" [workspace.lints.clippy] -collapsible_if = { level = "allow", priority = 127 } # remove me # The counts were generated with this command: # cargo clippy --all-targets --workspace --message-format=json --quiet \ # | jq -r '.message.code.code | select(. != null and startswith("clippy::"))' \ diff --git a/src/uu/date/src/format_modifiers.rs b/src/uu/date/src/format_modifiers.rs index bd87f464786..425052c0a81 100644 --- a/src/uu/date/src/format_modifiers.rs +++ b/src/uu/date/src/format_modifiers.rs @@ -316,6 +316,7 @@ fn strip_default_padding(value: &str) -> String { if stripped.is_empty() { return "0".to_string(); } + #[allow(clippy::collapsible_if)] if let Some(first_char) = stripped.chars().next() { if first_char.is_ascii_digit() { return stripped.to_string(); @@ -443,6 +444,7 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result 4 digits) + #[allow(clippy::collapsible_if)] if force_sign && !result.starts_with('+') && !result.starts_with('-') { if result.chars().next().is_some_and(|c| c.is_ascii_digit()) { let default_w = get_default_width(specifier); diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index f7d5efdaaf3..a947b622e38 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -156,7 +156,7 @@ impl Options { let exclude: Option> = matches .get_many::(OPT_EXCLUDE_TYPE) .map(|v| v.map(|s| s.to_string_lossy().to_string()).collect()); - + #[allow(clippy::collapsible_if)] if let (Some(include), Some(exclude)) = (&include, &exclude) { if let Some(types) = Self::get_intersected_types(include, exclude) { return Err(OptionsError::FilesystemTypeBothSelectedAndExcluded(types)); @@ -235,11 +235,13 @@ fn is_included(mi: &MountInfo, opt: &Options) -> bool { } // Don't show filesystems if they have been explicitly excluded. + #[allow(clippy::collapsible_if)] if let Some(ref excludes) = opt.exclude { if excludes.contains(&mi.fs_type) { return false; } } + #[allow(clippy::collapsible_if)] if let Some(ref includes) = opt.include { if !includes.contains(&mi.fs_type) { return false; @@ -311,6 +313,7 @@ fn get_all_filesystems(opt: &Options) -> UResult> { // this loop quadratic in the length of `vmi`. This could be // improved by a more efficient implementation of `is_best()`, // but `vmi` is probably not very long in practice. + #[allow(clippy::collapsible_if)] if is_included(&mi, opt) && is_best(&mounts, &mi) { let dev_path: &Path = Path::new(&mi.dev_name); // Only check is_symlink() for absolute paths. For non-absolute paths diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 20409f621b7..8d0d4994dc0 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -517,6 +517,7 @@ fn safe_du( } // Process directories recursively + #[allow(clippy::collapsible_if)] if is_dir { if options.one_file_system { if let (Some(this_inode), Some(my_inode)) = (this_stat.inode, my_stat.inode) { @@ -637,6 +638,7 @@ fn du_regular( && options.dereference == Deref::All && this_stat.metadata.is_dir() { + #[allow(clippy::collapsible_if)] if let Some(inode) = this_stat.inode { if ancestors.contains(&inode) { // This symlink points to an ancestor directory - skip to avoid cycle @@ -674,7 +676,7 @@ fn du_regular( // Mark this inode as seen seen_inodes.insert(inode); } - + #[allow(clippy::collapsible_if)] if this_stat.metadata.is_dir() { if options.one_file_system { if let (Some(this_inode), Some(my_inode)) = @@ -1143,6 +1145,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Pre-populate seen_inodes with the starting directory to detect cycles let stat = Stat::new(&path, None, &traversal_options); + #[allow(clippy::collapsible_if)] if let Ok(stat) = stat.as_ref() { if let Some(inode) = stat.inode { if !traversal_options.count_links && seen_inodes.contains(&inode) { @@ -1172,6 +1175,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } Err(e) => { // Check if this is our "already handled" error + #[allow(clippy::collapsible_if)] if let mpsc::SendError(Err(simple_error)) = e.as_ref() { if simple_error.code() == 0 { // Error already handled, continue to next file diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 3343544253e..fb12c8c795a 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -697,6 +697,7 @@ impl EnvAppData { self.do_input_debug_printing = self .do_input_debug_printing .or(Some(matches.get_count("debug") >= 2)); + #[allow(clippy::collapsible_if)] if let Some(value) = self.do_input_debug_printing { if value { debug_print_args(&original_args); diff --git a/src/uu/env/src/variable_parser.rs b/src/uu/env/src/variable_parser.rs index da200c9dba6..cb8f4e71813 100644 --- a/src/uu/env/src/variable_parser.rs +++ b/src/uu/env/src/variable_parser.rs @@ -18,6 +18,7 @@ impl<'a> VariableParser<'a, '_> { } fn check_variable_name_start(&self) -> Result<(), EnvError> { + #[allow(clippy::collapsible_if)] if let Some(c) = self.get_current_char() { if c.is_ascii_digit() { return Err(EnvError::EnvParsingOfVariableUnexpectedNumber( diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index 2c2599a8451..eea1fb743c8 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -518,6 +518,7 @@ fn evaluate_match_expression(left_bytes: Vec, right_bytes: Vec) -> ExprR let left_encoded = onig::EncodedBytes::ascii(&left_bytes); let pos = regex_search(®ex, left_encoded, left_bytes.len(), &mut region); + #[allow(clippy::collapsible_if)] if pos.is_some() { if let Some((start, end)) = region.pos(1) { let capture_bytes = &left_bytes[start..end]; diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 5fb75a86730..bc39eed52a2 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -298,6 +298,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) let remove_target = || { // In that case, we don't want to do link resolution // We need to clean the target + #[allow(clippy::collapsible_if)] if target_dir.is_file() { if let Err(e) = fs::remove_file(target_dir) { show_error!( @@ -374,6 +375,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) } fn relative_path<'a>(src: &'a Path, dst: &Path) -> Cow<'a, Path> { + #[allow(clippy::collapsible_if)] if let Ok(src_abs) = canonicalize(src, MissingHandling::Missing, ResolveMode::Physical) { if let Ok(dst_abs) = canonicalize( dst.parent().unwrap(), diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs index a50418cd987..a3195f19c50 100644 --- a/src/uu/ls/src/colors.rs +++ b/src/uu/ls/src/colors.rs @@ -73,6 +73,7 @@ impl<'a> StyleManager<'a> { let mut force_suffix_reset: bool = false; let mut applied_raw_code = false; + #[allow(clippy::collapsible_if)] if self.is_reset() { if let Some(norm_sty) = self.get_normal_style().copied() { style_code.push_str(&self.get_style_code(&norm_sty)); @@ -324,6 +325,7 @@ impl<'a> StyleManager<'a> { return None; } let mut target = path.path().read_link().ok()?; + #[allow(clippy::collapsible_if)] if target.is_relative() { if let Some(parent) = path.path().parent() { target = parent.join(target); @@ -404,6 +406,7 @@ impl<'a> StyleManager<'a> { #[cfg(unix)] fn indicator_for_file(&self, path: &PathData) -> Option { + #[allow(clippy::collapsible_if)] if self.needs_file_metadata() { if let Some(metadata) = path.metadata() { let mode = metadata.mode(); @@ -442,6 +445,7 @@ impl<'a> StyleManager<'a> { #[cfg(unix)] fn indicator_for_directory(&self, path: &PathData) -> Option { + #[allow(clippy::collapsible_if)] if self.needs_dir_metadata() { if let Some(metadata) = path.metadata() { let mode = metadata.mode(); @@ -541,6 +545,7 @@ pub(crate) fn color_name( } } + #[allow(clippy::collapsible_if)] if target_symlink.is_none() && path.file_type().is_some_and(fs::FileType::is_symlink) { if let Some(colored) = style_manager.color_symlink_name(path, name.clone(), wrap) { return colored; diff --git a/src/uu/ls/src/config.rs b/src/uu/ls/src/config.rs index 2cc87c788c3..059bc26dbbc 100644 --- a/src/uu/ls/src/config.rs +++ b/src/uu/ls/src/config.rs @@ -719,6 +719,7 @@ impl Config { { format = Format::Long; } else if let Some(mut indices) = options.indices_of(options::format::ONE_LINE) { + #[allow(clippy::collapsible_if)] if options.value_source(options::format::ONE_LINE) == Some(clap::parser::ValueSource::CommandLine) && indices.any(|i| i > idx) @@ -918,6 +919,7 @@ impl Config { locale_quoting = None; } + #[allow(clippy::collapsible_if)] if needs_color { if let Err(err) = validate_ls_colors_env() { if let LsColorsParseError::UnrecognizedPrefix(prefix) = &err { diff --git a/src/uu/ls/src/display.rs b/src/uu/ls/src/display.rs index 74180ea1e5e..241763e5788 100644 --- a/src/uu/ls/src/display.rs +++ b/src/uu/ls/src/display.rs @@ -700,6 +700,7 @@ fn display_item_name( name = color_name(name, path, style_manager, None, is_wrap(len)); } + #[allow(clippy::collapsible_if)] if config.format != Format::Long { if let Some(info) = more_info { let old_name = name; @@ -822,6 +823,7 @@ fn display_item_name( // Prepend the security context to the `name` and adjust `width` in order // to get correct alignment from later calls to`display_grid()`. + #[allow(clippy::collapsible_if)] if config.context { if let Some(pad_count) = prefix_context { let security_context: Cow<'_, str> = if matches!(config.format, Format::Commas) { @@ -1263,6 +1265,7 @@ fn calculate_padding_collection( padding_collections.inode = inode_len.max(padding_collections.inode); } + #[allow(clippy::collapsible_if)] if config.alloc_size { if let Some(md) = item.metadata() { let block_size_len = display_size(get_block_size(md, config), config).len(); @@ -1335,6 +1338,7 @@ fn calculate_padding_collection( }; for item in items { + #[allow(clippy::collapsible_if)] if config.alloc_size { if let Some(md) = item.metadata() { let block_size_len = display_size(get_block_size(md, config), config).len(); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 1f8889acfac..70fd6b4fc36 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -879,6 +879,7 @@ impl<'a> PathData<'a> { let security_context: OnceCell> = OnceCell::new(); let de: RefCell> = if let Some(de) = dir_entry { + #[allow(clippy::collapsible_if)] if must_dereference { if let Ok(md_pb) = p_buf.metadata() { ft.get_or_init(|| Some(md_pb.file_type())); @@ -910,6 +911,7 @@ impl<'a> PathData<'a> { fn metadata(&self) -> Option<&Metadata> { self.md .get_or_init(|| { + #[allow(clippy::collapsible_if)] if !self.must_dereference { if let Some(dir_entry) = RefCell::take(&self.de) { return dir_entry.metadata().ok(); @@ -926,6 +928,7 @@ impl<'a> PathData<'a> { // but GNU will not throw an error until a bad fd "dir" // is entered, here we match that GNU behavior, by handing // back the non-dereferenced metadata upon an EBADF + #[allow(clippy::collapsible_if)] if self.must_dereference && errno == 9i32 { if let Ok(file) = self.path().read_link() { return file.symlink_metadata().ok(); @@ -1118,6 +1121,7 @@ impl LsOutput for TextOutput<'_> { } fn initialize(&mut self, _config: &Config) -> UResult<()> { + #[allow(clippy::collapsible_if)] if let Some(style_manager) = self.state.style_manager.as_mut() { if style_manager.get_normal_style().is_some() { let to_write = style_manager.reset(true); @@ -1564,6 +1568,7 @@ fn get_security_context<'a>( // If we must dereference, ensure that the symlink is actually valid even if the system // does not support SELinux. // Conforms to the GNU coreutils where a dangling symlink results in exit code 1. + #[allow(clippy::collapsible_if)] if must_dereference { if let Err(err) = get_metadata_with_deref_opt(path, must_dereference) { // The Path couldn't be dereferenced, so return early and set exit code 1 diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index 0ad3006024c..f4fb4786289 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -550,6 +550,7 @@ impl<'a> Pager<'a> { return Ok(()); } loop { + #[allow(clippy::collapsible_if)] if event::poll(Duration::from_millis(100))? { if let Event::Key(KeyEvent { code: KeyCode::Enter, diff --git a/src/uu/mv/src/hardlink.rs b/src/uu/mv/src/hardlink.rs index 8ef687e3562..0a1a6d2aaf6 100644 --- a/src/uu/mv/src/hardlink.rs +++ b/src/uu/mv/src/hardlink.rs @@ -176,6 +176,7 @@ impl HardlinkGroupScanner { self.source_files = files.to_vec(); for file in files { + #[allow(clippy::collapsible_if)] if let Err(e) = self.scan_single_path(file) { if options.verbose { // Only show warnings for verbose mode diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index ee70b376b65..17961c54422 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -193,6 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .get_one::(OPT_TARGET_DIRECTORY) .map(OsString::from); + #[allow(clippy::collapsible_if)] if let Some(ref maybe_dir) = target_dir { if !Path::new(&maybe_dir).is_dir() { return Err(MvError::TargetNotADirectory(maybe_dir.quote().to_string()).into()); @@ -1127,7 +1128,7 @@ fn copy_dir_contents_recursive( print_verbose(&from_path, &to_path); } - + #[allow(clippy::collapsible_if)] if let Some(pb) = progress_bar { if let Ok(metadata) = from_path.metadata() { pb.inc(metadata.len()); diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index 28e32631c39..387b85297a1 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -396,7 +396,7 @@ fn transform_from( detailed_error_message(s, opts.from, &options.unit_separator).unwrap_or(original) })?; let had_no_suffix = suffix.is_none(); - + #[allow(clippy::collapsible_if)] if had_no_suffix { if let Some(scaled) = try_scale_exact_int_with_from_unit(i, opts.from_unit) { return Ok(scaled); diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 78202dcbdc8..6db879bb06f 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -50,6 +50,7 @@ fn format_and_write( }; // Return false if the input is in scientific notation + #[allow(clippy::collapsible_if)] if let Some(pos) = line.iter().position(|&b| b == b'E' || b == b'e') { if pos < line.len() - 1 { if line[pos + 1].is_ascii_digit() { @@ -186,6 +187,7 @@ fn parse_unit_size(s: &str) -> Result { // Reject all-zero numeric parts like "0" or "00K". let all_zero = !number.is_empty() && number.bytes().all(|b| b == b'0'); + #[allow(clippy::collapsible_if)] if !all_zero { if let Some(multiplier) = parse_unit_size_suffix(suffix) { if number.is_empty() { diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index d74c65cc592..ae3333f36e2 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -437,6 +437,7 @@ fn recreate_arguments(args: &[String]) -> Vec { let e_regex = Regex::new(r"^-e").unwrap(); let mut arguments = args.to_owned(); let num_option = args.iter().find_position(|x| n_regex.is_match(x.trim())); + #[allow(clippy::collapsible_if)] if let Some((pos, _value)) = num_option { if let Some(num_val_opt) = args.get(pos + 1) { if !num_regex.is_match(num_val_opt) { @@ -452,6 +453,7 @@ fn recreate_arguments(args: &[String]) -> Vec { let expand_tabs_option = arguments .iter() .find_position(|x| e_regex.is_match(x.trim())); + #[allow(clippy::collapsible_if)] if let Some((pos, value)) = expand_tabs_option { if value.trim().len() <= 2 { arguments[pos] = "-e\t8".to_string(); @@ -695,7 +697,7 @@ fn build_options( Some(res) => Some(res?), None => end_page_in_plus_option, }; - + #[allow(clippy::collapsible_if)] if let Some(end_page) = end_page { if start_page > end_page { return Err(PrError::EncounteredErrors { diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 64a5e2bacbe..f72b6b78328 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -217,6 +217,7 @@ fn get_config(matches: &mut clap::ArgMatches) -> UResult { // In the future, we might want to switch to the onig crate (like expr does) for better compatibility. // Verify regex is valid and doesn't match empty string + #[allow(clippy::collapsible_if)] if let Ok(re) = Regex::new(®ex) { if re.is_match("") { return Err(USimpleError::new(1, translate!("ptx-error-empty-regexp"))); diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 5f2b981ea2b..a9e5b920473 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -535,6 +535,7 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool { } // Only finish progress bar if it was created and files were processed + #[allow(clippy::collapsible_if)] if let Some(pb) = progress_bar { if any_files_processed { pb.finish(); diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index f35b1a0db2c..7bac8bc5c61 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -516,6 +516,7 @@ fn create_test_compatible_sequence( .seek(SeekFrom::Start(0)) .map_err_context(|| translate!("shred-failed-to-seek-file"))?; let mut buffer = [0u8; 1024]; + #[allow(clippy::collapsible_if)] if let Ok(bytes_read) = file_cell.borrow_mut().read(&mut buffer) { if bytes_read > 0 && buffer[..bytes_read].iter().all(|&b| b == 0x55) { // This is the test scenario - replicate exact algorithm diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index ce6b2118be4..52deef52b47 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -367,6 +367,7 @@ fn read_to_buffer( loop { match file.read(read_target) { Ok(0) => { + #[allow(clippy::collapsible_if)] if read_target.is_empty() { // chunk is full if let Some(max_buffer_size) = max_buffer_size { diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index df03a3da612..e6c5a6ef9a4 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -44,6 +44,7 @@ fn replace_output_file_in_input_files( let mut copy: Option = None; if let Some(Ok(output_path)) = output.map(|path| Path::new(path).canonicalize()) { for file in files { + #[allow(clippy::collapsible_if)] if let Ok(file_path) = Path::new(file).canonicalize() { if file_path == output_path { if let Some(copy) = © { @@ -330,6 +331,7 @@ impl FileMerger<'_> { file.current_chunk.with_dependent(|_, contents| { let current_line = &contents.lines[file.line_idx]; + #[allow(clippy::collapsible_if)] if settings.unique { if let Some(prev) = &prev { let cmp = compare_by( @@ -361,7 +363,7 @@ impl FileMerger<'_> { // This will cause the comparison to use a different line and the heap to readjust. self.heap.peek_mut().unwrap().line_idx += 1; } - + #[allow(clippy::collapsible_if)] if let Some(prev) = prev { if let Ok(prev_chunk) = Rc::try_unwrap(prev.chunk) { // If nothing is referencing the previous chunk anymore, this means that the previous line diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 8b321b55d53..67fb439648a 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -764,6 +764,7 @@ impl<'a> Line<'a> { selection.end += leading_whitespace; } else { // include a trailing si unit + #[allow(clippy::collapsible_if)] if selector.settings.mode == SortMode::HumanNumeric { if let Some( b'k' | b'K' | b'M' | b'G' | b'T' | b'P' | b'E' | b'Z' | b'Y' | b'R' @@ -1633,6 +1634,7 @@ where if starts_with_plus(&arg) { let as_str = arg.to_string_lossy(); + #[allow(clippy::collapsible_if)] if let Some(from_spec) = as_str.strip_prefix('+') { if let Some(from) = parse_legacy_part(from_spec) { let mut to_part = None; @@ -1715,6 +1717,7 @@ fn index_legacy_warnings(processed_args: &[OsString], legacy_warnings: &mut [Leg } } else { let as_str = arg.to_string_lossy(); + #[allow(clippy::collapsible_if)] if let Some(spec) = as_str.strip_prefix("-k") { if !spec.is_empty() { key_index = key_index.saturating_add(1); @@ -1728,7 +1731,7 @@ fn index_legacy_warnings(processed_args: &[OsString], legacy_warnings: &mut [Leg } i += 1; } - + #[allow(clippy::collapsible_if)] if matched_key { if let Some(&warning_idx) = index_by_arg.get(&i.saturating_sub(1)) { legacy_warnings[warning_idx].key_index = Some(key_index); @@ -2010,6 +2013,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), processed_args, 2)?; // Prevent -o/--output to be specified multiple times + #[allow(clippy::collapsible_if)] if let Some(mut outputs) = matches.get_many::(options::OUTPUT) { if let Some(first) = outputs.next() { if outputs.any(|out| out != first) { diff --git a/src/uu/sort/src/tmp_dir.rs b/src/uu/sort/src/tmp_dir.rs index e3851bb054b..dad04734f59 100644 --- a/src/uu/sort/src/tmp_dir.rs +++ b/src/uu/sort/src/tmp_dir.rs @@ -66,7 +66,7 @@ fn ensure_signal_handler_installed(state: Arc>) -> UR let state = handler_state.lock().unwrap(); (state.lock.clone(), state.path.clone()) }; - + #[allow(clippy::collapsible_if)] if let Some(lock) = lock { let _guard = lock.lock().unwrap(); if let Some(path) = path { diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 50e615c988b..853f87d215a 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -249,6 +249,7 @@ fn translate_regex_flavor(bytes: &[u8]) -> String { continue; } // Unescape escaped (), |, {} when not inside brackets + #[allow(clippy::collapsible_if)] b'\\' if !inside_brackets && !is_escaped => { if let Some(next) = bytes.get(i + 1) { if matches!(next, b'(' | b')' | b'|' | b'{' | b'}') { diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index 699d2f5f79d..a3354a8fe2f 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -62,6 +62,7 @@ impl FileHandling { /// Canonicalize `path` if it is not already an absolute path fn canonicalize_path(path: &Path) -> PathBuf { + #[allow(clippy::collapsible_if)] if path.is_relative() && !path.is_stdin() { if let Ok(p) = path.canonicalize() { return p; diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 7300e954087..a1c3ac7725e 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -389,6 +389,7 @@ impl Observer { // | EventKind::Modify(ModifyKind::Name(RenameMode::Any)) | EventKind::Modify(ModifyKind::Name(RenameMode::From)) => { + #[allow(clippy::collapsible_if)] if self.follow_name() { if settings.retry { if let Some(old_md) = self.files.get_mut_metadata(event_path) { @@ -548,6 +549,7 @@ pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { settings: &Settings, paths: &mut Vec| -> UResult<()> { + #[allow(clippy::collapsible_if)] if let Some(event_path) = event.paths.first() { if observer.files.contains_key(event_path) { // Handle Event if it is about a path that we are monitoring @@ -586,6 +588,7 @@ pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { kind: notify::ErrorKind::Io(ref e), paths, })) if e.kind() == std::io::ErrorKind::NotFound => { + #[allow(clippy::collapsible_if)] if let Some(event_path) = paths.first() { if observer.files.contains_key(event_path) { let _ = observer diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 509a5619d6e..dad083148c2 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -260,6 +260,7 @@ fn tail_stdin( // on macOS and Linux. #[cfg(target_os = "macos")] { + #[allow(clippy::collapsible_if)] if let Ok(mut stdin_handle) = same_file::Handle::stdin() { if let Ok(meta) = stdin_handle.as_file_mut().metadata() { if meta.file_type().is_dir() { diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index bcb688ee7b3..5263718599a 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -708,6 +708,7 @@ fn parse_date(ref_zoned: Zoned, s: &str) -> Result { } // "@%s" is "The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). (TZ) (Calculated from mktime(tm).)" + #[allow(clippy::collapsible_if)] if s.bytes().next() == Some(b'@') { if let Ok(ts) = &s[1..].parse::() { return Ok(FileTime::from_unix_time(*ts, 0)); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index c4f090ed737..ff1a1969b29 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -115,6 +115,7 @@ fn parse_tabstops(s: &str) -> Result { // Handle the increment if specified // Only add an extra tab stop if increment is non-zero + #[allow(clippy::collapsible_if)] if let Some(inc) = increment_size { if inc > 0 { let last = *nums.last().unwrap(); diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 2aa46d24961..3f7ffd46870 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -84,6 +84,7 @@ fn detect_target_utility() -> Option { println!("cargo:rerun-if-env-changed=UUCORE_TARGET_UTIL"); // First check if an explicit environment variable was set + #[allow(clippy::collapsible_if)] if let Ok(target_util) = env::var("UUCORE_TARGET_UTIL") { if !target_util.is_empty() { return Some(target_util); @@ -91,6 +92,7 @@ fn detect_target_utility() -> Option { } // Auto-detect utility name from CARGO_PKG_NAME if it's a uu_* package + #[allow(clippy::collapsible_if)] if let Ok(pkg_name) = env::var("CARGO_PKG_NAME") { if let Some(util_name) = pkg_name.strip_prefix("uu_") { println!("cargo:warning=Auto-detected utility name: {util_name}"); @@ -186,6 +188,7 @@ fn embed_all_utility_locales( let mut util_dirs = Vec::new(); for entry in fs::read_dir(&src_uu_dir)? { let entry = entry?; + #[allow(clippy::collapsible_if)] if entry.file_type()?.is_dir() { if let Some(dir_name) = entry.file_name().to_str() { util_dirs.push(dir_name.to_string()); @@ -247,6 +250,7 @@ fn embed_static_utility_locales( for entry in entries { let file_name = entry.file_name(); + #[allow(clippy::collapsible_if)] if let Some(dir_name) = file_name.to_str() { // Match uu_- if let Some((util_part, _)) = dir_name.split_once('-') { @@ -364,6 +368,7 @@ where F: Fn(&str) -> PathBuf, { let en_path = path_builder("en-US"); + #[allow(clippy::collapsible_if)] if let Some(locale_dir) = en_path.parent() { if locale_dir.exists() { for entry in std::fs::read_dir(locale_dir)? { diff --git a/src/uucore/src/lib/features/checksum/validate.rs b/src/uucore/src/lib/features/checksum/validate.rs index bb47ff6c920..8d0f9f77d43 100644 --- a/src/uucore/src/lib/features/checksum/validate.rs +++ b/src/uucore/src/lib/features/checksum/validate.rs @@ -504,6 +504,7 @@ fn get_raw_expected_digest(checksum: &str, bit_len_hint: Option) -> Optio // If the length of the string matches the one to be expected (in case it's // given) AND the digest can be decoded as hexadecimal, just go with it. + #[allow(clippy::collapsible_if)] if checks_hint(checksum.len() / 2) { if let Ok(raw_ck) = hex::decode(checksum) { return Some(raw_ck); diff --git a/src/uucore/src/lib/features/format/escape.rs b/src/uucore/src/lib/features/format/escape.rs index 2c6a0283a6e..97aa8dbcf67 100644 --- a/src/uucore/src/lib/features/format/escape.rs +++ b/src/uucore/src/lib/features/format/escape.rs @@ -122,6 +122,7 @@ pub fn parse_escape_code( rest: &mut &[u8], zero_octal_parsing: OctalParsing, ) -> Result { + #[allow(clippy::collapsible_if)] if let [c, new_rest @ ..] = rest { // This is for the \NNN syntax for octal sequences. // Note that '0' is intentionally omitted because that diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index d165b8a9f68..72e851730ac 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -637,6 +637,7 @@ pub fn infos_refer_to_same_file( info1: IOResult, info2: IOResult, ) -> bool { + #[allow(clippy::collapsible_if)] if let Ok(info1) = info1 { if let Ok(info2) = info2 { return info1 == info2; diff --git a/src/uucore/src/lib/features/fsxattr.rs b/src/uucore/src/lib/features/fsxattr.rs index d9683264652..bc9b6adc278 100644 --- a/src/uucore/src/lib/features/fsxattr.rs +++ b/src/uucore/src/lib/features/fsxattr.rs @@ -36,6 +36,7 @@ pub fn copy_xattrs>(source: P, dest: P) -> std::io::Result<()> { #[cfg(unix)] pub fn copy_xattrs_skip_selinux>(source: P, dest: P) -> std::io::Result<()> { for attr_name in xattr::list(&source)? { + #[allow(clippy::collapsible_if)] if attr_name.to_string_lossy() != "security.selinux" { if let Some(value) = xattr::get(&source, &attr_name)? { xattr::set(&dest, &attr_name, &value)?; diff --git a/src/uucore/src/lib/features/i18n/datetime.rs b/src/uucore/src/lib/features/i18n/datetime.rs index ce52013605f..c9e2d03daf7 100644 --- a/src/uucore/src/lib/features/i18n/datetime.rs +++ b/src/uucore/src/lib/features/i18n/datetime.rs @@ -116,11 +116,13 @@ pub fn localize_format_string(format: &str, date: JiffDate) -> String { // Format localized names using ICU DateTimeFormatter let locale_prefs = locale.clone().into(); + #[allow(clippy::collapsible_if)] if fmt.contains("%B") { if let Ok(f) = DateTimeFormatter::try_new(locale_prefs, fieldsets::M::long()) { fmt = fmt.replace("%B", &f.format(&iso_date).to_string()); } } + #[allow(clippy::collapsible_if)] if fmt.contains("%b") || fmt.contains("%h") { if let Ok(f) = DateTimeFormatter::try_new(locale_prefs, fieldsets::M::medium()) { // ICU's medium format may include trailing periods (e.g., "febr." for Hungarian), @@ -135,11 +137,13 @@ pub fn localize_format_string(format: &str, date: JiffDate) -> String { .replace("%h", &month_abbrev); } } + #[allow(clippy::collapsible_if)] if fmt.contains("%A") { if let Ok(f) = DateTimeFormatter::try_new(locale_prefs, fieldsets::E::long()) { fmt = fmt.replace("%A", &f.format(&iso_date).to_string()); } } + #[allow(clippy::collapsible_if)] if fmt.contains("%a") { if let Ok(f) = DateTimeFormatter::try_new(locale_prefs, fieldsets::E::short()) { fmt = fmt.replace("%a", &f.format(&iso_date).to_string()); diff --git a/src/uucore/src/lib/features/parser/num_parser.rs b/src/uucore/src/lib/features/parser/num_parser.rs index 7550e8dd79f..88a26740fd8 100644 --- a/src/uucore/src/lib/features/parser/num_parser.rs +++ b/src/uucore/src/lib/features/parser/num_parser.rs @@ -290,6 +290,7 @@ fn parse_digits(base: Base, str: &str, fractional: bool) -> (Option, i6 // If allowed, parse the fractional part of the number if there can be one and the // input contains a '.' decimal separator. + #[allow(clippy::collapsible_if)] if fractional { if let Some(rest) = rest.strip_prefix('.') { return base.parse_digits_count(rest, digits); @@ -330,6 +331,7 @@ fn parse_exponent(base: Base, str: &str) -> (Option, &str) { /// Parse a multiplier from allowed suffixes (e.g. s/m/h). fn parse_suffix_multiplier<'a>(str: &'a str, allowed_suffixes: &[(char, u32)]) -> (u32, &'a str) { + #[allow(clippy::collapsible_if)] if let Some(ch) = str.chars().next() { if let Some(mul) = allowed_suffixes .iter() diff --git a/src/uucore/src/lib/features/parser/parse_size.rs b/src/uucore/src/lib/features/parser/parse_size.rs index 15a6d58b8c5..cbe15e83308 100644 --- a/src/uucore/src/lib/features/parser/parse_size.rs +++ b/src/uucore/src/lib/features/parser/parse_size.rs @@ -378,6 +378,7 @@ impl<'parser> Parser<'parser> { // Binary prefix: "0b" followed by at least one binary digit (0 or 1) // Note: "0b" alone is treated as decimal 0 with suffix "b" + #[allow(clippy::collapsible_if)] if let Some(prefix) = size.strip_prefix("0b") { if !prefix.is_empty() { return NumberSystem::Binary; diff --git a/src/uucore/src/lib/features/proc_info.rs b/src/uucore/src/lib/features/proc_info.rs index 0d99cb8a8b9..5fc4e43b9af 100644 --- a/src/uucore/src/lib/features/proc_info.rs +++ b/src/uucore/src/lib/features/proc_info.rs @@ -310,6 +310,7 @@ impl ProcessInformation { }; for dir in result.flatten().filter(|it| it.path().is_symlink()) { + #[allow(clippy::collapsible_if)] if let Ok(path) = fs::read_link(dir.path()) { if let Ok(tty) = Teletype::try_from(path) { return tty; diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index 8d33cd081a2..aea6551a356 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -64,6 +64,7 @@ fn get_macos_boot_time_sysctl() -> Option { .arg("kern.boottime") .output(); + #[allow(clippy::collapsible_if)] if let Ok(output) = output { if output.status.success() { // Parse output format: { sec = 1729338352, usec = 0 } Wed Oct 19 08:25:52 2025 diff --git a/src/uucore/src/lib/mods/clap_localization.rs b/src/uucore/src/lib/mods/clap_localization.rs index fc4f838c216..f8b4ca0f9e3 100644 --- a/src/uucore/src/lib/mods/clap_localization.rs +++ b/src/uucore/src/lib/mods/clap_localization.rs @@ -219,6 +219,7 @@ impl<'a> ErrorFormatter<'a> { } // Show possible values for InvalidValue errors + #[allow(clippy::collapsible_if)] if matches!(err.kind(), ErrorKind::InvalidValue) { if let Some(valid_values) = err.get(ContextKind::ValidValue) { if !valid_values.to_string().is_empty() { diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs index 99afc8c0c8a..1164cbf69ab 100644 --- a/src/uucore/src/lib/mods/locale.rs +++ b/src/uucore/src/lib/mods/locale.rs @@ -93,6 +93,7 @@ impl Localizer { } // Fall back to English bundle if available + #[allow(clippy::collapsible_if)] if let Some(ref fallback) = self.fallback_bundle { if let Some(message) = fallback.get_message(id).and_then(|m| m.value()) { let mut errs = Vec::new(); @@ -283,6 +284,7 @@ fn create_english_bundle_from_embedded( } // Checksum algorithms need locale messages from checksum_common + #[allow(clippy::collapsible_if)] if util_name.ends_with("sum") { if let Some(uucore_content) = get_embedded_locale("checksum_common/en-US.ftl") { let uucore_resource = parse_fluent_resource(uucore_content, &CHECKSUM_FLUENT)?; @@ -320,6 +322,7 @@ fn create_wasi_bundle_from_embedded( bundle.set_use_isolating(false); let mut try_add = |key: &str| { + #[allow(clippy::collapsible_if)] if let Some(content) = get_embedded_locale(key) { if let Ok(resource) = FluentResource::try_new(content.to_string()) { bundle.add_resource_overriding(Box::leak(Box::new(resource))); diff --git a/src/uucore/src/lib/mods/os.rs b/src/uucore/src/lib/mods/os.rs index fca4578ddd6..3c1669c618e 100644 --- a/src/uucore/src/lib/mods/os.rs +++ b/src/uucore/src/lib/mods/os.rs @@ -14,6 +14,7 @@ pub fn is_wsl_1() -> bool { if is_wsl_2() { return false; } + #[allow(clippy::collapsible_if)] if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { if let Ok(s) = std::str::from_utf8(&b) { let a = s.to_ascii_lowercase(); @@ -28,6 +29,7 @@ pub fn is_wsl_1() -> bool { pub fn is_wsl_2() -> bool { #[cfg(target_os = "linux")] { + #[allow(clippy::collapsible_if)] if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { if let Ok(s) = std::str::from_utf8(&b) { let a = s.to_ascii_lowercase();