From e9d28d3a000aeded54d846a8300a88a7500e8f3f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 8 Apr 2025 23:26:59 -0400 Subject: [PATCH] chore: use `expect` instead of `allow` The `#[expect(...)]` is usually better than `#[allow(...)]` because it verifies the assumption that disabling a warning is still relevant to the code - thus eliminating the dead code when warning is no longer there. Here I tried to replace some conditional compilation to ensure linux/window separation is cleaner, and fix a few non-obvious cases --- src/bin/coreutils.rs | 1 - src/uu/cksum/src/cksum.rs | 1 - src/uu/cp/src/copydir.rs | 5 +--- src/uu/cp/src/cp.rs | 34 +++++++--------------- src/uu/csplit/src/csplit.rs | 1 - src/uu/date/src/date.rs | 1 - src/uu/dd/src/dd.rs | 46 ++++++++++++++---------------- src/uu/dd/src/parseargs.rs | 2 -- src/uu/du/src/du.rs | 2 -- src/uu/env/src/native_int_str.rs | 2 -- src/uu/expand/src/expand.rs | 1 - src/uu/fmt/src/linebreak.rs | 1 - src/uu/fmt/src/parasplit.rs | 1 - src/uu/fold/src/fold.rs | 1 - src/uu/hashsum/src/hashsum.rs | 2 -- src/uu/head/src/head.rs | 1 - src/uu/ln/src/ln.rs | 2 -- src/uu/ls/src/ls.rs | 44 ++++++++++++---------------- src/uu/mkdir/src/mkdir.rs | 9 ++++-- src/uu/mv/src/mv.rs | 1 - src/uu/nl/src/helper.rs | 1 - src/uu/numfmt/src/options.rs | 1 - src/uu/od/src/parse_formats.rs | 1 - src/uu/paste/src/paste.rs | 1 - src/uu/pr/src/pr.rs | 2 -- src/uu/ptx/src/ptx.rs | 1 - src/uu/rm/src/rm.rs | 1 - src/uu/shred/src/shred.rs | 3 +- src/uu/sort/src/chunks.rs | 3 -- src/uu/sort/src/numeric_str_cmp.rs | 1 - src/uu/sort/src/sort.rs | 2 -- src/uu/split/src/split.rs | 1 - src/uu/tac/src/tac.rs | 1 - src/uu/tail/src/follow/watch.rs | 2 -- src/uu/tail/src/paths.rs | 1 - src/uu/tail/src/platform/unix.rs | 1 - src/uu/tee/src/tee.rs | 1 - src/uu/unexpand/src/unexpand.rs | 1 - src/uu/wc/src/count_fast.rs | 2 -- src/uu/wc/src/utf8/read.rs | 1 - src/uucore/src/lib/features/sum.rs | 12 ++++---- tests/by-util/test_cp.rs | 2 +- tests/by-util/test_env.rs | 1 - tests/by-util/test_ls.rs | 6 +--- tests/by-util/test_mkdir.rs | 2 +- tests/by-util/test_rm.rs | 1 - tests/by-util/test_tail.rs | 6 ++-- tests/by-util/test_tee.rs | 1 - tests/by-util/test_tsort.rs | 1 - tests/uutests/src/lib/random.rs | 1 - tests/uutests/src/lib/util.rs | 7 +---- 51 files changed, 70 insertions(+), 156 deletions(-) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index b29e7ea2337..12cea34d1ce 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -50,7 +50,6 @@ fn name(binary_path: &Path) -> Option<&str> { binary_path.file_stem()?.to_str() } -#[allow(clippy::cognitive_complexity)] fn main() { uucore::panic::mute_sigpipe_panic(); diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index a1a9115d9a0..2bfc6badae6 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -54,7 +54,6 @@ struct Options { /// /// * `options` - CLI options for the assigning checksum algorithm /// * `files` - A iterator of OsStr which is a bunch of files that are using for calculating checksum -#[allow(clippy::cognitive_complexity)] fn cksum<'a, I>(mut options: Options, files: I) -> UResult<()> where I: Iterator, diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index 2079affa3b5..1b7898a9e3a 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -222,7 +222,6 @@ where path.as_ref().display().to_string().ends_with("/.") } -#[allow(clippy::too_many_arguments)] /// Copy a single entry during a directory traversal. fn copy_direntry( progress_bar: Option<&ProgressBar>, @@ -542,12 +541,10 @@ pub fn path_has_prefix(p1: &Path, p2: &Path) -> io::Result { /// potentially change. (See `test_dir_perm_race_with_preserve_mode_and_ownership``) /// - The `recursive` flag determines whether parent directories should be created /// if they do not already exist. -// we need to allow unused_variable since `options` might be unused in non unix systems -#[allow(unused_variables)] fn build_dir( path: &PathBuf, recursive: bool, - options: &Options, + #[cfg_attr(not(unix), expect(unused_variables))] options: &Options, copy_attributes_from: Option<&Path>, ) -> CopyResult<()> { let mut builder = fs::DirBuilder::new(); diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index eb80e6251ee..2dc987c77fb 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -136,27 +136,21 @@ impl Default for OverwriteMode { } /// Possible arguments for `--reflink`. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] pub enum ReflinkMode { Always, + #[cfg_attr( + any(target_os = "linux", target_os = "android", target_os = "macos"), + default + )] Auto, + #[cfg_attr( + not(any(target_os = "linux", target_os = "android", target_os = "macos")), + default + )] Never, } -impl Default for ReflinkMode { - #[allow(clippy::derivable_impls)] - fn default() -> Self { - #[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))] - { - ReflinkMode::Auto - } - #[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))] - { - ReflinkMode::Never - } - } -} - /// Possible arguments for `--sparse`. #[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] pub enum SparseMode { @@ -252,7 +246,6 @@ impl Ord for Preserve { /// reason. /// /// The fields are documented with the arguments that determine their value. -#[allow(dead_code)] #[derive(Debug, Clone, Eq, PartialEq)] pub struct Options { /// `--attributes-only` @@ -354,7 +347,6 @@ enum PerformedAction { /// Enum representing various debug states of the offload and reflink actions. #[derive(Debug)] -#[allow(dead_code)] // All of them are used on Linux enum OffloadReflinkDebug { Unknown, No, @@ -970,7 +962,6 @@ impl Attributes { } impl Options { - #[allow(clippy::cognitive_complexity)] fn from_matches(matches: &ArgMatches) -> CopyResult { let not_implemented_opts = vec![ #[cfg(not(any(windows, unix)))] @@ -1259,9 +1250,6 @@ fn parse_path_args( }; if options.strip_trailing_slashes { - // clippy::assigning_clones added with Rust 1.78 - // Rust version = 1.76 on OpenBSD stable/7.5 - #[cfg_attr(not(target_os = "openbsd"), allow(clippy::assigning_clones))] for source in &mut paths { *source = source.components().as_path().to_owned(); } @@ -2165,12 +2153,10 @@ fn handle_copy_mode( /// * `Ok(Permissions)` - The calculated permissions for the destination file. /// * `Err(CopyError)` - An error occurred while getting the metadata of the destination file. /// -// Allow unused variables for Windows (on options) -#[allow(unused_variables)] fn calculate_dest_permissions( dest: &Path, source_metadata: &Metadata, - options: &Options, + #[cfg_attr(not(unix), expect(unused_variables))] options: &Options, context: &str, ) -> CopyResult { if dest.exists() { diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index fc99a759f25..cc221685136 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -358,7 +358,6 @@ impl SplitWriter<'_> { /// - if no line matched, an [`CsplitError::MatchNotFound`]. /// - if there are not enough lines to accommodate the offset, an /// [`CsplitError::LineOutOfRange`]. - #[allow(clippy::cognitive_complexity)] fn do_to_match( &mut self, pattern_as_str: &str, diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index c305e2548b3..e1c83dfdeb6 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -137,7 +137,6 @@ impl From<&str> for Rfc3339Format { } #[uucore::main] -#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 0d79cdda4af..1dcc9b8fb30 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -453,20 +453,19 @@ impl Input<'_> { /// the input file is no longer needed. If not possible, then this /// function prints an error message to stderr and sets the exit /// status code to 1. - #[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))] + #[cfg(target_os = "linux")] fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) { - #[cfg(target_os = "linux")] - { - show_if_err!(self - .src + show_if_err!( + self.src .discard_cache(offset, len) - .map_err_context(|| "failed to discard cache for: 'standard input'".to_string())); - } - #[cfg(not(target_os = "linux"))] - { - // TODO Is there a way to discard filesystem cache on - // these other operating systems? - } + .map_err_context(|| "failed to discard cache for: 'standard input'".to_string()) + ); + } + + #[cfg(not(target_os = "linux"))] + fn discard_cache(&self, _offset: libc::off_t, _len: libc::off_t) { + // TODO Is there a way to discard filesystem cache on + // these other operating systems? } /// Fills a given buffer. @@ -828,19 +827,19 @@ impl<'a> Output<'a> { /// the output file is no longer needed. If not possible, then /// this function prints an error message to stderr and sets the /// exit status code to 1. - #[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))] + #[cfg(target_os = "linux")] fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) { - #[cfg(target_os = "linux")] - { - show_if_err!(self.dst.discard_cache(offset, len).map_err_context(|| { + show_if_err!( + self.dst.discard_cache(offset, len).map_err_context(|| { "failed to discard cache for: 'standard output'".to_string() - })); - } - #[cfg(not(target_os = "linux"))] - { - // TODO Is there a way to discard filesystem cache on - // these other operating systems? - } + }) + ); + } + + #[cfg(not(target_os = "linux"))] + fn discard_cache(&self, _offset: libc::off_t, _len: libc::off_t) { + // TODO Is there a way to discard filesystem cache on + // these other operating systems? } /// writes a block of data. optionally retries when first try didn't complete @@ -1207,7 +1206,6 @@ fn finalize( } #[cfg(any(target_os = "linux", target_os = "android"))] -#[allow(clippy::cognitive_complexity)] fn make_linux_oflags(oflags: &OFlags) -> Option { let mut flag = 0; diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index dd9a53fd884..ff446d6ffce 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -317,7 +317,6 @@ impl Parser { } } - #[allow(clippy::cognitive_complexity)] fn parse_input_flags(&mut self, val: &str) -> Result<(), ParseError> { let i = &mut self.iflag; for f in val.split(',') { @@ -349,7 +348,6 @@ impl Parser { Ok(()) } - #[allow(clippy::cognitive_complexity)] fn parse_output_flags(&mut self, val: &str) -> Result<(), ParseError> { let o = &mut self.oflag; for f in val.split(',') { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 0b268888136..ebdf0cd8bac 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -301,7 +301,6 @@ fn read_block_size(s: Option<&str>) -> UResult { } // this takes `my_stat` to avoid having to stat files multiple times. -#[allow(clippy::cognitive_complexity)] fn du( mut my_stat: Stat, options: &TraversalOptions, @@ -616,7 +615,6 @@ fn read_files_from(file_name: &str) -> Result, std::io::Error> { } #[uucore::main] -#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/env/src/native_int_str.rs b/src/uu/env/src/native_int_str.rs index 856948fc137..787afdd6508 100644 --- a/src/uu/env/src/native_int_str.rs +++ b/src/uu/env/src/native_int_str.rs @@ -144,7 +144,6 @@ pub fn to_native_int_representation(input: &OsStr) -> Cow<'_, NativeIntStr> { } } -#[allow(clippy::needless_pass_by_value)] // needed on windows pub fn from_native_int_representation(input: Cow<'_, NativeIntStr>) -> Cow<'_, OsStr> { #[cfg(target_os = "windows")] { @@ -160,7 +159,6 @@ pub fn from_native_int_representation(input: Cow<'_, NativeIntStr>) -> Cow<'_, O } } -#[allow(clippy::needless_pass_by_value)] // needed on windows pub fn from_native_int_representation_owned(input: NativeIntString) -> OsString { #[cfg(target_os = "windows")] { diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 4c37393b4ac..56320a19dc9 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -349,7 +349,6 @@ enum CharType { Other, } -#[allow(clippy::cognitive_complexity)] fn expand_line( buf: &mut Vec, output: &mut BufWriter, diff --git a/src/uu/fmt/src/linebreak.rs b/src/uu/fmt/src/linebreak.rs index 6c34b08088a..9b0b5aef9e6 100644 --- a/src/uu/fmt/src/linebreak.rs +++ b/src/uu/fmt/src/linebreak.rs @@ -215,7 +215,6 @@ struct LineBreak<'a> { fresh: bool, } -#[allow(clippy::cognitive_complexity)] fn find_kp_breakpoints<'a, T: Iterator>>( iter: T, args: &BreakArgs<'a>, diff --git a/src/uu/fmt/src/parasplit.rs b/src/uu/fmt/src/parasplit.rs index f9da4ad58fd..e74c0f4beb9 100644 --- a/src/uu/fmt/src/parasplit.rs +++ b/src/uu/fmt/src/parasplit.rs @@ -275,7 +275,6 @@ impl ParagraphStream<'_> { impl Iterator for ParagraphStream<'_> { type Item = Result; - #[allow(clippy::cognitive_complexity)] fn next(&mut self) -> Option> { // return a NoFormatLine in an Err; it should immediately be output let noformat = match self.lines.peek()? { diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 0aba9c57ee4..84ab0191003 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -205,7 +205,6 @@ fn fold_file_bytewise(mut file: BufReader, spaces: bool, width: usiz /// /// If `spaces` is `true`, attempt to break lines at whitespace boundaries. #[allow(unused_assignments)] -#[allow(clippy::cognitive_complexity)] fn fold_file(mut file: BufReader, spaces: bool, width: usize) -> UResult<()> { let mut line = String::new(); let mut output = String::new(); diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index cd8ca912df5..f47c73fa30b 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -60,7 +60,6 @@ struct Options { /// Returns a UResult of a tuple containing the algorithm name, the hasher instance, and /// the output length in bits or an Err if multiple hash algorithms are specified or if a /// required flag is missing. -#[allow(clippy::cognitive_complexity)] fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult { let mut alg: Option = None; @@ -514,7 +513,6 @@ fn uu_app(binary_name: &str) -> (Command, bool) { } } -#[allow(clippy::cognitive_complexity)] fn hashsum<'a, I>(mut options: Options, files: I) -> UResult<()> where I: Iterator, diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index 573926a7bb2..68f0baa043c 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -451,7 +451,6 @@ fn head_file(input: &mut File, options: &HeadOptions) -> io::Result { } } -#[allow(clippy::cognitive_complexity)] fn uu_head(options: &HeadOptions) -> UResult<()> { let mut first = true; for file in &options.files { diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 88d93331830..41035fa41b0 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -280,7 +280,6 @@ fn exec(files: &[PathBuf], settings: &Settings) -> UResult<()> { link(&files[0], &files[1], settings) } -#[allow(clippy::cognitive_complexity)] fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) -> UResult<()> { if !target_dir.is_dir() { return Err(LnError::TargetIsDirectory(target_dir.to_owned()).into()); @@ -365,7 +364,6 @@ fn relative_path<'a>(src: &'a Path, dst: &Path) -> Cow<'a, Path> { src.into() } -#[allow(clippy::cognitive_complexity)] fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> { let mut backup_path = None; let source: Cow<'_, Path> = if settings.relative { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 60c91e47828..0e2ee6fe3dc 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -372,8 +372,8 @@ pub struct Config { long: LongFormat, alloc_size: bool, file_size_block_size: u64, - #[allow(dead_code)] - block_size: u64, // is never read on Windows + #[cfg(unix)] + block_size: u64, width: u16, // Dir and vdir needs access to this field pub quoting_style: QuotingStyle, @@ -927,7 +927,6 @@ impl Config { }; let width = parse_width(options.get_one::(options::WIDTH))?; - #[allow(clippy::needless_bool)] let mut show_control = if options.get_flag(options::HIDE_CONTROL_CHARS) { false } else if options.get_flag(options::SHOW_CONTROL_CHARS) { @@ -1103,6 +1102,7 @@ impl Config { long, alloc_size: options.get_flag(options::size::ALLOCATION_SIZE), file_size_block_size, + #[cfg(unix)] block_size, width, quoting_style, @@ -2035,7 +2035,6 @@ fn show_dir_name( write!(out, ":") } -#[allow(clippy::cognitive_complexity)] pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { let mut files = Vec::::new(); let mut dirs = Vec::::new(); @@ -2474,7 +2473,6 @@ fn display_additional_leading_info( Ok(result) } -#[allow(clippy::cognitive_complexity)] fn display_items( items: &[PathData], config: &Config, @@ -2595,30 +2593,28 @@ fn display_items( Ok(()) } -#[allow(unused_variables)] +#[cfg(unix)] fn get_block_size(md: &Metadata, config: &Config) -> u64 { /* GNU ls will display sizes in terms of block size md.len() will differ from this value when the file has some holes */ - #[cfg(unix)] - { - let raw_blocks = if md.file_type().is_char_device() || md.file_type().is_block_device() { - 0u64 - } else { - md.blocks() * 512 - }; - match config.size_format { - SizeFormat::Binary | SizeFormat::Decimal => raw_blocks, - SizeFormat::Bytes => raw_blocks / config.block_size, - } - } - #[cfg(not(unix))] - { - // no way to get block size for windows, fall-back to file size - md.len() + let raw_blocks = if md.file_type().is_char_device() || md.file_type().is_block_device() { + 0u64 + } else { + md.blocks() * 512 + }; + match config.size_format { + SizeFormat::Binary | SizeFormat::Decimal => raw_blocks, + SizeFormat::Bytes => raw_blocks / config.block_size, } } +#[cfg(not(unix))] +fn get_block_size(md: &Metadata, _config: &Config) -> u64 { + // no way to get block size for windows, fall-back to file size + md.len() +} + fn display_grid( names: impl Iterator, width: u16, @@ -2724,8 +2720,6 @@ fn display_grid( /// longest_size_len: usize, /// ``` /// that decide the maximum possible character count of each field. -#[allow(clippy::write_literal)] -#[allow(clippy::cognitive_complexity)] fn display_item_long( item: &PathData, padding: &PaddingCollection, @@ -3082,7 +3076,6 @@ fn display_date(metadata: &Metadata, config: &Config) -> String { } } -#[allow(dead_code)] enum SizeOrDeviceId { Size(String), Device(String, String), @@ -3177,7 +3170,6 @@ fn classify_file(path: &PathData, out: &mut BufWriter) -> Option { /// /// Note that non-unicode sequences in symlink targets are dealt with using /// [`std::path::Path::to_string_lossy`]. -#[allow(clippy::cognitive_complexity)] fn display_item_name( path: &PathData, config: &Config, diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 14c7701dba1..b18c6365c82 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -233,10 +233,13 @@ fn chmod(_path: &Path, _mode: u32) -> UResult<()> { Ok(()) } -// Return true if the directory at `path` has been created by this call. +/// Return true if the directory at `path` has been created by this call. // `is_parent` argument is not used on windows -#[allow(unused_variables)] -fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> { +fn create_dir( + path: &Path, + #[cfg_attr(windows, expect(unused_variables))] is_parent: bool, + config: &Config, +) -> UResult<()> { let path_exists = path.exists(); if path_exists && !config.recursive { return Err(USimpleError::new( diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 072a6919752..7aef1e81dd6 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -496,7 +496,6 @@ pub fn mv(files: &[OsString], opts: &Options) -> UResult<()> { } } -#[allow(clippy::cognitive_complexity)] fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) -> UResult<()> { // remember the moved destinations for further usage let mut moved_destinations: HashSet = HashSet::with_capacity(files.len()); diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index 3e5a96b9ca2..8c8d65aa793 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -8,7 +8,6 @@ use crate::options; // parse_options loads the options into the settings, returning an array of // error messages. -#[allow(clippy::cognitive_complexity)] pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> Vec { // This vector holds error messages encountered. let mut errs: Vec = vec![]; diff --git a/src/uu/numfmt/src/options.rs b/src/uu/numfmt/src/options.rs index 72cfe226958..b714aba4867 100644 --- a/src/uu/numfmt/src/options.rs +++ b/src/uu/numfmt/src/options.rs @@ -111,7 +111,6 @@ impl FromStr for FormatOptions { // An optional zero (%010f) will zero pad the number. // An optional negative value (%-10f) will left align. // An optional precision (%.1f) determines the precision of the number. - #[allow(clippy::cognitive_complexity)] fn from_str(s: &str) -> Result { let mut iter = s.chars().peekable(); let mut options = Self::default(); diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index 86f32a25a4a..be74dfe87e0 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -100,7 +100,6 @@ fn od_argument_with_option(ch: char) -> bool { /// arguments with parameters like -w16 can only appear at the end: -fvoxw16 /// parameters of -t/--format specify 1 or more formats. /// if -- appears on the command line, parsing should stop. -#[allow(clippy::cognitive_complexity)] pub fn parse_format_flags(args: &[String]) -> Result, String> { let mut formats = Vec::new(); diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 98679b74635..c101134d039 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -78,7 +78,6 @@ pub fn uu_app() -> Command { ) } -#[allow(clippy::cognitive_complexity)] fn paste( filenames: Vec, serial: bool, diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index a8efdf99578..574afc327ae 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -479,7 +479,6 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option .map(from_parse_error_to_pr_error) } -#[allow(clippy::cognitive_complexity)] fn build_options( matches: &ArgMatches, paths: &[&str], @@ -1013,7 +1012,6 @@ fn print_page( Ok(lines_written) } -#[allow(clippy::cognitive_complexity)] fn write_columns( lines: &[FileLine], options: &OutputOptions, diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 785d8645b82..d8b0e76ad4c 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -111,7 +111,6 @@ struct WordFilter { } impl WordFilter { - #[allow(clippy::cognitive_complexity)] fn new(matches: &clap::ArgMatches, config: &Config) -> UResult { let (o, oset): (bool, HashSet) = if matches.contains_id(options::ONLY_FILE) { let words = diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 733b4dfc4a5..024efec71be 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -57,7 +57,6 @@ pub struct Options { /// If no other option sets this mode, [`InteractiveMode::PromptProtected`] /// is used pub interactive: InteractiveMode, - #[allow(dead_code)] /// `--one-file-system` pub one_fs: bool, /// `--preserve-root`/`--no-preserve-root` diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 93b9c589f50..e80aeb58031 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -382,7 +382,6 @@ fn pass_name(pass_type: &PassType) -> String { } #[allow(clippy::too_many_arguments)] -#[allow(clippy::cognitive_complexity)] fn wipe_file( path_str: &str, n_passes: usize, @@ -414,7 +413,7 @@ fn wipe_file( if force { let mut perms = metadata.permissions(); #[cfg(unix)] - #[allow(clippy::useless_conversion, clippy::unnecessary_cast)] + #[allow(clippy::unnecessary_cast)] { // NOTE: set_readonly(false) makes the file world-writable on Unix. // NOTE: S_IWUSR type is u16 on macOS, i32 on Redox. diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 8f423701ac0..a7f480a085f 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -5,9 +5,6 @@ //! Utilities for reading files as chunks. -#![allow(dead_code)] -// Ignores non-used warning for `borrow_buffer` in `Chunk` - use std::{ io::{ErrorKind, Read}, sync::mpsc::SyncSender, diff --git a/src/uu/sort/src/numeric_str_cmp.rs b/src/uu/sort/src/numeric_str_cmp.rs index d3d04a348f6..13c273cb0b0 100644 --- a/src/uu/sort/src/numeric_str_cmp.rs +++ b/src/uu/sort/src/numeric_str_cmp.rs @@ -50,7 +50,6 @@ impl NumInfo { /// an empty range (idx..idx) is returned so that idx is the char after the last zero. /// If the input is not a number (which has to be treated as zero), the returned empty range /// will be 0..0. - #[allow(clippy::cognitive_complexity)] pub fn parse(num: &str, parse_settings: &NumInfoParseSettings) -> (Self, Range) { let mut exponent = -1; let mut had_decimal_pt = false; diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 19baead3045..166e076ca58 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1014,7 +1014,6 @@ fn get_rlimit() -> UResult { } #[uucore::main] -#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut settings = GlobalSettings::default(); @@ -1679,7 +1678,6 @@ fn compare_by<'a>( // In contrast to numeric compare, GNU general numeric/FP sort *should* recognize positive signs and // scientific notation, so we strip those lines only after the end of the following numeric string. // For example, 5e10KFD would be 5e10 or 5x10^10 and +10000HFKJFK would become 10000. -#[allow(clippy::cognitive_complexity)] fn get_leading_gen(input: &str) -> Range { let trimmed = input.trim_start(); let leading_whitespace_len = input.len() - trimmed.len(); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 79aea3e1552..06a27efe38f 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -1518,7 +1518,6 @@ where Ok(()) } -#[allow(clippy::cognitive_complexity)] fn split(settings: &Settings) -> UResult<()> { let r_box = if settings.input == "-" { Box::new(stdin()) as Box diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 4496c2ce120..2800f003aed 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -220,7 +220,6 @@ fn buffer_tac(data: &[u8], before: bool, separator: &str) -> std::io::Result<()> Ok(()) } -#[allow(clippy::cognitive_complexity)] fn tac(filenames: &[&str], before: bool, regex: bool, separator: &str) -> UResult<()> { // Compile the regular expression pattern if it is provided. let maybe_pattern = if regex { diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 212ad63f969..e1441c7768a 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -305,7 +305,6 @@ impl Observer { Ok(()) } - #[allow(clippy::cognitive_complexity)] fn handle_event( &mut self, event: ¬ify::Event, @@ -472,7 +471,6 @@ EventKind::Create(CreateKind::File | CreateKind::Folder | CreateKind::Any) => { } } -#[allow(clippy::cognitive_complexity)] pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { if observer.files.no_files_remaining(settings) && !observer.files.only_stdin_remaining() { return Err(USimpleError::new(1, text::NO_FILES_REMAINING.to_string())); diff --git a/src/uu/tail/src/paths.rs b/src/uu/tail/src/paths.rs index 158535ea2c1..03c04383260 100644 --- a/src/uu/tail/src/paths.rs +++ b/src/uu/tail/src/paths.rs @@ -136,7 +136,6 @@ impl HeaderPrinter { } } pub trait FileExtTail { - #[allow(clippy::wrong_self_convention)] fn is_seekable(&mut self, current_offset: u64) -> bool; } diff --git a/src/uu/tail/src/platform/unix.rs b/src/uu/tail/src/platform/unix.rs index 08e75bedf4f..c444e6772c5 100644 --- a/src/uu/tail/src/platform/unix.rs +++ b/src/uu/tail/src/platform/unix.rs @@ -20,7 +20,6 @@ impl ProcessChecker { } // Borrowing mutably to be aligned with Windows implementation - #[allow(clippy::wrong_self_convention)] pub fn is_dead(&mut self) -> bool { unsafe { libc::kill(self.pid, 0) != 0 && get_errno() != libc::EPERM } } diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 7c4131b737e..178e3004ba1 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -31,7 +31,6 @@ mod options { pub const OUTPUT_ERROR: &str = "output-error"; } -#[allow(dead_code)] struct Options { append: bool, ignore_interrupts: bool, diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index fb17b971d57..8914afbcd0d 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -308,7 +308,6 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi (ctype, cwidth, nbytes) } -#[allow(clippy::cognitive_complexity)] fn unexpand_line( buf: &mut Vec, output: &mut BufWriter, diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index b79e6b0e378..8bdad3aeab7 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -64,8 +64,6 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result { Ok(0) => break, Ok(res) => { byte_count += res; - // Silent the warning as we want to the error message - #[allow(clippy::question_mark)] if splice_exact(&pipe_rd, &null_file, res).is_err() { return Err(byte_count); } diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index af10cbb5366..774a3dbc92f 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -44,7 +44,6 @@ impl BufReadDecoder { /// This is similar to `Iterator::next`, /// except that decoded chunks borrow the decoder (~iterator) /// so they need to be handled or copied before the next chunk can start decoding. - #[allow(clippy::cognitive_complexity)] pub fn next_strict(&mut self) -> Option> { enum BytesSource { BufRead(usize), diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index be450cb2f61..341c5442701 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -408,29 +408,27 @@ pub struct DigestWriter<'a> { binary: bool, /// Whether the previous - #[allow(dead_code)] + #[cfg(windows)] was_last_character_carriage_return: bool, - // TODO These are dead code only on non-Windows operating systems. - // It might be better to use a `#[cfg(windows)]` guard here. } impl<'a> DigestWriter<'a> { pub fn new(digest: &'a mut Box, binary: bool) -> Self { - let was_last_character_carriage_return = false; DigestWriter { digest, binary, - was_last_character_carriage_return, + #[cfg(windows)] + was_last_character_carriage_return: false, } } pub fn finalize(&mut self) -> bool { + #[cfg(windows)] if self.was_last_character_carriage_return { self.digest.hash_update(b"\r"); true - } else { - false } + false } } diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 72eddfd9f9a..5ca60d5fa78 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -5802,7 +5802,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() { sleep(Duration::from_millis(100)); } let mode = at.metadata(&format!("{DEST_DIR}/{SRC_DIR}")).mode(); - #[allow(clippy::unnecessary_cast, clippy::cast_lossless)] + #[allow(clippy::unnecessary_cast)] let mask = if attr == "mode" { libc::S_IWGRP | libc::S_IWOTH } else { diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 6911958bdd1..38c8c3bf8aa 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -545,7 +545,6 @@ fn test_gnu_e20() { } #[test] -#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign fn test_env_parsing_errors() { let ts = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 4123809fcb2..644ed550906 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -4,11 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff dired subdired tmpfs mdir COLORTERM mexe bcdef mfoo // spell-checker:ignore (words) fakeroot setcap -#![allow( - clippy::similar_names, - clippy::too_many_lines, - clippy::cast_possible_truncation -)] +#![allow(clippy::similar_names, clippy::too_many_lines)] #[cfg(all(unix, feature = "chmod"))] use nix::unistd::{close, dup}; diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 3eaec9774da..fa649df11ba 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -5,7 +5,7 @@ // spell-checker:ignore bindgen getfattr testtest -#![allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] +#![allow(clippy::cast_sign_loss)] #[cfg(not(windows))] use libc::mode_t; diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index e61f4196b25..ace94cf5214 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -2,7 +2,6 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![allow(clippy::stable_sort_primitive)] use std::process::Stdio; diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index cebc8fc3955..11c5d25cf9a 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -55,11 +55,11 @@ use uutests::util_name; const FOOBAR_TXT: &str = "foobar.txt"; const FOOBAR_2_TXT: &str = "foobar2.txt"; const FOOBAR_WITH_NULL_TXT: &str = "foobar_with_null.txt"; -#[allow(dead_code)] +#[cfg(target_os = "linux")] const FOLLOW_NAME_TXT: &str = "follow_name.txt"; -#[allow(dead_code)] +#[cfg(target_os = "linux")] const FOLLOW_NAME_SHORT_EXP: &str = "follow_name_short.expected"; -#[allow(dead_code)] +#[cfg(target_os = "linux")] const FOLLOW_NAME_EXP: &str = "follow_name.expected"; const DEFAULT_SLEEP_INTERVAL_MILLIS: u64 = 1000; diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index e20a22326f5..24354da5ad8 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -2,7 +2,6 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![allow(clippy::borrow_as_ptr)] use uutests::util::TestScenario; use uutests::{at_and_ucmd, new_ucmd, util_name}; diff --git a/tests/by-util/test_tsort.rs b/tests/by-util/test_tsort.rs index c957a59a1cc..d8e3254924d 100644 --- a/tests/by-util/test_tsort.rs +++ b/tests/by-util/test_tsort.rs @@ -2,7 +2,6 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![allow(clippy::cast_possible_wrap)] use uutests::at_and_ucmd; use uutests::new_ucmd; diff --git a/tests/uutests/src/lib/random.rs b/tests/uutests/src/lib/random.rs index 7a13f1e1de0..20e1e349e4b 100644 --- a/tests/uutests/src/lib/random.rs +++ b/tests/uutests/src/lib/random.rs @@ -2,7 +2,6 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![allow(clippy::naive_bytecount)] use rand::distr::{Distribution, Uniform}; use rand::{Rng, rng}; diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 964b24e86b5..ea4e0ccc83e 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -6,11 +6,7 @@ //spell-checker: ignore (linux) winsize xpixel ypixel setrlimit FSIZE SIGBUS SIGSEGV sigbus tmpfs #![allow(dead_code)] -#![allow( - clippy::too_many_lines, - clippy::should_panic_without_expect, - clippy::missing_errors_doc -)] +#![allow(clippy::too_many_lines, clippy::missing_errors_doc)] #[cfg(unix)] use libc::mode_t; @@ -2243,7 +2239,6 @@ impl UChild { } /// Return true if the child process is exited and false otherwise. - #[allow(clippy::wrong_self_convention)] pub fn is_not_alive(&mut self) -> bool { !self.is_alive() }