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
|
// * prefix/stem may be any string ending in a non-alphanumeric character
|
||||||
let util_name = if let Some(util) = utils.keys().find(|util| {
|
let util_name = if let Some(util) = utils.keys().find(|util| {
|
||||||
binary_as_util.ends_with(*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)
|
.ends_with(char::is_alphanumeric)
|
||||||
}) {
|
}) {
|
||||||
// prefixed util => replace 0th (aka, executable name) argument
|
// 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 {
|
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
|
||||||
state.one_blank_kept = true;
|
state.one_blank_kept = true;
|
||||||
if state.at_line_start && options.number == NumberingMode::All {
|
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;
|
state.line_number += 1;
|
||||||
}
|
}
|
||||||
writer.write_all(options.end_of_line().as_bytes())?;
|
writer.write_all(options.end_of_line().as_bytes())?;
|
||||||
|
@ -498,7 +498,7 @@ fn write_lines<R: FdReadable>(
|
||||||
}
|
}
|
||||||
state.one_blank_kept = false;
|
state.one_blank_kept = false;
|
||||||
if state.at_line_start && options.number != NumberingMode::None {
|
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;
|
state.line_number += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,10 @@ impl Error {
|
||||||
|
|
||||||
pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String {
|
pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String {
|
||||||
let mut desc = String::with_capacity(256);
|
let mut desc = String::with_capacity(256);
|
||||||
write!(&mut desc, "{}", err).unwrap();
|
write!(desc, "{}", err).unwrap();
|
||||||
while let Some(source) = err.source() {
|
while let Some(source) = err.source() {
|
||||||
err = source;
|
err = source;
|
||||||
write!(&mut desc, ". {}", err).unwrap();
|
write!(desc, ". {}", err).unwrap();
|
||||||
}
|
}
|
||||||
desc
|
desc
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl Sieve {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn odd_primes() -> PrimeSieve {
|
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
|
// path length
|
||||||
if total_len > POSIX_PATH_MAX {
|
if total_len > POSIX_PATH_MAX {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"limit {} exceeded by length {} of file name {}",
|
"limit {} exceeded by length {} of file name {}",
|
||||||
POSIX_PATH_MAX,
|
POSIX_PATH_MAX,
|
||||||
total_len,
|
total_len,
|
||||||
|
@ -140,7 +140,7 @@ fn check_basic(path: &[String]) -> bool {
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
} else if total_len == 0 {
|
} else if total_len == 0 {
|
||||||
writeln!(&mut std::io::stderr(), "empty file name");
|
writeln!(std::io::stderr(), "empty file name");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// components: character portability and length
|
// components: character portability and length
|
||||||
|
@ -148,7 +148,7 @@ fn check_basic(path: &[String]) -> bool {
|
||||||
let component_len = p.len();
|
let component_len = p.len();
|
||||||
if component_len > POSIX_NAME_MAX {
|
if component_len > POSIX_NAME_MAX {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"limit {} exceeded by length {} of file name component {}",
|
"limit {} exceeded by length {} of file name component {}",
|
||||||
POSIX_NAME_MAX,
|
POSIX_NAME_MAX,
|
||||||
component_len,
|
component_len,
|
||||||
|
@ -170,7 +170,7 @@ fn check_extra(path: &[String]) -> bool {
|
||||||
for p in path {
|
for p in path {
|
||||||
if p.starts_with('-') {
|
if p.starts_with('-') {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"leading hyphen in file name component {}",
|
"leading hyphen in file name component {}",
|
||||||
p.quote()
|
p.quote()
|
||||||
);
|
);
|
||||||
|
@ -179,7 +179,7 @@ fn check_extra(path: &[String]) -> bool {
|
||||||
}
|
}
|
||||||
// path length
|
// path length
|
||||||
if path.join("/").is_empty() {
|
if path.join("/").is_empty() {
|
||||||
writeln!(&mut std::io::stderr(), "empty file name");
|
writeln!(std::io::stderr(), "empty file name");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -192,7 +192,7 @@ fn check_default(path: &[String]) -> bool {
|
||||||
// path length
|
// path length
|
||||||
if total_len > libc::PATH_MAX as usize {
|
if total_len > libc::PATH_MAX as usize {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"limit {} exceeded by length {} of file name {}",
|
"limit {} exceeded by length {} of file name {}",
|
||||||
libc::PATH_MAX,
|
libc::PATH_MAX,
|
||||||
total_len,
|
total_len,
|
||||||
|
@ -205,7 +205,7 @@ fn check_default(path: &[String]) -> bool {
|
||||||
let component_len = p.len();
|
let component_len = p.len();
|
||||||
if component_len > libc::FILENAME_MAX as usize {
|
if component_len > libc::FILENAME_MAX as usize {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"limit {} exceeded by length {} of file name component {}",
|
"limit {} exceeded by length {} of file name component {}",
|
||||||
libc::FILENAME_MAX,
|
libc::FILENAME_MAX,
|
||||||
component_len,
|
component_len,
|
||||||
|
@ -227,7 +227,7 @@ fn check_searchable(path: &str) -> bool {
|
||||||
if e.kind() == ErrorKind::NotFound {
|
if e.kind() == ErrorKind::NotFound {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
writeln!(&mut std::io::stderr(), "{}", e);
|
writeln!(std::io::stderr(), "{}", e);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ fn check_portable_chars(path_segment: &str) -> bool {
|
||||||
if !VALID_CHARS.contains(ch) {
|
if !VALID_CHARS.contains(ch) {
|
||||||
let invalid = path_segment[i..].chars().next().unwrap();
|
let invalid = path_segment[i..].chars().next().unwrap();
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
std::io::stderr(),
|
||||||
"nonportable character '{}' in file name component {}",
|
"nonportable character '{}' in file name component {}",
|
||||||
invalid,
|
invalid,
|
||||||
path_segment.quote()
|
path_segment.quote()
|
||||||
|
|
|
@ -186,7 +186,7 @@ fn round_terminal_digit(
|
||||||
if position < after_dec.len() {
|
if position < after_dec.len() {
|
||||||
let digit_at_pos: char;
|
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 {
|
if let '5'..='9' = digit_at_pos {
|
||||||
let (new_after_dec, finished_in_dec) = _round_str_from(&after_dec, position);
|
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);
|
let mut big_input = at.make_file(FILE);
|
||||||
for i in 0..LINES {
|
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");
|
big_input.flush().expect("Could not flush FILE");
|
||||||
|
|
||||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||||
for i in (LINES - N_ARG)..LINES {
|
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");
|
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);
|
let mut big_input = at.make_file(FILE);
|
||||||
for i in 0..BYTES {
|
for i in 0..BYTES {
|
||||||
let digit = from_digit((i % 10) as u32, 10).unwrap();
|
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");
|
big_input.flush().expect("Could not flush FILE");
|
||||||
|
|
||||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||||
for i in (BYTES - N_ARG)..BYTES {
|
for i in (BYTES - N_ARG)..BYTES {
|
||||||
let digit = from_digit((i % 10) as u32, 10).unwrap();
|
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");
|
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);
|
let mut big_input = at.make_file(FILE);
|
||||||
for i in 0..LINES {
|
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");
|
big_input.flush().expect("Could not flush FILE");
|
||||||
|
|
||||||
let mut big_expected = at.make_file(EXPECTED_FILE);
|
let mut big_expected = at.make_file(EXPECTED_FILE);
|
||||||
for i in (LINES - N_ARG)..LINES {
|
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");
|
big_expected.flush().expect("Could not flush EXPECTED_FILE");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue