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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ missing_errors_doc = "allow" # 1572
missing_panics_doc = "allow" # 946
must_use_candidate = "allow" # 322
match_same_arms = "allow" # 204
redundant_closure_for_method_calls = "allow" # 125
cast_possible_truncation = "allow" # 122
too_many_lines = "allow" # 101
cast_possible_wrap = "allow" # 78
Expand Down
3 changes: 2 additions & 1 deletion src/uu/checksum_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// spell-checker:ignore (ToDO) algo

use std::borrow::Borrow;
use std::ffi::OsString;

use clap::builder::ValueParser;
Expand Down Expand Up @@ -159,7 +160,7 @@ pub fn checksum_main(
let files = matches
.get_many::<OsString>(options::FILE)
.unwrap()
.map(|s| s.as_os_str());
.map(Borrow::borrow);

if check {
// cksum does not support '--check'ing legacy algorithms
Expand Down
2 changes: 1 addition & 1 deletion src/uu/chgrp/src/chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn get_dest_gid(matches: &ArgMatches) -> UResult<(Option<u32>, String)> {
} else {
let group = matches
.get_one::<String>(options::ARG_GROUP)
.map(|s| s.as_str())
.map(String::as_str)
.unwrap_or_default();
raw_group = group.to_string();
if group.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

let commands = match matches.get_many::<String>(options::COMMAND) {
Some(v) => v.map(|s| s.as_str()).collect(),
Some(v) => v.map(String::as_str).collect(),
None => vec![],
};

Expand Down
4 changes: 2 additions & 2 deletions src/uu/cp/src/copydir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn get_local_to_root_parent(
/// Given an iterator, return all its items except the last.
fn skip_last<T>(mut iter: impl Iterator<Item = T>) -> impl Iterator<Item = T> {
let last = iter.next();
iter.scan(last, |state, item| state.replace(item))
iter.scan(last, Option::replace)
}

/// Paths that are invariant throughout the traversal when copying a directory.
Expand All @@ -111,7 +111,7 @@ impl<'a> Context<'a> {
let root_path = current_dir.join(root);
let target_is_file = target.is_file();
let root_parent = if target.exists() && !root.to_str().unwrap().ends_with("/.") {
root_path.parent().map(|p| p.to_path_buf())
root_path.parent().map(ToOwned::to_owned)
} else if root == Path::new(".") && target.is_dir() {
// Special case: when copying current directory (.) to an existing directory,
// we don't want to use the parent path as root_parent because we want to
Expand Down
6 changes: 3 additions & 3 deletions src/uu/csplit/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ mod tests {
fn up_to_line_pattern() {
let input: Vec<String> = vec!["24", "42", "{*}", "50", "{4}"]
.into_iter()
.map(|v| v.to_string())
.map(ToOwned::to_owned)
.collect();
let patterns = get_patterns(input.as_slice()).unwrap();
assert_eq!(patterns.len(), 3);
Expand Down Expand Up @@ -225,7 +225,7 @@ mod tests {
"/test6.*end$/-3",
]
.into_iter()
.map(|v| v.to_string())
.map(ToString::to_string)
.collect();
let patterns = get_patterns(input.as_slice()).unwrap();
assert_eq!(patterns.len(), 6);
Expand Down Expand Up @@ -287,7 +287,7 @@ mod tests {
"%test6.*end$%-3",
]
.into_iter()
.map(|v| v.to_string())
.map(ToString::to_string)
.collect();
let patterns = get_patterns(input.as_slice()).unwrap();
assert_eq!(patterns.len(), 6);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn cut_fields_newline_char_delim<R: Read, W: Write>(
) -> UResult<()> {
let buf_in = BufReader::new(reader);

let segments: Vec<_> = buf_in.split(newline_char).filter_map(|x| x.ok()).collect();
let segments: Vec<_> = buf_in.split(newline_char).filter_map(Result::ok).collect();
let mut print_delim = false;

for &Range { low, high } in ranges {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ fn build_tz_abbrev_map() -> HashMap<String, String> {
/// Uses lazy-loaded cache with preferred mappings for disambiguation.
fn tz_abbrev_to_iana(abbrev: &str) -> Option<&str> {
let cache = TZ_ABBREV_CACHE.get_or_init(build_tz_abbrev_map);
cache.get(abbrev).map(|s| s.as_str())
cache.get(abbrev).map(String::as_str)
}

/// Attempts to parse a date string that contains a timezone abbreviation (e.g. "EST").
Expand Down
2 changes: 1 addition & 1 deletion src/uu/date/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod tests {
if ptr.is_null() {
None
} else {
CStr::from_ptr(ptr).to_str().ok().map(|s| s.to_string())
CStr::from_ptr(ptr).to_str().ok().map(ToString::to_string)
}
};

Expand Down
10 changes: 5 additions & 5 deletions src/uu/dd/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ const SPACE: u8 = b' ';
/// all-spaces block at the end. Otherwise, remove the last block if
/// it is all spaces.
fn block(buf: &[u8], cbs: usize, sync: bool, rstat: &mut ReadStat) -> Vec<Vec<u8>> {
let mut blocks = buf
.split(|&e| e == NEWLINE)
.map(|split| split.to_vec())
.fold(Vec::new(), |mut blocks, mut split| {
let mut blocks = buf.split(|&e| e == NEWLINE).map(<[u8]>::to_vec).fold(
Vec::new(),
|mut blocks, mut split| {
if split.len() > cbs {
rstat.records_truncated += 1;
}
split.resize(cbs, SPACE);
blocks.push(split);

blocks
});
},
);

// If `sync` is true and there has been at least one partial
// record read from the input, then leave the all-spaces block at
Expand Down
2 changes: 1 addition & 1 deletion src/uu/df/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Column {
let names = matches
.get_many::<String>(OPT_OUTPUT)
.unwrap()
.map(|s| s.as_str());
.map(String::as_str);
let mut seen: Vec<&str> = vec![];
let mut columns = vec![];
for name in names {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let files = matches
.get_many::<OsString>(options::FILE)
.map_or(vec![], |file_values| file_values.collect());
.map_or(vec![], Iterator::collect);

// clap provides .conflicts_with / .conflicts_with_all, but we want to
// manually handle conflicts so we can match the output of GNU coreutils
Expand Down
2 changes: 1 addition & 1 deletion src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let max_depth = parse_depth(
matches
.get_one::<String>(options::MAX_DEPTH)
.map(|s| s.as_str()),
.map(String::as_str),
summarize,
)?;

Expand Down
12 changes: 8 additions & 4 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,16 +863,20 @@ fn apply_removal_of_all_env_vars(opts: &Options<'_>) {
fn make_options(matches: &clap::ArgMatches) -> UResult<Options<'_>> {
let ignore_env = matches.get_flag("ignore-environment");
let line_ending = LineEnding::from_zero_flag(matches.get_flag("null"));
let running_directory = matches.get_one::<OsString>("chdir").map(|s| s.as_os_str());
let running_directory = matches
.get_one::<OsString>("chdir")
.map(OsString::as_os_str);
let files = match matches.get_many::<OsString>("file") {
Some(v) => v.map(|s| s.as_os_str()).collect(),
Some(v) => v.map(OsString::as_os_str).collect(),
None => Vec::with_capacity(0),
};
let unsets = match matches.get_many::<OsString>("unset") {
Some(v) => v.map(|s| s.as_os_str()).collect(),
Some(v) => v.map(OsString::as_os_str).collect(),
None => Vec::with_capacity(0),
};
let argv0 = matches.get_one::<OsString>("argv0").map(|s| s.as_os_str());
let argv0 = matches
.get_one::<OsString>("argv0")
.map(OsString::as_os_str);

#[cfg(unix)]
let ignore_signal = build_signal_request(matches, options::IGNORE_SIGNAL)?;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/env/src/native_int_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'a> NativeStr<'a> {
let n_prefix = to_native_int_representation(prefix);
let result = self.match_cow(
|b| b.strip_prefix(&*n_prefix).ok_or(()),
|o| o.strip_prefix(&*n_prefix).map(|x| x.to_vec()).ok_or(()),
|o| o.strip_prefix(&*n_prefix).map(ToOwned::to_owned).ok_or(()),
);
result.ok()
}
Expand All @@ -266,7 +266,7 @@ impl<'a> NativeStr<'a> {
let n_prefix = to_native_int_representation(prefix);
let result = self.match_cow_native(
|b| b.strip_prefix(&*n_prefix).ok_or(()),
|o| o.strip_prefix(&*n_prefix).map(|x| x.to_vec()).ok_or(()),
|o| o.strip_prefix(&*n_prefix).map(ToOwned::to_owned).ok_or(()),
);
result.ok()
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct Options {
impl Options {
fn new(matches: &ArgMatches) -> Result<Self, ParseError> {
let (remaining_mode, tabstops) = match matches.get_many::<String>(options::TABS) {
Some(s) => tabstops_parse(&s.map(|s| s.as_str()).collect::<Vec<_>>().join(","))?,
Some(s) => tabstops_parse(&s.map(String::as_str).collect::<Vec<_>>().join(","))?,
None => (RemainingMode::None, vec![DEFAULT_TABSTOP]),
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn extract_files(matches: &ArgMatches) -> UResult<Vec<OsString>> {
})
.collect();

if files.as_ref().is_ok_and(|f| f.is_empty()) {
if files.as_ref().is_ok_and(Vec::is_empty) {
Ok(vec![OsString::from("-")])
} else {
files
Expand Down
4 changes: 2 additions & 2 deletions src/uu/fmt/src/parasplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Iterator for FileLines<'_> {
// not truly blank we will not allow mail headers on the
// following line)
if pmatch
&& n[poffset + self.opts.prefix.as_ref().map_or(0, |s| s.len())..]
&& n[poffset + self.opts.prefix.as_ref().map_or(0, String::len)..]
.iter()
.all(|&b| is_fmt_whitespace_byte(b))
{
Expand All @@ -304,7 +304,7 @@ impl Iterator for FileLines<'_> {
}

// figure out the indent, prefix, and prefixindent ending points
let prefix_end = poffset + self.opts.prefix.as_ref().map_or(0, |s| s.len());
let prefix_end = poffset + self.opts.prefix.as_ref().map_or(0, String::len);
let (indent_end, prefix_len, indent_len) = self.compute_indent(&n[..], prefix_end);

Some(Line::FormatLine(FileLine {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let groups = entries::get_groups_gnu(Some(gid))?;
let groups = if state.user_specified {
possible_pw.as_ref().map(|p| p.belongs_to()).unwrap()
possible_pw.as_ref().map(Passwd::belongs_to).unwrap()
} else {
groups.clone()
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/join/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ fn parse_print_settings(matches: &clap::ArgMatches) -> UResult<(bool, bool, bool
}

fn get_and_parse_field_number(matches: &clap::ArgMatches, key: &str) -> UResult<Option<usize>> {
let value = matches.get_one::<String>(key).map(|s| s.as_str());
let value = matches.get_one::<String>(key).map(String::as_str);
parse_field_number_option(value)
}

Expand Down
2 changes: 1 addition & 1 deletion src/uu/kill/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn handle_obsolete(args: &mut Vec<String>) -> Option<usize> {
let slice = args[1].as_str();
if let Some(signal) = slice.strip_prefix('-') {
// With '-', a signal name must start with an uppercase char
if signal.chars().next().is_some_and(|c| c.is_lowercase()) {
if signal.chars().next().is_some_and(char::is_lowercase) {
return None;
}
// Check if it is a valid signal
Expand Down
4 changes: 2 additions & 2 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a> StyleManager<'a> {

if target_missing {
let orphan_raw = self.indicator_codes.get(&Indicator::OrphanedSymbolicLink);
let orphan_raw_is_empty = orphan_raw.is_some_and(|value| value.is_empty());
let orphan_raw_is_empty = orphan_raw.is_some_and(String::is_empty);
if orphan_enabled && (!orphan_raw_is_empty || self.ln_color_from_target) {
return Some(Indicator::OrphanedSymbolicLink);
}
Expand Down Expand Up @@ -541,7 +541,7 @@ pub(crate) fn color_name(
}
}

if target_symlink.is_none() && path.file_type().is_some_and(|ft| ft.is_symlink()) {
if target_symlink.is_none() && path.file_type().is_some_and(fs::FileType::is_symlink) {
if let Some(colored) = style_manager.color_symlink_name(path, name.clone(), wrap) {
return colored;
}
Expand Down
16 changes: 8 additions & 8 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn parse_time_style(options: &clap::ArgMatches) -> Result<(String, Option<String

if let Some(field) = options
.get_one::<String>(options::TIME_STYLE)
.map(|s| s.to_owned())
.map(ToOwned::to_owned)
.or_else(|| std::env::var("TIME_STYLE").ok())
{
//If both FULL_TIME and TIME_STYLE are present
Expand Down Expand Up @@ -1953,7 +1953,7 @@ impl PathData {
} else {
dir_entry
.as_ref()
.map(|inner| inner.file_name())
.map(DirEntry::file_name)
.unwrap_or_default()
};

Expand Down Expand Up @@ -2048,7 +2048,7 @@ impl PathData {

fn file_type(&self) -> Option<&FileType> {
self.ft
.get_or_init(|| self.metadata().map(|md| md.file_type()))
.get_or_init(|| self.metadata().map(Metadata::file_type))
.as_ref()
}

Expand All @@ -2059,7 +2059,7 @@ impl PathData {

#[cfg(unix)]
fn is_executable_file(&self) -> bool {
self.file_type().is_some_and(|f| f.is_file())
self.file_type().is_some_and(FileType::is_file)
&& self.metadata().is_some_and(file_is_executable)
}

Expand Down Expand Up @@ -2331,7 +2331,7 @@ fn sort_entries(entries: &mut [PathData], config: &Config) {
)
}),
Sort::Size => {
entries.sort_by_key(|k| Reverse(k.metadata().map_or(0, |md| md.len())));
entries.sort_by_key(|k| Reverse(k.metadata().map_or(0, Metadata::len)));
}
// The default sort in GNU ls is case insensitive
Sort::Name => entries.sort_by(|a, b| a.display_name().cmp(b.display_name())),
Expand Down Expand Up @@ -2499,7 +2499,7 @@ fn enter_directory(
for e in entries
.iter()
.skip(if config.files == Files::All { 2 } else { 0 })
.filter(|p| p.file_type().is_some_and(|ft| ft.is_dir()))
.filter(|p| p.file_type().is_some_and(FileType::is_dir))
{
match fs::read_dir(e.path()) {
Err(err) => {
Expand Down Expand Up @@ -3376,7 +3376,7 @@ fn display_item_name(
}

if config.format == Format::Long
&& path.file_type().is_some_and(|ft| ft.is_symlink())
&& path.file_type().is_some_and(FileType::is_symlink)
&& !path.must_dereference
{
match path.path().read_link() {
Expand All @@ -3402,7 +3402,7 @@ fn display_item_name(
let target_data = PathData::new(
resolved_target,
None,
target_path.file_name().map(|s| s.to_os_string()),
target_path.file_name().map(OsStr::to_os_string),
config,
false,
);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Options {
}
Some(template) => {
let tmpdir = if env::var(TMPDIR_ENV_VAR).is_ok() && matches.get_flag(OPT_T) {
env::var_os(TMPDIR_ENV_VAR).map(|t| t.into())
env::var_os(TMPDIR_ENV_VAR).map(Into::into)
} else if tmpdir.is_some() {
tmpdir
} else if matches.get_flag(OPT_T) || matches.contains_id(OPT_TMPDIR) {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mv/benches/mv_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn mv_multiple_to_dir(bencher: Bencher) {
(temp_dir, args)
})
.bench_values(|(temp_dir, args)| {
let arg_refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
let arg_refs: Vec<&str> = args.iter().map(String::as_str).collect();
black_box(run_util_function(uumain, &arg_refs));
drop(temp_dir);
});
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mv/src/hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl HardlinkGroupScanner {
#[cfg(unix)]
pub fn stats(&self) -> ScannerStats {
let total_groups = self.hardlink_groups.len();
let total_files = self.hardlink_groups.values().map(|group| group.len()).sum();
let total_files = self.hardlink_groups.values().map(Vec::len).sum();

ScannerStats {
total_groups,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn parse_paths(files: &[OsString], opts: &Options) -> Vec<PathBuf> {
.map(|p| p.components().as_path().to_owned())
.collect::<Vec<PathBuf>>()
} else {
paths.map(|p| p.to_owned()).collect::<Vec<PathBuf>>()
paths.map(ToOwned::to_owned).collect::<Vec<PathBuf>>()
}
}

Expand Down
Loading
Loading