Skip to content
Merged
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 @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,9 +2328,9 @@ fn calculate_dest_permissions(
source_metadata: &Metadata,
options: &Options,
context: &str,
) -> CopyResult<Permissions> {
) -> Permissions {
if let Some(metadata) = dest_metadata {
Ok(metadata.permissions())
metadata.permissions()
} else {
#[cfg(unix)]
{
Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -2524,7 +2523,7 @@ fn copy_file(
&source_metadata,
options,
context,
)?;
);

#[cfg(unix)]
let source_is_fifo = source_metadata.file_type().is_fifo();
Expand Down
6 changes: 2 additions & 4 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,16 +1092,14 @@ 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);
}
if i.settings.oflags.nocache {
o.discard_cache(0, 0);
}

Ok(())
}

/// Copy the given input data to this output, consuming both.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileInfo> {
Some(FileInfo {
file_id: metadata.ino() as u128,
Expand Down
13 changes: 5 additions & 8 deletions src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ fn build_regex(pattern_bytes: Vec<u8>) -> ExprResult<(Regex, String)> {
}

/// Find matches in the input using the compiled regex
fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> ExprResult<String> {
fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> String {
use onig::EncodedBytes;
use uucore::i18n::{UEncoding, get_locale_encoding};

let encoding = get_locale_encoding();

// 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) {
Expand Down Expand Up @@ -483,7 +483,7 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> 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 {
Expand All @@ -500,9 +500,7 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> ExprResul
}
}
}
};

Ok(result)
}
}

/// Evaluate a match expression with locale-aware regex matching
Expand Down Expand Up @@ -533,8 +531,7 @@ fn evaluate_match_expression(left_bytes: Vec<u8>, right_bytes: Vec<u8>) -> 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
Expand Down
2 changes: 2 additions & 0 deletions src/uu/false/src/false.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/uu/head/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ pub fn parse_obsolete(src: &str) -> Option<Result<Vec<OsString>, 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
}
Expand All @@ -48,11 +52,11 @@ fn process_num_block(
src: &str,
last_char: char,
chars: &mut std::str::CharIndices,
) -> Option<Result<Vec<OsString>, ParseError>> {
) -> Result<Vec<OsString>, ParseError> {
let num = match src.parse::<usize>() {
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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -134,6 +138,7 @@ mod tests {
}
}

#[expect(clippy::unnecessary_wraps, reason = "test helper")]
fn obsolete_result(src: &[&str]) -> Option<Result<Vec<String>, ParseError>> {
Some(Ok(src.iter().map(|&s| s.to_string()).collect()))
}
Expand Down
10 changes: 6 additions & 4 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option<String
const LOCALE_FORMAT: (&str, Option<&str>) = ("%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<String>), LsError> {
Ok((recent.to_string(), older.map(String::from)))
}
Expand Down Expand Up @@ -2634,7 +2635,7 @@ fn display_additional_leading_info(
item: &PathData,
padding: &PaddingCollection,
config: &Config,
) -> UResult<String> {
) -> String {
let mut result = String::new();
#[cfg(unix)]
{
Expand All @@ -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)]
Expand Down Expand Up @@ -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}")?;
}
Expand Down Expand Up @@ -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
};
Expand Down
10 changes: 7 additions & 3 deletions src/uu/mkdir/src/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, String> {
Ok(DEFAULT_PERM)
}
Expand Down Expand Up @@ -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)),
}
Expand Down Expand Up @@ -154,14 +159,13 @@ pub fn uu_app() -> Command {
/**
* Create the list of new directories
*/
fn exec(dirs: ValuesRef<OsString>, config: &Config) -> UResult<()> {
fn exec(dirs: ValuesRef<OsString>, 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`.
Expand Down
9 changes: 4 additions & 5 deletions src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down Expand Up @@ -483,7 +483,7 @@ pub fn uu_app() -> Command {
)
}

fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> {
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());
Expand All @@ -503,8 +503,7 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult<P
}
// We guarantee utf8.
let buf = String::from_utf8(buf).unwrap();
let tmpdir = Path::new(tmpdir).join(buf);
Ok(tmpdir)
Path::new(tmpdir).join(buf)
}

/// Create a temporary directory with the given parameters.
Expand Down Expand Up @@ -617,7 +616,7 @@ pub fn mktemp(options: &Options) -> UResult<PathBuf> {

// 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)
}
Expand Down
21 changes: 6 additions & 15 deletions src/uu/mv/src/hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ pub struct HardlinkOptions {
pub verbose: bool,
}

/// Result type for hardlink operations
pub type HardlinkResult<T> = Result<T, HardlinkError>;

/// Errors that can occur during hardlink operations
#[derive(Debug)]
pub enum HardlinkError {
Expand Down Expand Up @@ -122,7 +119,7 @@ impl HardlinkTracker {
dest: &Path,
scanner: &HardlinkGroupScanner,
options: &HardlinkOptions,
) -> HardlinkResult<Option<PathBuf>> {
) -> Option<PathBuf> {
use std::os::unix::fs::MetadataExt;

let metadata = match source.metadata() {
Expand All @@ -132,7 +129,7 @@ impl HardlinkTracker {
if options.verbose {
eprintln!("warning: cannot get metadata for {}: {}", source.quote(), e);
}
return Ok(None);
return None;
}
};

Expand All @@ -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
}
}

Expand All @@ -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
Expand Down Expand Up @@ -206,8 +199,6 @@ impl HardlinkGroupScanner {
);
}
}

Ok(())
}

/// Scan a single path (file or directory)
Expand Down
Loading
Loading