1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

fix clippy warning

This commit is contained in:
Jan Scheer 2021-05-29 00:46:25 +02:00
parent bb268d1500
commit a2947f6897
10 changed files with 36 additions and 31 deletions

View file

@ -136,7 +136,7 @@ fn basename(fullname: &str, suffix: &str) -> String {
} }
} }
#[allow(clippy::manual_strip)] // can be replaced with strip_suffix once the minimum rust version is 1.45 // can be replaced with strip_suffix once the minimum rust version is 1.45
fn strip_suffix(name: &str, suffix: &str) -> String { fn strip_suffix(name: &str, suffix: &str) -> String {
if name == suffix { if name == suffix {
return name.to_owned(); return name.to_owned();

View file

@ -669,8 +669,8 @@ impl Options {
} }
}, },
backup: backup_mode, backup: backup_mode,
backup_suffix: backup_suffix, backup_suffix,
overwrite: overwrite, overwrite,
no_target_dir, no_target_dir,
preserve_attributes, preserve_attributes,
recursive, recursive,
@ -1089,7 +1089,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
} }
#[cfg(not(windows))] #[cfg(not(windows))]
#[allow(clippy::unnecessary_wraps)] // needed for windows version #[allow(clippy::unnecessary_unwrap)] // needed for windows version
fn symlink_file(source: &Path, dest: &Path, context: &str) -> CopyResult<()> { fn symlink_file(source: &Path, dest: &Path, context: &str) -> CopyResult<()> {
match std::os::unix::fs::symlink(source, dest).context(context) { match std::os::unix::fs::symlink(source, dest).context(context) {
Ok(_) => Ok(()), Ok(_) => Ok(()),

View file

@ -483,10 +483,11 @@ where
/// Shrink the buffer so that its length is equal to the set size, returning an iterator for /// Shrink the buffer so that its length is equal to the set size, returning an iterator for
/// the elements that were too much. /// the elements that were too much.
fn shrink_buffer_to_size(&mut self) -> impl Iterator<Item = String> + '_ { fn shrink_buffer_to_size(&mut self) -> impl Iterator<Item = String> + '_ {
let mut shrink_offset = 0; let shrink_offset = if self.buffer.len() > self.size {
if self.buffer.len() > self.size { self.buffer.len() - self.size
shrink_offset = self.buffer.len() - self.size; } else {
} 0
};
self.buffer self.buffer
.drain(..shrink_offset) .drain(..shrink_offset)
.map(|(_, line)| line.unwrap()) .map(|(_, line)| line.unwrap())

View file

@ -1614,7 +1614,7 @@ fn display_date(metadata: &Metadata, config: &Config) -> String {
Some(time) => { Some(time) => {
//Date is recent if from past 6 months //Date is recent if from past 6 months
//According to GNU a Gregorian year has 365.2425 * 24 * 60 * 60 == 31556952 seconds on the average. //According to GNU a Gregorian year has 365.2425 * 24 * 60 * 60 == 31556952 seconds on the average.
let recent = time + chrono::Duration::seconds(31556952 / 2) > chrono::Local::now(); let recent = time + chrono::Duration::seconds(31_556_952 / 2) > chrono::Local::now();
match config.time_style { match config.time_style {
TimeStyle::FullIso => time.format("%Y-%m-%d %H:%M:%S.%f %z"), TimeStyle::FullIso => time.format("%Y-%m-%d %H:%M:%S.%f %z"),
@ -1696,7 +1696,6 @@ fn file_is_executable(md: &Metadata) -> bool {
md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0 md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0
} }
#[allow(clippy::clippy::collapsible_else_if)]
fn classify_file(path: &PathData) -> Option<char> { fn classify_file(path: &PathData) -> Option<char> {
let file_type = path.file_type()?; let file_type = path.file_type()?;

View file

@ -76,7 +76,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
input_strings.push("-"); input_strings.push("-");
} }
Ok(CommandLineInputs::FileNames( Ok(CommandLineInputs::FileNames(
input_strings.iter().map(|s| s.to_string()).collect(), input_strings.iter().map(|&s| s.to_string()).collect(),
)) ))
} }
@ -92,7 +92,7 @@ pub fn parse_inputs_traditional(input_strings: Vec<&str>) -> Result<CommandLineI
Ok(match offset0 { Ok(match offset0 {
Ok(n) => CommandLineInputs::FileAndOffset(("-".to_string(), n, None)), Ok(n) => CommandLineInputs::FileAndOffset(("-".to_string(), n, None)),
_ => CommandLineInputs::FileNames( _ => CommandLineInputs::FileNames(
input_strings.iter().map(|s| s.to_string()).collect(), input_strings.iter().map(|&s| s.to_string()).collect(),
), ),
}) })
} }
@ -179,7 +179,7 @@ mod tests {
impl<'a> MockOptions<'a> { impl<'a> MockOptions<'a> {
fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> { fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> {
MockOptions { MockOptions {
inputs: inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>(), inputs: inputs.iter().map(|&s| s.to_string()).collect::<Vec<_>>(),
option_names, option_names,
} }
} }

View file

@ -50,10 +50,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();
let mut separator = "\n"; let separator = if matches.is_present(OPT_NULL) {
if matches.is_present(OPT_NULL) { "\x00"
separator = "\x00"; } else {
} "\n"
};
if variables.is_empty() { if variables.is_empty() {
for (env_var, value) in env::vars() { for (env_var, value) in env::vars() {

View file

@ -108,10 +108,13 @@ impl WordFilter {
// Ignore empty string regex from cmd-line-args // Ignore empty string regex from cmd-line-args
let arg_reg: Option<String> = if matches.is_present(options::WORD_REGEXP) { let arg_reg: Option<String> = if matches.is_present(options::WORD_REGEXP) {
match matches.value_of(options::WORD_REGEXP) { match matches.value_of(options::WORD_REGEXP) {
Some(v) => match v.is_empty() { Some(v) => {
true => None, if v.is_empty() {
false => Some(v.to_string()), None
}, } else {
Some(v.to_string())
}
}
None => None, None => None,
} }
} else { } else {

View file

@ -296,10 +296,10 @@ impl<'a> Line<'a> {
fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) { fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) {
if settings.zero_terminated && !settings.debug { if settings.zero_terminated && !settings.debug {
crash_if_err!(1, writer.write_all(self.line.as_bytes())); crash_if_err!(1, writer.write_all(self.line.as_bytes()));
crash_if_err!(1, writer.write_all("\0".as_bytes())); crash_if_err!(1, writer.write_all(b"\0"));
} else if !settings.debug { } else if !settings.debug {
crash_if_err!(1, writer.write_all(self.line.as_bytes())); crash_if_err!(1, writer.write_all(self.line.as_bytes()));
crash_if_err!(1, writer.write_all("\n".as_bytes())); crash_if_err!(1, writer.write_all(b"\n"));
} else { } else {
crash_if_err!(1, self.print_debug(settings, writer)); crash_if_err!(1, self.print_debug(settings, writer));
} }
@ -1437,7 +1437,7 @@ mod tests {
fn test_get_hash() { fn test_get_hash() {
let a = "Ted".to_string(); let a = "Ted".to_string();
assert_eq!(2646829031758483623, get_hash(&a)); assert_eq!(2_646_829_031_758_483_623, get_hash(&a));
} }
#[test] #[test]

View file

@ -146,15 +146,16 @@ pub trait Args: Iterator<Item = OsString> + Sized {
InvalidEncodingHandling::Ignore => s.is_ok(), InvalidEncodingHandling::Ignore => s.is_ok(),
_ => true, _ => true,
}) })
.map(|s| match s.is_ok() { .map(|s| match s {
true => s.unwrap(), Ok(v) => v,
false => s.unwrap_err(), Err(e) => e,
}) })
.collect(); .collect();
match full_conversion { if full_conversion {
true => ConversionResult::Complete(result_vector), ConversionResult::Complete(result_vector)
false => ConversionResult::Lossy(result_vector), } else {
ConversionResult::Lossy(result_vector)
} }
} }

View file

@ -33,7 +33,7 @@ pub fn determine_backup_suffix(supplied_suffix: Option<&str>) -> String {
if let Some(suffix) = supplied_suffix { if let Some(suffix) = supplied_suffix {
String::from(suffix) String::from(suffix)
} else { } else {
env::var("SIMPLE_BACKUP_SUFFIX").unwrap_or("~".to_owned()) env::var("SIMPLE_BACKUP_SUFFIX").unwrap_or_else(|_| "~".to_owned())
} }
} }