diff --git a/Cargo.toml b/Cargo.toml index 823f81115b0..693cc365082 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -669,7 +669,6 @@ cast_sign_loss = "allow" # 70 struct_excessive_bools = "allow" # 68 cast_precision_loss = "allow" # 52 cast_lossless = "allow" # 35 -unnecessary_wraps = "allow" # 33 ignored_unit_patterns = "allow" # 21 similar_names = "allow" # 20 large_stack_arrays = "allow" # 20 diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 17931d73112..04a3c1c0110 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -2328,9 +2328,9 @@ fn calculate_dest_permissions( source_metadata: &Metadata, options: &Options, context: &str, -) -> CopyResult { +) -> Permissions { if let Some(metadata) = dest_metadata { - Ok(metadata.permissions()) + metadata.permissions() } else { #[cfg(unix)] { @@ -2341,12 +2341,11 @@ fn calculate_dest_permissions( use uucore::mode::get_umask; let mode = mode & !get_umask(); permissions.set_mode(mode); - Ok(permissions) + permissions } #[cfg(not(unix))] { - let permissions = source_metadata.permissions(); - Ok(permissions) + source_metadata.permissions() } } } @@ -2524,7 +2523,7 @@ fn copy_file( &source_metadata, options, context, - )?; + ); #[cfg(unix)] let source_is_fifo = source_metadata.file_type().is_fifo(); diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 7c63af29072..d4812d4cf38 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1092,7 +1092,7 @@ impl BlockWriter<'_> { /// depending on the command line arguments, this function /// informs the OS to flush/discard the caches for input and/or output file. -fn flush_caches_full_length(i: &Input, o: &Output) -> io::Result<()> { +fn flush_caches_full_length(i: &Input, o: &Output) { // Using len=0 in posix_fadvise means "to end of file" if i.settings.iflags.nocache { i.discard_cache(0, 0); @@ -1100,8 +1100,6 @@ fn flush_caches_full_length(i: &Input, o: &Output) -> io::Result<()> { if i.settings.oflags.nocache { o.discard_cache(0, 0); } - - Ok(()) } /// Copy the given input data to this output, consuming both. @@ -1163,7 +1161,7 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> { // requests that we inform the system that we no longer // need the contents of the input file in a system cache. // - flush_caches_full_length(&i, &o)?; + flush_caches_full_length(&i, &o); return finalize( BlockWriter::Unbuffered(o), rstat, diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 83092ccaf38..b0a52846eed 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -233,6 +233,10 @@ fn get_blocks(path: &Path, _metadata: &Metadata) -> u64 { } #[cfg(not(windows))] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn get_file_info(_path: &Path, metadata: &Metadata) -> Option { Some(FileInfo { file_id: metadata.ino() as u128, diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index a2a255992b8..a5c453c1745 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -367,7 +367,7 @@ fn build_regex(pattern_bytes: Vec) -> ExprResult<(Regex, String)> { } /// Find matches in the input using the compiled regex -fn find_match(regex: Regex, re_string: String, left_bytes: Vec) -> ExprResult { +fn find_match(regex: Regex, re_string: String, left_bytes: Vec) -> String { use onig::EncodedBytes; use uucore::i18n::{UEncoding, get_locale_encoding}; @@ -375,7 +375,7 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec) -> ExprResul // Match against the input using the appropriate encoding let mut region = onig::Region::new(); - let result = match encoding { + match encoding { UEncoding::Utf8 => { // In UTF-8 locale, check if input is valid UTF-8 if let Ok(left_str) = std::str::from_utf8(&left_bytes) { @@ -483,7 +483,7 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec) -> ExprResul if let Some((start, end)) = region.pos(1) { let capture_bytes = &left_bytes[start..end]; // Return raw bytes as String for consistency with other cases - return Ok(String::from_utf8_lossy(capture_bytes).into_owned()); + return String::from_utf8_lossy(capture_bytes).into_owned(); } String::new() } else { @@ -500,9 +500,7 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec) -> ExprResul } } } - }; - - Ok(result) + } } /// Evaluate a match expression with locale-aware regex matching @@ -533,8 +531,7 @@ fn evaluate_match_expression(left_bytes: Vec, right_bytes: Vec) -> ExprR } } - let result = find_match(regex, re_string, left_bytes)?; - Ok(result.into()) + Ok(find_match(regex, re_string, left_bytes).into()) } /// Precedence for infix binary operators diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 8fa38b67cc8..d4e6b673898 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -9,6 +9,8 @@ use uucore::error::{UResult, set_exit_code}; use uucore::translate; #[uucore::main] +// TODO: modify proc macro to allow no-result uumain +#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")] pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Mirror GNU options, always return `1`. In particular even the 'successful' cases of no-op, // and the interrupted display of help and version should return `1`. Also, we return Ok in all diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index 54025a89d07..daf87c54d87 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -34,7 +34,11 @@ pub fn parse_obsolete(src: &str) -> Option, ParseError>> { } } if has_num { - process_num_block(&src[num_start..num_end], last_char, &mut chars) + Some(process_num_block( + &src[num_start..num_end], + last_char, + &mut chars, + )) } else { None } @@ -48,11 +52,11 @@ fn process_num_block( src: &str, last_char: char, chars: &mut std::str::CharIndices, -) -> Option, ParseError>> { +) -> Result, ParseError> { let num = match src.parse::() { Ok(n) => n, Err(e) if *e.kind() == std::num::IntErrorKind::PosOverflow => usize::MAX, - _ => return Some(Err(ParseError)), + _ => return Err(ParseError), }; let mut quiet = false; let mut verbose = false; @@ -78,7 +82,7 @@ fn process_num_block( 'k' => multiplier = Some(1024), 'm' => multiplier = Some(1024 * 1024), '\0' => {} - _ => return Some(Err(ParseError)), + _ => return Err(ParseError), } if let Some((_, next)) = chars.next() { c = next; @@ -104,7 +108,7 @@ fn process_num_block( options.push(OsString::from("-n")); options.push(OsString::from(format!("{num}"))); } - Some(Ok(options)) + Ok(options) } /// Parses an -c or -n argument, @@ -134,6 +138,7 @@ mod tests { } } + #[expect(clippy::unnecessary_wraps, reason = "test helper")] fn obsolete_result(src: &[&str]) -> Option, ParseError>> { Some(Ok(src.iter().map(|&s| s.to_string()).collect())) } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index d952abafd94..489fa301b97 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -262,6 +262,7 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option) = ("%b %e %H:%M", Some("%b %e %Y")); // Convert time_styles references to owned String/option. + #[expect(clippy::unnecessary_wraps, reason = "internal result helper")] fn ok((recent, older): (&str, Option<&str>)) -> Result<(String, Option), LsError> { Ok((recent.to_string(), older.map(String::from))) } @@ -2634,7 +2635,7 @@ fn display_additional_leading_info( item: &PathData, padding: &PaddingCollection, config: &Config, -) -> UResult { +) -> String { let mut result = String::new(); #[cfg(unix)] { @@ -2661,7 +2662,8 @@ fn display_additional_leading_info( write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap(); } } - Ok(result) + + result } #[allow(clippy::cognitive_complexity)] @@ -2690,7 +2692,7 @@ fn display_items( let should_display_leading_info = config.alloc_size; if should_display_leading_info { - let more_info = display_additional_leading_info(item, &padding_collection, config)?; + let more_info = display_additional_leading_info(item, &padding_collection, config); write!(state.out, "{more_info}")?; } @@ -2725,7 +2727,7 @@ fn display_items( for i in items { let more_info = if should_display_leading_info { - Some(display_additional_leading_info(i, &padding, config)?) + Some(display_additional_leading_info(i, &padding, config)) } else { None }; diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 7ea6553520f..3d0a9bc33c9 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -51,6 +51,10 @@ pub struct Config<'a> { } #[cfg(windows)] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn get_mode(_matches: &ArgMatches) -> Result { Ok(DEFAULT_PERM) } @@ -92,7 +96,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { set_security_context: set_security_context || context.is_some(), context, }; - exec(dirs, &config) + exec(dirs, &config); + Ok(()) } Err(f) => Err(USimpleError::new(1, f)), } @@ -154,14 +159,13 @@ pub fn uu_app() -> Command { /** * Create the list of new directories */ -fn exec(dirs: ValuesRef, config: &Config) -> UResult<()> { +fn exec(dirs: ValuesRef, config: &Config) { for dir in dirs { let path_buf = PathBuf::from(dir); let path = path_buf.as_path(); show_if_err!(mkdir(path, config)); } - Ok(()) } /// Create directory at a given `path`. diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index f84f00a0053..3efd0690188 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -399,7 +399,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Create the temporary file or directory, or simulate creating it. let res = if dry_run { - dry_exec(&tmpdir, &prefix, rand, &suffix) + Ok(dry_exec(&tmpdir, &prefix, rand, &suffix)) } else { exec(&tmpdir, &prefix, rand, &suffix, make_dir) }; @@ -483,7 +483,7 @@ pub fn uu_app() -> Command { ) } -fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult { +fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> PathBuf { let len = prefix.len() + suffix.len() + rand; let mut buf = Vec::with_capacity(len); buf.extend(prefix.as_bytes()); @@ -503,8 +503,7 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult

UResult { // Create the temporary file or directory, or simulate creating it. if options.dry_run { - dry_exec(&tmpdir, &prefix, rand, &suffix) + Ok(dry_exec(&tmpdir, &prefix, rand, &suffix)) } else { exec(&tmpdir, &prefix, rand, &suffix, options.directory) } diff --git a/src/uu/mv/src/hardlink.rs b/src/uu/mv/src/hardlink.rs index d5758031c4e..8c4ea7b3340 100644 --- a/src/uu/mv/src/hardlink.rs +++ b/src/uu/mv/src/hardlink.rs @@ -40,9 +40,6 @@ pub struct HardlinkOptions { pub verbose: bool, } -/// Result type for hardlink operations -pub type HardlinkResult = Result; - /// Errors that can occur during hardlink operations #[derive(Debug)] pub enum HardlinkError { @@ -122,7 +119,7 @@ impl HardlinkTracker { dest: &Path, scanner: &HardlinkGroupScanner, options: &HardlinkOptions, - ) -> HardlinkResult> { + ) -> Option { use std::os::unix::fs::MetadataExt; let metadata = match source.metadata() { @@ -132,7 +129,7 @@ impl HardlinkTracker { if options.verbose { eprintln!("warning: cannot get metadata for {}: {}", source.quote(), e); } - return Ok(None); + return None; } }; @@ -154,14 +151,14 @@ impl HardlinkTracker { existing_path.quote() ); } - return Ok(Some(existing_path.clone())); + return Some(existing_path.clone()); } } // This is the first time we see this file, record its destination self.inode_map.insert(key, dest.to_path_buf()); - Ok(None) + None } } @@ -171,13 +168,9 @@ impl HardlinkGroupScanner { } /// Scan files and group them by hardlinks, including recursive directory scanning - pub fn scan_files( - &mut self, - files: &[PathBuf], - options: &HardlinkOptions, - ) -> HardlinkResult<()> { + pub fn scan_files(&mut self, files: &[PathBuf], options: &HardlinkOptions) { if self.scanned { - return Ok(()); + return; } // Store the source files for destination mapping @@ -206,8 +199,6 @@ impl HardlinkGroupScanner { ); } } - - Ok(()) } /// Scan a single path (file or directory) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index f96a6f65ec6..f7103f78b07 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -587,19 +587,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) }; // Pre-scan files if needed - if let Err(e) = scanner.scan_files(files, &hardlink_options) { - if hardlink_options.verbose { - eprintln!("mv: warning: failed to scan files for hardlinks: {e}"); - eprintln!("mv: continuing without hardlink preservation"); - } else { - // Show warning in non-verbose mode for serious errors - eprintln!( - "mv: warning: hardlink scanning failed, continuing without hardlink preservation" - ); - } - // Continue without hardlink tracking on scan failure - // This provides graceful degradation rather than failing completely - } + scanner.scan_files(files, &hardlink_options); (tracker, scanner) }; @@ -898,6 +886,10 @@ fn rename_fifo_fallback(from: &Path, to: &Path) -> io::Result<()> { } #[cfg(not(unix))] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn rename_fifo_fallback(_from: &Path, _to: &Path) -> io::Result<()> { Ok(()) } @@ -1140,7 +1132,7 @@ fn copy_file_with_hardlinks_helper( let hardlink_options = HardlinkOptions::default(); // Create a hardlink instead of copying if let Some(existing_target) = - hardlink_tracker.check_hardlink(from, to, hardlink_scanner, &hardlink_options)? + hardlink_tracker.check_hardlink(from, to, hardlink_scanner, &hardlink_options) { fs::hard_link(&existing_target, to)?; return Ok(()); @@ -1186,7 +1178,7 @@ fn rename_file_fallback( use crate::hardlink::HardlinkOptions; let hardlink_options = HardlinkOptions::default(); if let Some(existing_target) = - tracker.check_hardlink(from, to, scanner, &hardlink_options)? + tracker.check_hardlink(from, to, scanner, &hardlink_options) { // Create a hardlink to the first moved file instead of copying fs::hard_link(&existing_target, to)?; diff --git a/src/uu/pinky/src/platform/unix.rs b/src/uu/pinky/src/platform/unix.rs index 8f69ae72939..486f8b3ca09 100644 --- a/src/uu/pinky/src/platform/unix.rs +++ b/src/uu/pinky/src/platform/unix.rs @@ -10,7 +10,7 @@ use crate::options; use crate::uu_app; use uucore::entries::{Locate, Passwd}; -use uucore::error::{FromIo, UResult}; +use uucore::error::UResult; use uucore::libc::S_IWGRP; use uucore::translate; use uucore::utmpx::{self, Utmpx, UtmpxRecord, time}; @@ -96,14 +96,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; if do_short_format { - match pk.short_pinky() { - Ok(_) => Ok(()), - Err(e) => Err(e.map_err_context(String::new)), - } + pk.short_pinky(); } else { pk.long_pinky(); - Ok(()) } + Ok(()) } struct Pinky { @@ -170,7 +167,7 @@ fn gecos_to_fullname(pw: &Passwd) -> Option { } impl Pinky { - fn print_entry(&self, ut: &UtmpxRecord) -> std::io::Result<()> { + fn print_entry(&self, ut: &UtmpxRecord) { let mut pts_path = PathBuf::from("/dev"); pts_path.push(ut.tty_device().as_str()); @@ -230,7 +227,6 @@ impl Pinky { } println!(); - Ok(()) } fn print_heading(&self) { @@ -249,7 +245,7 @@ impl Pinky { println!(); } - fn short_pinky(&self) -> std::io::Result<()> { + fn short_pinky(&self) { if self.include_heading { self.print_heading(); } @@ -257,10 +253,9 @@ impl Pinky { if ut.is_user_process() && (self.names.is_empty() || self.names.iter().any(|n| n.as_str() == ut.user())) { - self.print_entry(&ut)?; + self.print_entry(&ut); } } - Ok(()) } fn long_pinky(&self) { diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index e7a345b4c52..0b05a3a35f7 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -549,17 +549,17 @@ fn create_test_compatible_sequence( } } - create_standard_pass_sequence(num_passes) + Ok(create_standard_pass_sequence(num_passes)) } /// Create standard pass sequence with patterns and random passes -fn create_standard_pass_sequence(num_passes: usize) -> UResult> { +fn create_standard_pass_sequence(num_passes: usize) -> Vec { if num_passes == 0 { - return Ok(Vec::new()); + return Vec::new(); } if num_passes <= 3 { - return Ok(vec![PassType::Random; num_passes]); + return vec![PassType::Random; num_passes]; } let mut sequence = Vec::new(); @@ -596,7 +596,7 @@ fn create_standard_pass_sequence(num_passes: usize) -> UResult> { // Final pass is always random sequence.push(PassType::Random); - Ok(sequence) + sequence } /// Create compatible pass sequence using the standard algorithm @@ -609,7 +609,7 @@ fn create_compatible_sequence( create_test_compatible_sequence(num_passes, random_source) } else { // For system random, use standard algorithm - create_standard_pass_sequence(num_passes) + Ok(create_standard_pass_sequence(num_passes)) } } @@ -679,7 +679,7 @@ fn wipe_file( if random_source.is_some() { pass_sequence = create_compatible_sequence(n_passes, random_source)?; } else { - pass_sequence = create_standard_pass_sequence(n_passes)?; + pass_sequence = create_standard_pass_sequence(n_passes); } } @@ -773,7 +773,7 @@ fn do_pass( /// Repeatedly renames the file with strings of decreasing length (most likely all 0s) /// Return the path of the file after its last renaming or None in case of an error -fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Option { +fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> PathBuf { let file_name_len = orig_path.file_name().unwrap().len(); let mut last_path = PathBuf::from(orig_path); @@ -821,7 +821,7 @@ fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Op } } - Some(last_path) + last_path } fn do_remove( @@ -838,14 +838,12 @@ fn do_remove( } let remove_path = if remove_method == RemoveMethod::Unlink { - Some(path.with_file_name(orig_filename)) + path.with_file_name(orig_filename) } else { wipe_name(path, verbose, remove_method) }; - if let Some(rp) = remove_path { - fs::remove_file(rp)?; - } + fs::remove_file(remove_path)?; if verbose { show_error!( diff --git a/src/uu/split/src/number.rs b/src/uu/split/src/number.rs index b81c1e989fa..fd0256a1551 100644 --- a/src/uu/split/src/number.rs +++ b/src/uu/split/src/number.rs @@ -144,7 +144,10 @@ impl Number { pub fn increment(&mut self) -> Result<(), Overflow> { match self { Self::FixedWidth(number) => number.increment(), - Self::DynamicWidth(number) => number.increment(), + Self::DynamicWidth(number) => { + number.increment(); + Ok(()) + } } } } @@ -303,9 +306,8 @@ impl DynamicWidthNumber { } } - fn increment(&mut self) -> Result<(), Overflow> { + fn increment(&mut self) { self.current += 1; - Ok(()) } fn digits(&self) -> Vec { diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index b18e73d5d97..bffe1f7b145 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -90,11 +90,19 @@ enum ProgramOptionsError { target_os = "openbsd", target_os = "dragonfly" ))] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn preload_strings() -> UResult<(&'static str, &'static str)> { Ok(("LD_PRELOAD", "so")) } #[cfg(target_vendor = "apple")] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn preload_strings() -> UResult<(&'static str, &'static str)> { Ok(("DYLD_LIBRARY_PATH", "dylib")) } diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 7b668c8d354..af54db3e9fe 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -428,7 +428,7 @@ fn stty(opts: &Options) -> UResult<()> { print_special_setting(setting, opts.file.as_raw_fd())?; } ArgOptions::SavedState(state) => { - apply_saved_state(&mut termios, state)?; + apply_saved_state(&mut termios, state); } } } @@ -613,6 +613,10 @@ impl WrappedPrinter { } } +#[allow( + clippy::unnecessary_wraps, + reason = "needed for some platform-specific code" +)] fn print_terminal_size( termios: &Termios, opts: &Options, @@ -986,10 +990,10 @@ fn apply_char_mapping(termios: &mut Termios, mapping: &(S, u8)) { /// /// If state has fewer than 4 elements, no changes are applied. This is a defensive /// check that should never trigger since `parse_saved_state` rejects such states. -fn apply_saved_state(termios: &mut Termios, state: &[u32]) -> nix::Result<()> { +fn apply_saved_state(termios: &mut Termios, state: &[u32]) { // Require at least 4 elements for the flags (defensive check) if state.len() < 4 { - return Ok(()); // No-op for invalid state (already validated by parser) + return; // No-op for invalid state (already validated by parser) } // Apply the four flag groups, done (as _) for MacOS size compatibility @@ -1004,8 +1008,6 @@ fn apply_saved_state(termios: &mut Termios, state: &[u32]) -> nix::Result<()> { termios.control_chars[i] = cc_val as u8; } } - - Ok(()) } fn apply_special_setting( diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index de79a957bf8..902abb9cc59 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -41,6 +41,10 @@ mod platform { use uucore::error::UResult; + #[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" + )] pub fn do_sync() -> UResult<()> { sync(); Ok(()) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 3c1bab7a81e..dd10f5c9173 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -760,6 +760,7 @@ fn parse_timestamp(s: &str) -> UResult { /// /// On Windows, uses `GetFinalPathNameByHandleW` to attempt to get the path /// from the stdout handle. +#[cfg_attr(not(windows), expect(clippy::unnecessary_wraps))] fn pathbuf_from_stdout() -> Result { #[cfg(all(unix, not(target_os = "android")))] { diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index ad3e01c9e70..fe8c762e0ec 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -9,6 +9,8 @@ use uucore::error::{UResult, set_exit_code}; use uucore::translate; #[uucore::main] +// TODO: modify proc macro to allow no-result uumain +#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args: Vec = args.collect(); if args.len() != 2 { diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 92527221b91..22c84a1a212 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -52,6 +52,7 @@ pub fn uu_app() -> Command { } /// Copies words from `i` into `buf`, separated by spaces. +#[allow(clippy::unnecessary_wraps, reason = "needed on some platforms")] fn args_into_buffer<'a>( buf: &mut Vec, i: Option>, diff --git a/src/uucore/src/lib/features/checksum/compute.rs b/src/uucore/src/lib/features/checksum/compute.rs index 2b45503540f..4a51f81d790 100644 --- a/src/uucore/src/lib/features/checksum/compute.rs +++ b/src/uucore/src/lib/features/checksum/compute.rs @@ -156,7 +156,7 @@ fn print_legacy_checksum( filename: &OsStr, sum: &DigestOutput, size: usize, -) -> UResult<()> { +) { debug_assert!(options.algo_kind.is_legacy()); debug_assert!(matches!(sum, DigestOutput::U16(_) | DigestOutput::Crc(_))); @@ -191,15 +191,9 @@ fn print_legacy_checksum( print!(" "); let _dropped_result = io::stdout().write_all(escaped_filename.as_bytes()); } - - Ok(()) } -fn print_tagged_checksum( - options: &ChecksumComputeOptions, - filename: &OsStr, - sum: &String, -) -> UResult<()> { +fn print_tagged_checksum(options: &ChecksumComputeOptions, filename: &OsStr, sum: &String) { let (escaped_filename, prefix) = if options.line_ending == LineEnding::Nul { (filename.to_string_lossy().to_string(), "") } else { @@ -214,8 +208,6 @@ fn print_tagged_checksum( // Print closing parenthesis and sum print!(") = {sum}"); - - Ok(()) } fn print_untagged_checksum( @@ -223,7 +215,7 @@ fn print_untagged_checksum( filename: &OsStr, sum: &String, reading_mode: ReadingMode, -) -> UResult<()> { +) { let (escaped_filename, prefix) = if options.line_ending == LineEnding::Nul { (filename.to_string_lossy().to_string(), "") } else { @@ -235,8 +227,6 @@ fn print_untagged_checksum( // Print filename let _dropped_result = io::stdout().write_all(escaped_filename.as_bytes()); - - Ok(()) } /// Calculate checksum @@ -309,14 +299,14 @@ where return Ok(()); } OutputFormat::Legacy => { - print_legacy_checksum(&options, filename, &digest_output, sz)?; + print_legacy_checksum(&options, filename, &digest_output, sz); } OutputFormat::Tagged(digest_format) => { print_tagged_checksum( &options, filename, &encode_sum(digest_output, digest_format)?, - )?; + ); } OutputFormat::Untagged(digest_format, reading_mode) => { print_untagged_checksum( @@ -324,7 +314,7 @@ where filename, &encode_sum(digest_output, digest_format)?, reading_mode, - )?; + ); } } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 3c3ac52ad36..173fe918fd2 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -143,6 +143,10 @@ impl From<&str> for MetadataTimeField { } #[cfg(unix)] +#[expect( + clippy::unnecessary_wraps, + reason = "fn sig must match on all platforms" +)] fn metadata_get_change_time(md: &Metadata) -> Option { let mut st = UNIX_EPOCH; let (secs, nsecs) = (md.ctime(), md.ctime_nsec()); diff --git a/src/uucore/src/lib/features/systemd_logind.rs b/src/uucore/src/lib/features/systemd_logind.rs index 67ede638563..9efd46a3945 100644 --- a/src/uucore/src/lib/features/systemd_logind.rs +++ b/src/uucore/src/lib/features/systemd_logind.rs @@ -580,10 +580,10 @@ impl SystemdUtmpxCompat { } /// Canonical host name - pub fn canon_host(&self) -> std::io::Result { + pub fn canon_host(&self) -> String { // Simple implementation - just return the host as-is // Could be enhanced with DNS lookup like the original - Ok(self.record.host.clone()) + self.record.host.clone() } } diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 3c3664389df..e46136b4ae3 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -521,7 +521,7 @@ impl UtmpxRecord { match self { Self::Traditional(utmpx) => utmpx.canon_host(), #[cfg(feature = "feat_systemd_logind")] - Self::Systemd(systemd) => systemd.canon_host(), + Self::Systemd(systemd) => Ok(systemd.canon_host()), } } } diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 10a49a060ec..5b89829288e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -434,6 +434,7 @@ impl error::UError for NonUtf8OsStrError {} /// /// This always succeeds on unix platforms, /// and fails on other platforms if the string can't be coerced to UTF-8. +#[cfg_attr(unix, expect(clippy::unnecessary_wraps))] pub fn os_str_as_bytes(os_string: &OsStr) -> Result<&[u8], NonUtf8OsStrError> { #[cfg(unix)] return Ok(os_string.as_bytes()); @@ -467,6 +468,7 @@ pub fn os_str_as_bytes_lossy(os_string: &OsStr) -> Cow<'_, [u8]> { /// /// This always succeeds on unix platforms, /// and fails on other platforms if the bytes can't be parsed as UTF-8. +#[cfg_attr(unix, expect(clippy::unnecessary_wraps))] pub fn os_str_from_bytes(bytes: &[u8]) -> error::UResult> { #[cfg(unix)] return Ok(Cow::Borrowed(OsStr::from_bytes(bytes))); @@ -481,6 +483,7 @@ pub fn os_str_from_bytes(bytes: &[u8]) -> error::UResult> { /// /// This always succeeds on unix platforms, /// and fails on other platforms if the bytes can't be parsed as UTF-8. +#[cfg_attr(unix, expect(clippy::unnecessary_wraps))] pub fn os_string_from_vec(vec: Vec) -> error::UResult { #[cfg(unix)] return Ok(OsString::from_vec(vec)); @@ -495,6 +498,7 @@ pub fn os_string_from_vec(vec: Vec) -> error::UResult { /// /// This always succeeds on unix platforms, /// and fails on other platforms if the bytes can't be parsed as UTF-8. +#[cfg_attr(unix, expect(clippy::unnecessary_wraps))] pub fn os_string_to_vec(s: OsString) -> error::UResult> { #[cfg(unix)] let v = s.into_vec(); diff --git a/tests/test_uudoc.rs b/tests/test_uudoc.rs index e9b33406674..b4f12c0999e 100644 --- a/tests/test_uudoc.rs +++ b/tests/test_uudoc.rs @@ -21,7 +21,7 @@ pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_uudoc"); fn init() { // No need for unsafe here unsafe { - std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY); + env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY); } // Print for debugging eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}");