Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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::"))' \
Expand Down
2 changes: 2 additions & 0 deletions src/uu/date/src/format_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -443,6 +444,7 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
// GNU behavior: + only adds sign if:
// 1. An explicit width is provided, OR
// 2. The value exceeds the default width for that specifier (e.g., year > 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);
Expand Down
5 changes: 4 additions & 1 deletion src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Options {
let exclude: Option<Vec<_>> = matches
.get_many::<OsString>(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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -311,6 +313,7 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
// 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
Expand Down
6 changes: 5 additions & 1 deletion src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) =
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/uu/env/src/variable_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ fn evaluate_match_expression(left_bytes: Vec<u8>, right_bytes: Vec<u8>) -> ExprR
let left_encoded = onig::EncodedBytes::ascii(&left_bytes);
let pos = regex_search(&regex, 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];
Expand Down
2 changes: 2 additions & 0 deletions src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -404,6 +406,7 @@ impl<'a> StyleManager<'a> {

#[cfg(unix)]
fn indicator_for_file(&self, path: &PathData) -> Option<Indicator> {
#[allow(clippy::collapsible_if)]
if self.needs_file_metadata() {
if let Some(metadata) = path.metadata() {
let mode = metadata.mode();
Expand Down Expand Up @@ -442,6 +445,7 @@ impl<'a> StyleManager<'a> {

#[cfg(unix)]
fn indicator_for_directory(&self, path: &PathData) -> Option<Indicator> {
#[allow(clippy::collapsible_if)]
if self.needs_dir_metadata() {
if let Some(metadata) = path.metadata() {
let mode = metadata.mode();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/uu/ls/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/uu/ls/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ impl<'a> PathData<'a> {
let security_context: OnceCell<Box<str>> = OnceCell::new();

let de: RefCell<Option<DirEntry>> = 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()));
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/uu/more/src/more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/uu/mv/src/hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.get_one::<OsString>(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());
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn format_and_write<W: std::io::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() {
Expand Down Expand Up @@ -186,6 +187,7 @@ fn parse_unit_size(s: &str) -> Result<usize> {

// 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() {
Expand Down
4 changes: 3 additions & 1 deletion src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ fn recreate_arguments(args: &[String]) -> Vec<String> {
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) {
Expand All @@ -452,6 +453,7 @@ fn recreate_arguments(args: &[String]) -> Vec<String> {
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();
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fn get_config(matches: &mut clap::ArgMatches) -> UResult<Config> {
// 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(&regex) {
if re.is_match("") {
return Err(USimpleError::new(1, translate!("ptx-error-empty-regexp")));
Expand Down
1 change: 1 addition & 0 deletions src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/uu/shred/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/uu/sort/src/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ fn read_to_buffer<T: Read>(
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 {
Expand Down
Loading
Loading