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
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
run: |
## `cargo clippy` lint testing
unset fault
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity"
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone"
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
Expand Down
2 changes: 1 addition & 1 deletion src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Config {
format!("{}: No such file or directory", name.maybe_quote()),
));
}
Some(name.to_owned())
Some(name.clone())
}
}
None => None,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let squeeze_blank = matches.get_flag(options::SQUEEZE_BLANK);
let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => vec!["-".to_owned()],
};

Expand Down
12 changes: 3 additions & 9 deletions src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,9 @@ impl CsplitOptions {
split_name: crash_if_err!(
1,
SplitName::new(
matches
.get_one::<String>(options::PREFIX)
.map(|s| s.to_owned()),
matches
.get_one::<String>(options::SUFFIX_FORMAT)
.map(|s| s.to_owned()),
matches
.get_one::<String>(options::DIGITS)
.map(|s| s.to_owned())
matches.get_one::<String>(options::PREFIX).cloned(),
matches.get_one::<String>(options::SUFFIX_FORMAT).cloned(),
matches.get_one::<String>(options::DIGITS).cloned()
)
),
keep_files,
Expand Down
4 changes: 2 additions & 2 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if s.is_empty() {
Some("\0".to_owned())
} else {
Some(s.to_owned())
Some(s.clone())
}
}
None => None,
Expand Down Expand Up @@ -491,7 +491,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let files: Vec<String> = matches
.get_many::<String>(options::FILE)
.unwrap_or_default()
.map(|s| s.to_owned())
.cloned()
.collect();

