Skip to content
Open
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
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,10 @@ should_panic_without_expect = "allow" # 2
doc_markdown = "allow"
unused_self = "allow"
enum_glob_use = "allow"
unnested_or_patterns = "allow"

# TODO: uucore/src/lib/features/fsxattr.rs apply_xattrs() - consider using iterator
implicit_hasher = "allow"
struct_field_names = "allow"
doc_link_with_quotes = "allow"
format_push_string = "allow"
flat_map_option = "allow"
from_iter_instead_of_collect = "allow"
large_types_passed_by_value = "allow"

[workspace.metadata.cargo-shear]
ignored = ["clap", "fluent", "libstdbuf"]
4 changes: 2 additions & 2 deletions src/uu/df/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Filesystem {
mount_info.mount_dir.clone()
};
#[cfg(unix)]
let usage = FsUsage::new(statfs(&stat_path).ok()?);
let usage = FsUsage::new(&statfs(&stat_path).ok()?);
#[cfg(windows)]
let usage = FsUsage::new(Path::new(&stat_path)).ok()?;
Some(Self {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Filesystem {
dummy: false,
};

let usage = FsUsage::new(stat_result);
let usage = FsUsage::new(&stat_result);

Ok(Self {
file: Some(file),
Expand Down
16 changes: 7 additions & 9 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// SMACK label
#[cfg(feature = "smack")]
if state.smack_supported {
match uucore::smack::get_smack_label_for_self() {
return match uucore::smack::get_smack_label_for_self() {
Ok(label) => {
write!(lock, "{label}{line_ending}")?;
return Ok(());
Ok(())
}
Err(_) => {
return Err(USimpleError::new(
1,
translate!("id-error-cannot-get-context"),
));
}
}
Err(_) => Err(USimpleError::new(
1,
translate!("id-error-cannot-get-context"),
)),
};
}

// Neither SELinux nor SMACK supported
Expand Down
2 changes: 2 additions & 0 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ fn parse_funky_string(
}
}

// current match list is much easier to read than nested or-patterns
#[expect(clippy::unnested_or_patterns)]
fn is_valid_ls_colors_prefix(label: [u8; 2]) -> bool {
matches!(
label,
Expand Down
10 changes: 5 additions & 5 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3559,7 +3559,7 @@ fn get_security_context<'a>(

#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
if config.selinux_supported {
match selinux::SecurityContext::of_path(path, must_dereference, false) {
return match selinux::SecurityContext::of_path(path, must_dereference, false) {
Err(_r) => {
// TODO: show the actual reason why it failed
show_warning!(
Expand All @@ -3569,9 +3569,9 @@ fn get_security_context<'a>(
"path" => path.quote().to_string()
)
);
return Cow::Borrowed(SUBSTITUTE_STRING);
Cow::Borrowed(SUBSTITUTE_STRING)
}
Ok(None) => return Cow::Borrowed(SUBSTITUTE_STRING),
Ok(None) => Cow::Borrowed(SUBSTITUTE_STRING),
Ok(Some(context)) => {
let context = context.as_bytes();

Expand All @@ -3590,9 +3590,9 @@ fn get_security_context<'a>(
String::from_utf8_lossy(context).to_string()
});

return Cow::Owned(res);
Cow::Owned(res)
}
}
};
}

#[cfg(all(feature = "smack", target_os = "linux"))]
Expand Down
8 changes: 4 additions & 4 deletions src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,16 +616,16 @@ fn remove_dir_recursive(
{
if let Some(s) = path.to_str() {
if s.len() > 1000 {
match fs::remove_dir_all(path) {
Ok(_) => return false,
return match fs::remove_dir_all(path) {
Ok(_) => false,
Err(e) => {
let e = e.map_err_context(
|| translate!("rm-error-cannot-remove", "file" => path.quote()),
);
show_error!("{e}");
return true;
true
}
}
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/format/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> FormatArguments<'a> {
return Err(ExtendedParserError::NotNumeric);
};

let (Some((b'"', bytes)) | Some((b'\'', bytes))) = s.split_first() else {
let Some((b'"' | b'\'', bytes)) = s.split_first() else {
// This really can't happen, the string we are given must start with '/".
debug_assert!(false);
return Err(ExtendedParserError::NotNumeric);
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ pub struct FsUsage {

impl FsUsage {
#[cfg(unix)]
pub fn new(statvfs: StatFs) -> Self {
pub fn new(statvfs: &StatFs) -> Self {
{
#[cfg(all(
not(any(target_os = "freebsd", target_os = "openbsd")),
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl HasHardwareFeatures for CpuFeatures {
/// This is used by GNU utilities to allow users to disable hardware acceleration.
#[derive(Debug, Clone)]
pub struct SimdPolicy {
/// Features disabled via GLIBC_TUNABLES (e.g., ["AVX2", "AVX512F"])
/// Features disabled via GLIBC_TUNABLES (e.g., `["AVX2", "AVX512F"]`)
disabled_by_env: BTreeSet<HardwareFeature>,
hardware_features: &'static CpuFeatures,
}
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! [`BufRead::lines`] method. While the [`BufRead::lines`] method
//! yields [`String`] instances that do not include the line ending
//! characters (`"\n"` or `"\r\n"`), our functions yield
//! [`Vec`]<['u8']> instances that include the line ending
//! [`Vec`]<[`u8`]> instances that include the line ending
//! characters. This is useful if the input data does not end with a
//! newline character and you want to preserve the exact form of the
//! input data.
Expand Down
3 changes: 2 additions & 1 deletion src/uucore/src/lib/features/parser/shortcut_value_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use clap::{
builder::{PossibleValue, TypedValueParser},
error::{ContextKind, ContextValue, ErrorKind},
};
use std::fmt::Write as _;

/// A parser that accepts shortcuts for values.
#[derive(Clone)]
Expand Down Expand Up @@ -69,7 +70,7 @@ fn add_ambiguous_value_tip(
) {
let mut formatted_possible_values = String::new();
for (i, s) in possible_values.iter().enumerate() {
formatted_possible_values.push_str(&format!("'{}'", s.get_name()));
let _ = write!(formatted_possible_values, "'{}'", s.get_name());
if i < possible_values.len() - 2 {
formatted_possible_values.push_str(", ");
} else if i < possible_values.len() - 1 {
Expand Down
7 changes: 2 additions & 5 deletions src/uucore/src/lib/features/proc_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl ProcessInformation {
.follow_links(false)
.into_iter()
.flatten()
.flat_map(|it| {
.filter_map(|it| {
it.path()
.file_name()
.and_then(|it| it.to_str())
Expand Down Expand Up @@ -470,10 +470,7 @@ mod tests {
assert_eq!(pid_entry.tty(), Teletype::Unknown);
} else {
assert_eq!(result.len(), 1);
assert_eq!(
pid_entry.tty(),
Vec::from_iter(result.into_iter()).first().unwrap().clone()
);
assert_eq!(pid_entry.tty(), result.into_iter().next().unwrap());
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ mod tests {
assert!(boot_time > 0, "Boot time should be positive");

// Boot time should be after 2000-01-01 (946684800 seconds since epoch)
assert!(boot_time > 946684800, "Boot time should be after year 2000");
assert!(
boot_time > 946_684_800,
"Boot time should be after year 2000"
);

// Boot time should be before current time
let now = Timestamp::now().as_second();
Expand Down
3 changes: 2 additions & 1 deletion tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ fn test_output_lossy_utf8() {
#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_comm_anonymous_pipes() {
use std::fmt::Write as _;
use std::{io::Write, os::fd::AsRawFd, process};
use uucore::pipes::pipe;

Expand All @@ -692,7 +693,7 @@ fn test_comm_anonymous_pipes() {
// write 1500 lines into comm1: 00000\n00001\n...01500\n
let mut content = String::new();
for i in 0..1500 {
content.push_str(&format!("{i:05}\n"));
let _ = writeln!(content, "{i:05}");
}
assert!(comm1_writer.write_all(content.as_bytes()).is_ok());
drop(comm1_writer);
Expand Down
Loading