mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
remove needless borrows
This commit is contained in:
parent
57dc11e586
commit
5af66753af
7 changed files with 22 additions and 22 deletions
|
@ -64,7 +64,7 @@ fn main() {
|
|||
// * prefix/stem may be any string ending in a non-alphanumeric character
|
||||
let util_name = if let Some(util) = utils.keys().find(|util| {
|
||||
binary_as_util.ends_with(*util)
|
||||
&& !(&binary_as_util[..binary_as_util.len() - (*util).len()])
|
||||
&& !binary_as_util[..binary_as_util.len() - (*util).len()]
|
||||
.ends_with(char::is_alphanumeric)
|
||||
}) {
|
||||
// prefixed util => replace 0th (aka, executable name) argument
|
||||
|
|
|
@ -479,7 +479,7 @@ fn write_lines<R: FdReadable>(
|
|||
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
|
||||
state.one_blank_kept = true;
|
||||
if state.at_line_start && options.number == NumberingMode::All {
|
||||
write!(&mut writer, "{0:6}\t", state.line_number)?;
|
||||
write!(writer, "{0:6}\t", state.line_number)?;
|
||||
state.line_number += 1;
|
||||
}
|
||||
writer.write_all(options.end_of_line().as_bytes())?;
|
||||
|
@ -498,7 +498,7 @@ fn write_lines<R: FdReadable>(
|
|||
}
|
||||
state.one_blank_kept = false;
|
||||
if state.at_line_start && options.number != NumberingMode::None {
|
||||
write!(&mut writer, "{0:6}\t", state.line_number)?;
|
||||
write!(writer, "{0:6}\t", state.line_number)?;
|
||||
state.line_number += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,10 +64,10 @@ impl Error {
|
|||
|
||||
pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String {
|
||||
let mut desc = String::with_capacity(256);
|
||||
write!(&mut desc, "{}", err).unwrap();
|
||||
write!(desc, "{}", err).unwrap();
|
||||
while let Some(source) = err.source() {
|
||||
err = source;
|
||||
write!(&mut desc, ". {}", err).unwrap();
|
||||
write!(desc, ". {}", err).unwrap();
|
||||
}
|
||||
desc
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Sieve {
|
|||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn odd_primes() -> PrimeSieve {
|
||||
(&INIT_PRIMES[1..]).iter().copied().chain(Sieve::new())
|
||||
INIT_PRIMES[1..].iter().copied().chain(Sieve::new())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ fn check_basic(path: &[String]) -> bool {
|
|||
// path length
|
||||
if total_len > POSIX_PATH_MAX {
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"limit {} exceeded by length {} of file name {}",
|
||||
POSIX_PATH_MAX,
|
||||
total_len,
|
||||
|
@ -140,7 +140,7 @@ fn check_basic(path: &[String]) -> bool {
|
|||
);
|
||||
return false;
|
||||
} else if total_len == 0 {
|
||||
writeln!(&mut std::io::stderr(), "empty file name");
|
||||
writeln!(std::io::stderr(), "empty file name");
|
||||
return false;
|
||||
}
|
||||
// components: character portability and length
|
||||
|
@ -148,7 +148,7 @@ fn check_basic(path: &[String]) -> bool {
|
|||
let component_len = p.len();
|
||||
if component_len > POSIX_NAME_MAX {
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"limit {} exceeded by length {} of file name component {}",
|
||||
POSIX_NAME_MAX,
|
||||
component_len,
|
||||
|
@ -170,7 +170,7 @@ fn check_extra(path: &[String]) -> bool {
|
|||
for p in path {
|
||||
if p.starts_with('-') {
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"leading hyphen in file name component {}",
|
||||
p.quote()
|
||||
);
|
||||
|
@ -179,7 +179,7 @@ fn check_extra(path: &[String]) -> bool {
|
|||
}
|
||||
// path length
|
||||
if path.join("/").is_empty() {
|
||||
writeln!(&mut std::io::stderr(), "empty file name");
|
||||
writeln!(std::io::stderr(), "empty file name");
|
||||
return false;
|
||||
}
|
||||
true
|
||||
|
@ -192,7 +192,7 @@ fn check_default(path: &[String]) -> bool {
|
|||
// path length
|
||||
if total_len > libc::PATH_MAX as usize {
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"limit {} exceeded by length {} of file name {}",
|
||||
libc::PATH_MAX,
|
||||
total_len,
|
||||
|
@ -205,7 +205,7 @@ fn check_default(path: &[String]) -> bool {
|
|||
let component_len = p.len();
|
||||
if component_len > libc::FILENAME_MAX as usize {
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"limit {} exceeded by length {} of file name component {}",
|
||||
libc::FILENAME_MAX,
|
||||
component_len,
|
||||
|
@ -227,7 +227,7 @@ fn check_searchable(path: &str) -> bool {
|
|||
if e.kind() == ErrorKind::NotFound {
|
||||
true
|
||||
} else {
|
||||
writeln!(&mut std::io::stderr(), "{}", e);
|
||||
writeln!(std::io::stderr(), "{}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ fn check_portable_chars(path_segment: &str) -> bool {
|
|||
if !VALID_CHARS.contains(ch) {
|
||||
let invalid = path_segment[i..].chars().next().unwrap();
|
||||
writeln!(
|
||||
&mut std::io::stderr(),
|
||||
std::io::stderr(),
|
||||
"nonportable character '{}' in file name component {}",
|
||||
invalid,
|
||||
path_segment.quote()
|
||||
|
|
|
@ -186,7 +186,7 @@ fn round_terminal_digit(
|
|||
if position < after_dec.len() {
|
||||
let digit_at_pos: char;
|
||||
{
|
||||
digit_at_pos = (&after_dec[position..=position]).chars().next().expect("");
|
||||
digit_at_pos = after_dec[position..=position].chars().next().expect("");
|
||||
}
|
||||
if let '5'..='9' = digit_at_pos {
|
||||
let (new_after_dec, finished_in_dec) = _round_str_from(&after_dec, position);
|
||||
|
|
|
@ -205,13 +205,13 @@ fn test_single_big_args() {
|
|||
|
||||
let mut big_input = at.make_file(FILE);
|
||||
for i in 0..LINES {
|
||||
writeln!(&mut big_input, "Line {}", i).expect("Could not write to FILE");
|
||||
writeln!(big_input, "Line {}", i).expect("Could not write to FILE");
|
||||
}
|
||||
big_input.flush().expect("Could not flush FILE");
|
||||
|
||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||
for i in (LINES - N_ARG)..LINES {
|
||||
writeln!(&mut big_expected, "Line {}", i).expect("Could not write to EXPECTED_FILE");
|
||||
writeln!(big_expected, "Line {}", i).expect("Could not write to EXPECTED_FILE");
|
||||
}
|
||||
big_expected.flush().expect("Could not flush EXPECTED_FILE");
|
||||
|
||||
|
@ -254,14 +254,14 @@ fn test_bytes_big() {
|
|||
let mut big_input = at.make_file(FILE);
|
||||
for i in 0..BYTES {
|
||||
let digit = from_digit((i % 10) as u32, 10).unwrap();
|
||||
write!(&mut big_input, "{}", digit).expect("Could not write to FILE");
|
||||
write!(big_input, "{}", digit).expect("Could not write to FILE");
|
||||
}
|
||||
big_input.flush().expect("Could not flush FILE");
|
||||
|
||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||
for i in (BYTES - N_ARG)..BYTES {
|
||||
let digit = from_digit((i % 10) as u32, 10).unwrap();
|
||||
write!(&mut big_expected, "{}", digit).expect("Could not write to EXPECTED_FILE");
|
||||
write!(big_expected, "{}", digit).expect("Could not write to EXPECTED_FILE");
|
||||
}
|
||||
big_expected.flush().expect("Could not flush EXPECTED_FILE");
|
||||
|
||||
|
@ -290,13 +290,13 @@ fn test_lines_with_size_suffix() {
|
|||
|
||||
let mut big_input = at.make_file(FILE);
|
||||
for i in 0..LINES {
|
||||
writeln!(&mut big_input, "Line {}", i).expect("Could not write to FILE");
|
||||
writeln!(big_input, "Line {}", i).expect("Could not write to FILE");
|
||||
}
|
||||
big_input.flush().expect("Could not flush FILE");
|
||||
|
||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||
for i in (LINES - N_ARG)..LINES {
|
||||
writeln!(&mut big_expected, "Line {}", i).expect("Could not write to EXPECTED_FILE");
|
||||
writeln!(big_expected, "Line {}", i).expect("Could not write to EXPECTED_FILE");
|
||||
}
|
||||
big_expected.flush().expect("Could not flush EXPECTED_FILE");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue