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
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,9 @@ 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 @@ -193,18 +193,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) => {
print!("{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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please document "why"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment - but the extended version: this is what it would look like after optimization -- i don't think it's as readable

        [b'l' | b'r' | b'e', b'c']
            | [b'r', b's']
            | [b'n' | b's' | b'd', b'o']
            | [b'f' | b'd' | b'p' | b'm', b'i']
            | [b'l', b'n']
            | [b'b' | b'c', b'd']
            | [b'o', b'r' | b'w']
            | [b'e', b'x']
            | [b's', b'u' | b'g' | b't']
            | [b't', b'w']
            | [b'c', b'a' | b'l']
            | [b'm', b'h']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed :)

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 @@ -3530,7 +3530,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 @@ -3540,9 +3540,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 @@ -3561,9 +3561,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 @@ -600,16 +600,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: 2 additions & 0 deletions src/uucore/src/lib/features/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ pub struct Passwd {
/// AKA passwd.pw_dir
pub user_dir: Option<String>,
/// AKA passwd.pw_passwd
#[expect(clippy::struct_field_names)]
pub user_passwd: Option<String>,
/// AKA passwd.pw_class
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
pub user_access_class: Option<String>,
/// AKA passwd.pw_change
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
#[expect(clippy::struct_field_names)]
pub passwd_change_time: time_t,
/// AKA passwd.pw_expire
#[cfg(any(target_os = "freebsd", target_vendor = "apple"))]
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 @@ -552,7 +552,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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is part of the clippy::format_push_string -- clippy warns without this change

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
36 changes: 16 additions & 20 deletions src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,41 +207,37 @@ pub enum OutputFormat {
}

struct FormattedUptime {
up_days: i64,
up_hours: i64,
up_mins: i64,
days: i64,
hours: i64,
mins: i64,
}

impl FormattedUptime {
fn new(up_secs: i64) -> Self {
let up_days = up_secs / 86400;
let up_hours = (up_secs - (up_days * 86400)) / 3600;
let up_mins = (up_secs - (up_days * 86400) - (up_hours * 3600)) / 60;

Self {
up_days,
up_hours,
up_mins,
}
let days = up_secs / 86400;
let hours = (up_secs - (days * 86400)) / 3600;
let mins = (up_secs - (days * 86400) - (hours * 3600)) / 60;

Self { days, hours, mins }
}

fn get_human_readable_uptime(&self) -> String {
translate!(
"uptime-format",
"days" => self.up_days,
"time" => format!("{:02}:{:02}", self.up_hours, self.up_mins))
"days" => self.days,
"time" => format!("{:02}:{:02}", self.hours, self.mins))
}

fn get_pretty_print_uptime(&self) -> String {
let mut parts = Vec::new();
if self.up_days > 0 {
parts.push(translate!("uptime-format-pretty-day", "day" => self.up_days));
if self.days > 0 {
parts.push(translate!("uptime-format-pretty-day", "day" => self.days));
}
if self.up_hours > 0 {
parts.push(translate!("uptime-format-pretty-hour", "hour" => self.up_hours));
if self.hours > 0 {
parts.push(translate!("uptime-format-pretty-hour", "hour" => self.hours));
}
if self.up_mins > 0 || parts.is_empty() {
parts.push(translate!("uptime-format-pretty-min", "min" => self.up_mins));
if self.mins > 0 || parts.is_empty() {
parts.push(translate!("uptime-format-pretty-min", "min" => self.mins));
}
parts.join(", ")
}
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