match mode_parse {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dirname/src/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let dirnames: Vec<String> = matches
.get_many::<String>(options::DIR)
.unwrap_or_default()
.map(|s| s.to_owned())
.cloned()
.collect();

if dirnames.is_empty() {
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 @@ -506,7 +506,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
let excludes_iterator = matches
.get_many::<String>(options::EXCLUDE)
.unwrap_or_default()
.map(|v| v.to_owned());
.cloned();

let mut exclude_patterns = Vec::new();
for f in excludes_iterator.chain(exclude_from_iterator) {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let bytes = matches.get_flag(options::BYTES);
let spaces = matches.get_flag(options::SPACES);
let poss_width = match matches.get_one::<String>(options::WIDTH) {
Some(v) => Some(v.to_owned()),
Some(v) => Some(v.clone()),
None => obs_width,
};

Expand All @@ -50,7 +50,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

let files = match matches.get_many::<String>(options::FILE) {
Some(v) => v.map(|v| v.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => vec!["-".to_owned()],
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl HeadOptions {
options.mode = Mode::from(matches)?;

options.files = match matches.get_many::<String>(options::FILES_NAME) {
Some(v) => v.map(|s| s.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => vec!["-".to_owned()],
};
//println!("{:#?}", options);
Expand Down
17 changes: 6 additions & 11 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
};

let backup_mode = backup_control::determine_backup_mode(matches)?;
let target_dir = matches
.get_one::<String>(OPT_TARGET_DIRECTORY)
.map(|d| d.to_owned());
let target_dir = matches.get_one::<String>(OPT_TARGET_DIRECTORY).cloned();

let preserve_timestamps = matches.get_flag(OPT_PRESERVE_TIMESTAMPS);
let compare = matches.get_flag(OPT_COMPARE);
Expand Down Expand Up @@ -593,7 +591,7 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
let source = sources.first().unwrap();

if source.is_dir() {
return Err(InstallError::OmittingDirectory(source.to_path_buf()).into());
return Err(InstallError::OmittingDirectory(source.clone()).into());
}

if target.is_file() || is_new_file_path(&target) {
Expand Down Expand Up @@ -628,7 +626,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
}

if sourcepath.is_dir() {
let err = InstallError::OmittingDirectory(sourcepath.to_path_buf());
let err = InstallError::OmittingDirectory(sourcepath.clone());
show!(err);
continue;
}
Expand Down Expand Up @@ -701,12 +699,9 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult<Option<PathBuf>> {
if let Some(ref backup_path) = backup_path {
// TODO!!
if let Err(err) = fs::rename(to, backup_path) {
return Err(InstallError::BackupFailed(
to.to_path_buf(),
backup_path.to_path_buf(),
err,
)
.into());
return Err(
InstallError::BackupFailed(to.to_path_buf(), backup_path.clone(), err).into(),
);
}
}
Ok(backup_path)
Expand Down
18 changes: 5 additions & 13 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,7 @@ fn extract_color(options: &clap::ArgMatches) -> bool {
///
/// A QuotingStyle variant representing the quoting style to use.
fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> QuotingStyle {
let opt_quoting_style = options
.get_one::<String>(options::QUOTING_STYLE)
.map(|cmd_line_qs| cmd_line_qs.to_owned());
let opt_quoting_style = options.get_one::<String>(options::QUOTING_STYLE).cloned();

if let Some(style) = opt_quoting_style {
match style.as_str() {
Expand Down Expand Up @@ -788,9 +786,7 @@ impl Config {
match parse_size_u64(&raw_bs.to_string_lossy()) {
Ok(size) => Some(size),
Err(_) => {
show!(LsError::BlockSizeParseError(
cmd_line_bs.unwrap().to_owned()
));
show!(LsError::BlockSizeParseError(cmd_line_bs.unwrap().clone()));
None
}
}
Expand Down Expand Up @@ -3056,7 +3052,7 @@ fn display_file_name(
target_data.must_dereference,
) {
Ok(md) => md,
Err(_) => path.md(out).unwrap().to_owned(),
Err(_) => path.md(out).unwrap().clone(),
};

name.push_str(&color_name(
Expand All @@ -3073,11 +3069,7 @@ fn display_file_name(
}
}
Err(err) => {
show!(LsError::IOErrorContext(
err,
path.p_buf.to_path_buf(),
false
));
show!(LsError::IOErrorContext(err, path.p_buf.clone(), false));
}
}
}
Expand All @@ -3087,7 +3079,7 @@ fn display_file_name(
if config.context {
if let Some(pad_count) = prefix_context {
let security_context = if matches!(config.format, Format::Commas) {
path.security_context.to_owned()
path.security_context.clone()
} else {
pad_left(&path.security_context, pad_count)
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mkfifo/src/mkfifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

let fifos: Vec<String> = match matches.get_many::<String>(options::FIFO) {
Some(v) => v.clone().map(|s| s.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => return Err(USimpleError::new(1, "missing operand")),
};

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 @@ -146,7 +146,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let files: Vec<OsString> = matches
.get_many::<OsString>(ARG_FILES)
.unwrap_or_default()
.map(|v| v.to_os_string())
.cloned()
.collect();

let overwrite_mode = determine_overwrite_mode(&matches);
Expand Down
4 changes: 2 additions & 2 deletions src/uu/nl/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
settings.section_delimiter = if delimiter.len() == 1 {
format!("{delimiter}:")
} else {
delimiter.to_owned()
delimiter.clone()
};
}
if let Some(val) = opts.get_one::<String>(options::NUMBER_SEPARATOR) {
settings.number_separator = val.to_owned();
settings.number_separator = val.clone();
}
settings.number_format = opts
.get_one::<String>(options::NUMBER_FORMAT)
Expand Down
2 changes: 1 addition & 1 deletion src/uu/nl/src/nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => vec!["-".to_owned()],
};

Expand Down
4 changes: 1 addition & 3 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
_ => unreachable!("Should be restricted by clap"),
};

let suffix = args
.get_one::<String>(options::SUFFIX)
.map(|s| s.to_owned());
let suffix = args.get_one::<String>(options::SUFFIX).cloned();

let invalid =
InvalidModes::from_str(args.get_one::<String>(options::INVALID).unwrap()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/uu/paste/src/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let files = matches
.get_many::<String>(options::FILE)
.unwrap()
.map(|s| s.to_owned())
.cloned()
.collect();
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED));

Expand Down
2 changes: 1 addition & 1 deletion src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

let mut input_files: Vec<String> = match &matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),
Some(v) => v.clone().cloned().collect(),
None => vec!["-".to_string()],
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/shuf/src/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let headcounts = matches
.get_many::<String>(options::HEAD_COUNT)
.unwrap_or_default()
.map(|s| s.to_owned())
.cloned()
.collect();
match parse_head_count(headcounts) {
Ok(val) => val,
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sort/src/numeric_str_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ mod tests {
let (a_info, a_range) = NumInfo::parse(a, &NumInfoParseSettings::default());
let (b_info, b_range) = NumInfo::parse(b, &NumInfoParseSettings::default());
let ordering = numeric_str_cmp(
(&a[a_range.to_owned()], &a_info),
(&b[b_range.to_owned()], &b_info),
(&a[a_range.clone()], &a_info),
(&b[b_range.clone()], &b_info),
);
assert_eq!(ordering, expected);
let ordering = numeric_str_cmp((&b[b_range], &b_info), (&a[a_range], &a_info));
Expand Down
6 changes: 3 additions & 3 deletions src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,10 @@ impl Settings {
};

let result = Self {
prefix: matches.get_one::<String>(ARG_PREFIX).unwrap().to_owned(),
prefix: matches.get_one::<String>(ARG_PREFIX).unwrap().clone(),
suffix,
input: matches.get_one::<String>(ARG_INPUT).unwrap().to_owned(),
filter: matches.get_one::<String>(OPT_FILTER).map(|s| s.to_owned()),
input: matches.get_one::<String>(ARG_INPUT).unwrap().clone(),
filter: matches.get_one::<String>(OPT_FILTER).cloned(),
strategy,
verbose: matches.value_source(OPT_VERBOSE) == Some(ValueSource::CommandLine),
separator,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sum/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(),
Some(v) => v.cloned().collect(),
None => vec!["-".to_owned()],
};

Expand Down
2 changes: 1 addition & 1 deletion src/uu/tail/src/follow/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl FileHandling {
pub fn insert(&mut self, k: &Path, v: PathData, update_last: bool) {
let k = Self::canonicalize_path(k);
if update_last {
self.last = Some(k.to_owned());
self.last = Some(k.clone());
}
let _ = self.map.insert(k, v);
}
Expand Down
10 changes: 5 additions & 5 deletions src/uu/tail/src/follow/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Observer {
if !path.is_file() {
continue;
}
let mut path = path.to_owned();
let mut path = path.clone();
if path.is_relative() {
path = std::env::current_dir()?.join(path);
}
Expand Down Expand Up @@ -345,7 +345,7 @@ impl Observer {
show_error!("{}: file truncated", display_name);
self.files.update_reader(event_path)?;
}
paths.push(event_path.to_owned());
paths.push(event_path.clone());
} else if !is_tailable && old_md.is_tailable() {
if pd.reader.is_some() {
self.files.reset_reader(event_path);
Expand All @@ -359,7 +359,7 @@ impl Observer {
} else if is_tailable {
show_error!( "{} has appeared; following new file", display_name.quote());
self.files.update_reader(event_path)?;
paths.push(event_path.to_owned());
paths.push(event_path.clone());
} else if settings.retry {
if self.follow_descriptor() {
show_error!(
Expand Down Expand Up @@ -403,7 +403,7 @@ impl Observer {
"{} cannot be used, reverting to polling",
text::BACKEND
);
self.orphans.push(event_path.to_owned());
self.orphans.push(event_path.clone());
let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path);
}
} else {
Expand Down Expand Up @@ -451,7 +451,7 @@ impl Observer {

if self.follow_descriptor() {
let new_path = event.paths.last().unwrap();
paths.push(new_path.to_owned());
paths.push(new_path.clone());

let new_data = PathData::from_other_with_path(self.files.remove(event_path), new_path);
self.files.insert(
Expand Down
2 changes: 1 addition & 1 deletion src/uu/test/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Parser {
/// The stream is unchanged and will return the same Symbol on subsequent
/// calls to `next()` or `peek()`.
fn peek(&mut self) -> Symbol {
Symbol::new(self.tokens.peek().map(|s| s.to_os_string()))
Symbol::new(self.tokens.peek().cloned())
}

/// Test if the next token in the stream is a BOOLOP (-a or -o), without
Expand Down