Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy Pedantic Acceptable Commits Try Again #6748

Merged
4 changes: 2 additions & 2 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ where
}
}
};
print!("{}", before_filename);
print!("{before_filename}");
if should_print_filename {
// The filename might not be valid UTF-8, and filename.display() would mangle the names.
// Therefore, emit the bytes directly to stdout, without any attempt at encoding them.
let _dropped_result = stdout().write_all(os_str_as_bytes(filename.as_os_str())?);
}
println!("{}", after_filename);
println!("{after_filename}");
}

Ok(())
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 @@ -42,7 +42,7 @@ struct LineReader {

impl LineReader {
fn new(input: Input, line_ending: LineEnding) -> Self {
Self { input, line_ending }
Self { line_ending, input }
}

fn read_line(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cp/src/copydir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
let source_is_dir = direntry.path().is_dir();
if path_ends_with_terminator(context.target) && source_is_dir {
if let Err(e) = std::fs::create_dir_all(context.target) {
eprintln!("Failed to create directory: {}", e);
eprintln!("Failed to create directory: {e}");

Check warning on line 178 in src/uu/cp/src/copydir.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/cp/src/copydir.rs#L178

Added line #L178 was not covered by tests
}
} else {
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
Expand Down
5 changes: 1 addition & 4 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Options {
out_delimiter,
line_ending,
field_opts: Some(FieldOptions {
only_delimited,
delimiter,
})},
field_opts: Some(FieldOptions { delimiter, only_delimited })},
)
}),
(2.., _, _, _) => Err(
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 @@ -237,7 +237,7 @@
None => {
return Err(USimpleError::new(
1,
format!("invalid date {}", relative_time),
format!("invalid date {relative_time}"),

Check warning on line 240 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L240

Added line #L240 was not covered by tests
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
None => {
let filesystems = get_all_filesystems(&opt).map_err(|e| {
let context = "cannot read table of mounted file systems";
USimpleError::new(e.code(), format!("{}: {}", context, e))
USimpleError::new(e.code(), format!("{context}: {e}"))

Check warning on line 447 in src/uu/df/src/df.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/df/src/df.rs#L447

Added line #L447 was not covered by tests
})?;

if filesystems.is_empty() {
Expand All @@ -457,7 +457,7 @@
let paths: Vec<_> = paths.collect();
let filesystems = get_named_filesystems(&paths, &opt).map_err(|e| {
let context = "cannot read table of mounted file systems";
USimpleError::new(e.code(), format!("{}: {}", context, e))
USimpleError::new(e.code(), format!("{context}: {e}"))

Check warning on line 460 in src/uu/df/src/df.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/df/src/df.rs#L460

Added line #L460 was not covered by tests
})?;

// This can happen if paths are given as command-line arguments
Expand Down
2 changes: 1 addition & 1 deletion src/uu/df/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ impl Filesystem {
#[cfg(windows)]
let usage = FsUsage::new(Path::new(&_stat_path)).ok()?;
Some(Self {
file,
mount_info,
usage,
file,
})
}

Expand Down
18 changes: 9 additions & 9 deletions src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,12 @@ mod tests {
},
usage: crate::table::FsUsage {
blocksize: 4096,
blocks: 244029695,
bfree: 125085030,
bavail: 125085030,
blocks: 244_029_695,
bfree: 125_085_030,
bavail: 125_085_030,
bavail_top_bit_set: false,
files: 999,
ffree: 1000000,
ffree: 1_000_000,
},
};

Expand All @@ -871,12 +871,12 @@ mod tests {
},
usage: crate::table::FsUsage {
blocksize: 4096,
blocks: 244029695,
bfree: 125085030,
bavail: 125085030,
blocks: 244_029_695,
bfree: 125_085_030,
bavail: 125_085_030,
bavail_top_bit_set: false,
files: 99999999999,
ffree: 999999,
files: 99_999_999_999,
ffree: 999_999,
},
};

Expand Down
17 changes: 8 additions & 9 deletions src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ pub fn generate_type_output(fmt: &OutputFmt) -> String {
match fmt {
OutputFmt::Display => FILE_TYPES
.iter()
.map(|&(_, key, val)| format!("\x1b[{}m{}\t{}\x1b[0m", val, key, val))
.map(|&(_, key, val)| format!("\x1b[{val}m{key}\t{val}\x1b[0m"))
.collect::<Vec<String>>()
.join("\n"),
_ => {
// Existing logic for other formats
FILE_TYPES
.iter()
.map(|&(_, v1, v2)| format!("{}={}", v1, v2))
.map(|&(_, v1, v2)| format!("{v1}={v2}"))
.collect::<Vec<String>>()
.join(":")
}
Expand All @@ -100,8 +100,7 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String {
display_parts.push(type_output);
for &(extension, code) in FILE_COLORS {
let prefix = if extension.starts_with('*') { "" } else { "*" };
let formatted_extension =
format!("\x1b[{}m{}{}\t{}\x1b[0m", code, prefix, extension, code);
let formatted_extension = format!("\x1b[{code}m{prefix}{extension}\t{code}\x1b[0m");
display_parts.push(formatted_extension);
}
display_parts.join("\n")
Expand All @@ -111,8 +110,8 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String {
let mut parts = vec![];
for &(extension, code) in FILE_COLORS {
let prefix = if extension.starts_with('*') { "" } else { "*" };
let formatted_extension = format!("{}{}", prefix, extension);
parts.push(format!("{}={}", formatted_extension, code));
let formatted_extension = format!("{prefix}{extension}");
parts.push(format!("{formatted_extension}={code}"));
}
let (prefix, suffix) = get_colors_format_strings(fmt);
let ls_colors = parts.join(sep);
Expand Down Expand Up @@ -493,7 +492,7 @@ pub fn generate_dircolors_config() -> String {
);
config.push_str("COLORTERM ?*\n");
for term in TERMS {
config.push_str(&format!("TERM {}\n", term));
config.push_str(&format!("TERM {term}\n"));
}

config.push_str(
Expand All @@ -514,14 +513,14 @@ pub fn generate_dircolors_config() -> String {
);

for (name, _, code) in FILE_TYPES {
config.push_str(&format!("{} {}\n", name, code));
config.push_str(&format!("{name} {code}\n"));
}

config.push_str("# List any file extensions like '.gz' or '.tar' that you would like ls\n");
config.push_str("# to color below. Put the extension, a space, and the color init string.\n");

for (ext, color) in FILE_COLORS {
config.push_str(&format!("{} {}\n", ext, color));
config.push_str(&format!("{ext} {color}\n"));
}
config.push_str("# Subsequent TERM or COLORTERM entries, can be used to add / override\n");
config.push_str("# config specific to those matching environment variables.");
Expand Down
7 changes: 2 additions & 5 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
if path.is_dir() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("{}: read error: Is a directory", file_name),
format!("{file_name}: read error: Is a directory"),
));
}

Expand All @@ -604,10 +604,7 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"cannot open '{}' for reading: No such file or directory",
file_name
),
format!("cannot open '{file_name}' for reading: No such file or directory"),
))
}
Err(e) => return Err(e),
Expand Down
10 changes: 5 additions & 5 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
let stdout_raw = io::stdout();
let mut stdout = stdout_raw.lock();
for (n, v) in env::vars() {
write!(stdout, "{}={}{}", n, v, line_ending).unwrap();
write!(stdout, "{n}={v}{line_ending}").unwrap();
}
}

Expand Down Expand Up @@ -281,15 +281,15 @@
USimpleError::new(125, "invalid backslash at end of string in -S")
}
parse_error::ParseError::InvalidSequenceBackslashXInMinusS { pos: _, c } => {
USimpleError::new(125, format!("invalid sequence '\\{}' in -S", c))
USimpleError::new(125, format!("invalid sequence '\\{c}' in -S"))
}
parse_error::ParseError::MissingClosingQuote { pos: _, c: _ } => {
USimpleError::new(125, "no terminating quote in -S string")
}
parse_error::ParseError::ParsingOfVariableNameFailed { pos, msg } => {
USimpleError::new(125, format!("variable name issue (at {}): {}", pos, msg,))
USimpleError::new(125, format!("variable name issue (at {pos}): {msg}",))
}
_ => USimpleError::new(125, format!("Error: {:?}", e)),
_ => USimpleError::new(125, format!("Error: {e:?}")),

Check warning on line 292 in src/uu/env/src/env.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/env/src/env.rs#L292

Added line #L292 was not covered by tests
})
}

Expand Down Expand Up @@ -393,7 +393,7 @@
| clap::error::ErrorKind::DisplayVersion => e.into(),
_ => {
// extent any real issue with parameter parsing by the ERROR_MSG_S_SHEBANG
let s = format!("{}", e);
let s = format!("{e}");
if !s.is_empty() {
let s = s.trim_end();
uucore::show_error!("{}", s);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/env/src/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(format!("{:?}", self).as_str())
f.write_str(format!("{self:?}").as_str())

Check warning on line 42 in src/uu/env/src/parse_error.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/env/src/parse_error.rs#L42

Added line #L42 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/env/src/variable_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a, 'b> VariableParser<'a, 'b> {
if c.is_ascii_digit() {
return Err(ParseError::ParsingOfVariableNameFailed {
pos: self.parser.get_peek_position(),
msg: format!("Unexpected character: '{}', expected variable name must not start with 0..9", c) });
msg: format!("Unexpected character: '{c}', expected variable name must not start with 0..9") });
}
}
Ok(())
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'a, 'b> VariableParser<'a, 'b> {
Some(c) => {
return Err(ParseError::ParsingOfVariableNameFailed {
pos: self.parser.get_peek_position(),
msg: format!("Unexpected character: '{}', expected a closing brace ('}}') or colon (':')", c)
msg: format!("Unexpected character: '{c}', expected a closing brace ('}}') or colon (':')")
})
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl StringOp {
Self::Match => {
let left = left.eval()?.eval_as_string();
let right = right.eval()?.eval_as_string();
let re_string = format!("^{}", right);
let re_string = format!("^{right}");
let re = Regex::with_options(
&re_string,
RegexOptions::REGEX_OPTION_NONE,
Expand Down
6 changes: 3 additions & 3 deletions src/uu/factor/src/factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ fn write_result(
for (factor, n) in factorization {
if print_exponents {
if n > 1 {
write!(w, " {}^{}", factor, n)?;
write!(w, " {factor}^{n}")?;
} else {
write!(w, " {}", factor)?;
write!(w, " {factor}")?;
}
} else {
w.write_all(format!(" {}", factor).repeat(n).as_bytes())?;
w.write_all(format!(" {factor}").repeat(n).as_bytes())?;
}
}
writeln!(w)?;
Expand Down
8 changes: 4 additions & 4 deletions src/uu/fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl FmtOptions {
if width > MAX_WIDTH {
return Err(USimpleError::new(
1,
format!("invalid width: '{}': Numerical result out of range", width),
format!("invalid width: '{width}': Numerical result out of range"),
));
}

Expand All @@ -154,13 +154,13 @@ impl FmtOptions {
crown,
tagged,
mail,
uniform,
quick,
split_only,
prefix,
xprefix,
anti_prefix,
xanti_prefix,
uniform,
quick,
width,
goal,
tabwidth,
Expand Down Expand Up @@ -241,7 +241,7 @@ fn extract_files(matches: &ArgMatches) -> UResult<Vec<String>> {
} else {
let first_num = x.chars().nth(1).expect("a negative number should be at least two characters long");
Some(Err(
UUsageError::new(1, format!("invalid option -- {}; -WIDTH is recognized only when it is the first\noption; use -w N instead", first_num))
UUsageError::new(1, format!("invalid option -- {first_num}; -WIDTH is recognized only when it is the first\noption; use -w N instead"))
))
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult<HashAlgorithm> {
set_or_err(detect_algo("b3sum", None)?)?;
}
if matches.get_flag("sha3") {
let bits = matches.get_one::<usize>("bits").cloned();
let bits = matches.get_one::<usize>("bits").copied();
set_or_err(create_sha3(bits)?)?;
}
if matches.get_flag("sha3-224") {
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 @@ -158,7 +158,7 @@ fn table() {
.enumerate()
.filter(|(_, s)| **s != "EXIT")
{
println!("{0: >#2} {1}", idx, signal);
println!("{idx: >#2} {signal}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/ls/src/dired.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ pub fn print_dired_output(

/// Helper function to print positions with a given prefix.
fn print_positions(prefix: &str, positions: &Vec<BytePosition>) {
print!("{}", prefix);
print!("{prefix}");
for c in positions {
print!(" {}", c);
print!(" {c}");
}
println!();
}
Expand Down
Loading
Loading