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 @@ -664,7 +664,6 @@ match_same_arms = "allow" # 204
redundant_closure_for_method_calls = "allow" # 125
cast_possible_truncation = "allow" # 122
too_many_lines = "allow" # 101
trivially_copy_pass_by_ref = "allow" # 84
cast_possible_wrap = "allow" # 78
cast_sign_loss = "allow" # 70
struct_excessive_bools = "allow" # 68
Expand Down
2 changes: 1 addition & 1 deletion src/uu/comm/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum FileNumber {
}

impl FileNumber {
fn as_str(&self) -> &'static str {
fn as_str(self) -> &'static str {
match self {
Self::One => "1",
Self::Two => "2",
Expand Down
26 changes: 13 additions & 13 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ fn show_error_if_needed(error: &CpError) {
/// Behavior is determined by the `options` parameter, see [`Options`] for details.
pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult<()> {
let target_type = TargetType::determine(sources, target);
verify_target_type(target, &target_type)?;
verify_target_type(target, target_type)?;

let mut non_fatal_errors = false;
let mut seen_sources = HashSet::with_capacity(sources.len());
Expand Down Expand Up @@ -1614,8 +1614,8 @@ fn file_mode_for_interactive_overwrite(
}

impl OverwriteMode {
fn verify(&self, path: &Path, debug: bool) -> CopyResult<()> {
match *self {
fn verify(self, path: &Path, debug: bool) -> CopyResult<()> {
match self {
Self::NoClobber => {
if debug {
println!("{}", translate!("cp-debug-skipped", "path" => path.quote()));
Expand Down Expand Up @@ -1652,12 +1652,12 @@ impl OverwriteMode {
/// Note: ENOTSUP/EOPNOTSUPP errors are silently ignored when not required, as per GNU cp
/// documentation: "Try to preserve SELinux security context and extended attributes (xattr),
/// but ignore any failure to do that and print no corresponding diagnostic."
fn handle_preserve<F: Fn() -> CopyResult<()>>(p: &Preserve, f: F) -> CopyResult<()> {
fn handle_preserve<F: Fn() -> CopyResult<()>>(p: Preserve, f: F) -> CopyResult<()> {
match p {
Preserve::No { .. } => {}
Preserve::Yes { required } => {
let result = f();
if *required {
if required {
result?;
} else if let Err(ref error) = result {
// Suppress ENOTSUP errors when preservation is optional.
Expand Down Expand Up @@ -1724,7 +1724,7 @@ pub(crate) fn copy_attributes(

// Ownership must be changed first to avoid interfering with mode change.
#[cfg(unix)]
handle_preserve(&attributes.ownership, || -> CopyResult<()> {
handle_preserve(attributes.ownership, || -> CopyResult<()> {
use std::os::unix::prelude::MetadataExt;
use uucore::perms::Verbosity;
use uucore::perms::VerbosityLevel;
Expand Down Expand Up @@ -1759,7 +1759,7 @@ pub(crate) fn copy_attributes(
Ok(())
})?;

handle_preserve(&attributes.mode, || -> CopyResult<()> {
handle_preserve(attributes.mode, || -> CopyResult<()> {
// The `chmod()` system call that underlies the
// `fs::set_permissions()` call is unable to change the
// permissions of a symbolic link. In that case, we just
Expand All @@ -1778,7 +1778,7 @@ pub(crate) fn copy_attributes(
Ok(())
})?;

handle_preserve(&attributes.timestamps, || -> CopyResult<()> {
handle_preserve(attributes.timestamps, || -> CopyResult<()> {
let atime = FileTime::from_last_access_time(&source_metadata);
let mtime = FileTime::from_last_modification_time(&source_metadata);
if dest.is_symlink() {
Expand All @@ -1791,7 +1791,7 @@ pub(crate) fn copy_attributes(
})?;

#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
handle_preserve(&attributes.context, || -> CopyResult<()> {
handle_preserve(attributes.context, || -> CopyResult<()> {
// Get the source context and apply it to the destination
if let Ok(context) = selinux::SecurityContext::of_path(source, false, false) {
if let Some(context) = context {
Expand All @@ -1809,7 +1809,7 @@ pub(crate) fn copy_attributes(
Ok(())
})?;

handle_preserve(&attributes.xattr, || -> CopyResult<()> {
handle_preserve(attributes.xattr, || -> CopyResult<()> {
#[cfg(all(unix, not(target_os = "android")))]
{
copy_extended_attrs(source, dest)?;
Expand Down Expand Up @@ -2767,11 +2767,11 @@ fn copy_link(
}

/// Generate an error message if `target` is not the correct `target_type`
pub fn verify_target_type(target: &Path, target_type: &TargetType) -> CopyResult<()> {
pub fn verify_target_type(target: &Path, target_type: TargetType) -> CopyResult<()> {
match (target_type, target.is_dir()) {
(&TargetType::Directory, false) => Err(translate!("cp-error-target-not-directory", "target" => target.quote())
(TargetType::Directory, false) => Err(translate!("cp-error-target-not-directory", "target" => target.quote())
.into()),
(&TargetType::File, true) => Err(translate!("cp-error-cannot-overwrite-directory-with-non-directory", "dir" => target.quote())
(TargetType::File, true) => Err(translate!("cp-error-cannot-overwrite-directory-with-non-directory", "dir" => target.quote())
.into()),
_ => Ok(()),
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dd/src/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) enum SuffixType {
}

impl SuffixType {
fn base_and_suffix(&self, n: u128) -> (u128, &'static str) {
fn base_and_suffix(self, n: u128) -> (u128, &'static str) {
let (bases, suffixes) = match self {
Self::Iec => (IEC_BASES, IEC_SUFFIXES),
Self::Si => (SI_BASES, SI_SUFFIXES),
Expand Down
4 changes: 2 additions & 2 deletions src/uu/df/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ pub(crate) enum SuffixType {

impl SuffixType {
/// The first ten powers of 1024 and 1000, respectively.
fn bases(&self) -> [u128; 10] {
fn bases(self) -> [u128; 10] {
match self {
Self::Iec | Self::HumanReadable(HumanReadable::Binary) => IEC_BASES,
Self::Si | Self::HumanReadable(HumanReadable::Decimal) => SI_BASES,
}
}

/// Suffixes for the first nine multi-byte unit suffixes.
fn suffixes(&self) -> [&'static str; 9] {
fn suffixes(self) -> [&'static str; 9] {
match self {
// we use "kB" instead of "KB", same as GNU df
Self::Si => ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
Expand Down
8 changes: 4 additions & 4 deletions src/uu/df/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ impl Column {
}

/// Return the alignment of the specified column.
pub(crate) fn alignment(column: &Self) -> Alignment {
match column {
pub(crate) fn alignment(self) -> Alignment {
match self {
Self::Source | Self::Target | Self::File | Self::Fstype => Alignment::Left,
_ => Alignment::Right,
}
}

/// Return the minimum width of the specified column.
pub(crate) fn min_width(column: &Self) -> usize {
match column {
pub(crate) fn min_width(self) -> usize {
match self {
// 14 = length of "Filesystem" plus 4 spaces
Self::Source => 14,
Self::Used => 5,
Expand Down
4 changes: 2 additions & 2 deletions src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl Table {
.columns
.iter()
.enumerate()
.map(|(i, col)| Column::min_width(col).max(headers[i].len()))
.map(|(i, col)| col.min_width().max(headers[i].len()))
.collect();

let mut rows = vec![headers.iter().map(Cell::from_string).collect()];
Expand Down Expand Up @@ -527,7 +527,7 @@ impl Table {
let mut alignments = Vec::new();

for column in columns {
alignments.push(Column::alignment(column));
alignments.push(column.alignment());
}

alignments
Expand Down
6 changes: 3 additions & 3 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct Options<'a> {
fn parse_name_value_opt<'a>(opts: &mut Options<'a>, opt: &'a OsStr) -> UResult<bool> {
// is it a NAME=VALUE like opt ?
let wrap = NativeStr::<'a>::new(opt);
let split_o = wrap.split_once(&'=');
let split_o = wrap.split_once('=');
if let Some((name, value)) = split_o {
// yes, so push name, value pair
opts.sets.push((name, value));
Expand Down Expand Up @@ -930,8 +930,8 @@ fn apply_unset_env_vars(opts: &Options<'_>) -> Result<(), Box<dyn UError>> {
for name in &opts.unsets {
let native_name = NativeStr::new(name);
if name.is_empty()
|| native_name.contains(&'\0').unwrap()
|| native_name.contains(&'=').unwrap()
|| native_name.contains('\0').unwrap()
|| native_name.contains('=').unwrap()
{
return Err(USimpleError::new(
125,
Expand Down
6 changes: 3 additions & 3 deletions src/uu/env/src/native_int_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn from_native_int_representation_owned(input: NativeIntString) -> OsString
}
}

pub fn get_single_native_int_value(c: &char) -> Option<NativeCharInt> {
pub fn get_single_native_int_value(c: char) -> Option<NativeCharInt> {
#[cfg(target_os = "windows")]
{
let mut buf = [0u16, 0];
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a> NativeStr<'a> {
self.native
}

pub fn contains(&self, x: &char) -> Option<bool> {
pub fn contains(&self, x: char) -> Option<bool> {
let n_c = get_single_native_int_value(x)?;
Some(self.native.contains(&n_c))
}
Expand All @@ -239,7 +239,7 @@ impl<'a> NativeStr<'a> {
result.unwrap()
}

pub fn split_once(&self, pred: &char) -> Option<(Cow<'a, OsStr>, Cow<'a, OsStr>)> {
pub fn split_once(&self, pred: char) -> Option<(Cow<'a, OsStr>, Cow<'a, OsStr>)> {
let n_c = get_single_native_int_value(pred)?;
let p = self.native.iter().position(|&x| x == n_c)?;
let before = self.slice(0, p);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/env/src/string_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'a> StringParser<'a> {
}

pub fn skip_until_char_or_end(&mut self, c: char) {
let native_rep = get_single_native_int_value(&c).unwrap();
let native_rep = get_single_native_int_value(c).unwrap();
let pos = self.remaining.iter().position(|x| *x == native_rep);

if let Some(pos) = pos {
Expand Down
20 changes: 4 additions & 16 deletions src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ pub enum StringOp {
}

impl BinOp {
fn eval(
&self,
left: ExprResult<NumOrStr>,
right: ExprResult<NumOrStr>,
) -> ExprResult<NumOrStr> {
fn eval(self, left: ExprResult<NumOrStr>, right: ExprResult<NumOrStr>) -> ExprResult<NumOrStr> {
match self {
Self::Relation(op) => op.eval(left, right),
Self::Numeric(op) => op.eval(left, right),
Expand All @@ -70,7 +66,7 @@ impl BinOp {
}

impl RelationOp {
fn eval(&self, a: ExprResult<NumOrStr>, b: ExprResult<NumOrStr>) -> ExprResult<NumOrStr> {
fn eval(self, a: ExprResult<NumOrStr>, b: ExprResult<NumOrStr>) -> ExprResult<NumOrStr> {
// Make sure that the given comparison validates the relational operator.
let check_cmp = |cmp| {
use RelationOp::{Eq, Geq, Gt, Leq, Lt, Neq};
Expand Down Expand Up @@ -98,11 +94,7 @@ impl RelationOp {
}

impl NumericOp {
fn eval(
&self,
left: ExprResult<NumOrStr>,
right: ExprResult<NumOrStr>,
) -> ExprResult<NumOrStr> {
fn eval(self, left: ExprResult<NumOrStr>, right: ExprResult<NumOrStr>) -> ExprResult<NumOrStr> {
let a = left?.eval_as_bigint()?;
let b = right?.eval_as_bigint()?;
Ok(NumOrStr::Num(match self {
Expand All @@ -124,11 +116,7 @@ impl NumericOp {
}

impl StringOp {
fn eval(
&self,
left: ExprResult<NumOrStr>,
right: ExprResult<NumOrStr>,
) -> ExprResult<NumOrStr> {
fn eval(self, left: ExprResult<NumOrStr>, right: ExprResult<NumOrStr>) -> ExprResult<NumOrStr> {
match self {
Self::Or => {
let left = left?;
Expand Down
11 changes: 6 additions & 5 deletions src/uu/groups/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ enum GroupsError {

impl UError for GroupsError {}

fn infallible_gid2grp(gid: &u32) -> String {
if let Ok(grp) = gid2grp(*gid) {
fn infallible_gid2grp(gid: u32) -> String {
if let Ok(grp) = gid2grp(gid) {
grp
} else {
// The `show!()` macro sets the global exit code for the program.
show!(GroupsError::GroupNotFound(*gid));
show!(GroupsError::GroupNotFound(gid));
gid.to_string()
}
}
Expand All @@ -58,15 +58,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let Ok(gids) = get_groups_gnu(None) else {
return Err(GroupsError::GetGroupsFailed.into());
};
let groups: Vec<String> = gids.iter().map(infallible_gid2grp).collect();
let groups: Vec<String> = gids.into_iter().map(infallible_gid2grp).collect();
writeln!(stdout(), "{}", groups.join(" "))?;
return Ok(());
}

for user in users {
match Passwd::locate(user.as_str()) {
Ok(p) => {
let groups: Vec<String> = p.belongs_to().iter().map(infallible_gid2grp).collect();
let groups: Vec<String> =
p.belongs_to().into_iter().map(infallible_gid2grp).collect();
writeln!(stdout(), "{user} : {}", groups.join(" "))?;
}
Err(_) => {
Expand Down
6 changes: 3 additions & 3 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'a> StyleManager<'a> {
} else if file_type.is_dir() {
self.indicator_for_directory(path)
} else {
self.indicator_for_special_file(file_type)
self.indicator_for_special_file(*file_type)
}
}

Expand Down Expand Up @@ -478,7 +478,7 @@ impl<'a> StyleManager<'a> {
}

#[cfg(unix)]
fn indicator_for_special_file(&self, file_type: &fs::FileType) -> Option<Indicator> {
fn indicator_for_special_file(&self, file_type: fs::FileType) -> Option<Indicator> {
if file_type.is_fifo() && self.has_indicator_style(Indicator::FIFO) {
return Some(Indicator::FIFO);
}
Expand All @@ -495,7 +495,7 @@ impl<'a> StyleManager<'a> {
}

#[cfg(not(unix))]
fn indicator_for_special_file(&self, _file_type: &fs::FileType) -> Option<Indicator> {
fn indicator_for_special_file(&self, _file_type: fs::FileType) -> Option<Indicator> {
None
}

Expand Down
Loading
Loading