mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #7700 from nyurik/parens
chore: remove unneeded parens
This commit is contained in:
commit
ed8689eaa3
12 changed files with 43 additions and 46 deletions
|
@ -65,7 +65,7 @@ fn main() {
|
||||||
|
|
||||||
// binary name equals util name?
|
// binary name equals util name?
|
||||||
if let Some(&(uumain, _)) = utils.get(binary_as_util) {
|
if let Some(&(uumain, _)) = utils.get(binary_as_util) {
|
||||||
process::exit(uumain((vec![binary.into()].into_iter()).chain(args)));
|
process::exit(uumain(vec![binary.into()].into_iter().chain(args)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// binary name equals prefixed util name?
|
// binary name equals prefixed util name?
|
||||||
|
@ -111,7 +111,7 @@ fn main() {
|
||||||
|
|
||||||
match utils.get(util) {
|
match utils.get(util) {
|
||||||
Some(&(uumain, _)) => {
|
Some(&(uumain, _)) => {
|
||||||
process::exit(uumain((vec![util_os].into_iter()).chain(args)));
|
process::exit(uumain(vec![util_os].into_iter().chain(args)));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if util == "--help" || util == "-h" {
|
if util == "--help" || util == "-h" {
|
||||||
|
@ -124,7 +124,8 @@ fn main() {
|
||||||
match utils.get(util) {
|
match utils.get(util) {
|
||||||
Some(&(uumain, _)) => {
|
Some(&(uumain, _)) => {
|
||||||
let code = uumain(
|
let code = uumain(
|
||||||
(vec![util_os, OsString::from("--help")].into_iter())
|
vec![util_os, OsString::from("--help")]
|
||||||
|
.into_iter()
|
||||||
.chain(args),
|
.chain(args),
|
||||||
);
|
);
|
||||||
io::stdout().flush().expect("could not flush stdout");
|
io::stdout().flush().expect("could not flush stdout");
|
||||||
|
|
2
src/uu/env/src/env.rs
vendored
2
src/uu/env/src/env.rs
vendored
|
@ -160,7 +160,7 @@ fn parse_signal_opt<'a>(opts: &mut Options<'a>, opt: &'a OsStr) -> UResult<()> {
|
||||||
|
|
||||||
let mut sig_vec = Vec::with_capacity(signals.len());
|
let mut sig_vec = Vec::with_capacity(signals.len());
|
||||||
signals.into_iter().for_each(|sig| {
|
signals.into_iter().for_each(|sig| {
|
||||||
if !(sig.is_empty()) {
|
if !sig.is_empty() {
|
||||||
sig_vec.push(sig);
|
sig_vec.push(sig);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2392,11 +2392,9 @@ fn display_dir_entry_size(
|
||||||
// TODO: Cache/memorize the display_* results so we don't have to recalculate them.
|
// TODO: Cache/memorize the display_* results so we don't have to recalculate them.
|
||||||
if let Some(md) = entry.get_metadata(out) {
|
if let Some(md) = entry.get_metadata(out) {
|
||||||
let (size_len, major_len, minor_len) = match display_len_or_rdev(md, config) {
|
let (size_len, major_len, minor_len) = match display_len_or_rdev(md, config) {
|
||||||
SizeOrDeviceId::Device(major, minor) => (
|
SizeOrDeviceId::Device(major, minor) => {
|
||||||
(major.len() + minor.len() + 2usize),
|
(major.len() + minor.len() + 2usize, major.len(), minor.len())
|
||||||
major.len(),
|
}
|
||||||
minor.len(),
|
|
||||||
),
|
|
||||||
SizeOrDeviceId::Size(size) => (size.len(), 0usize, 0usize),
|
SizeOrDeviceId::Size(size) => (size.len(), 0usize, 0usize),
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
|
|
|
@ -655,8 +655,7 @@ fn build_options(
|
||||||
|
|
||||||
let page_length_le_ht = page_length < (HEADER_LINES_PER_PAGE + TRAILER_LINES_PER_PAGE);
|
let page_length_le_ht = page_length < (HEADER_LINES_PER_PAGE + TRAILER_LINES_PER_PAGE);
|
||||||
|
|
||||||
let display_header_and_trailer =
|
let display_header_and_trailer = !page_length_le_ht && !matches.get_flag(options::OMIT_HEADER);
|
||||||
!(page_length_le_ht) && !matches.get_flag(options::OMIT_HEADER);
|
|
||||||
|
|
||||||
let content_lines_per_page = if page_length_le_ht {
|
let content_lines_per_page = if page_length_le_ht {
|
||||||
page_length
|
page_length
|
||||||
|
|
|
@ -323,7 +323,7 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut word = line[beg..end].to_owned();
|
let mut word = line[beg..end].to_owned();
|
||||||
if filter.only_specified && !(filter.only_set.contains(&word)) {
|
if filter.only_specified && !filter.only_set.contains(&word) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if filter.ignore_specified && filter.ignore_set.contains(&word) {
|
if filter.ignore_specified && filter.ignore_set.contains(&word) {
|
||||||
|
|
|
@ -289,7 +289,7 @@ impl BytesChunkBuffer {
|
||||||
let mut chunk = Box::new(BytesChunk::new());
|
let mut chunk = Box::new(BytesChunk::new());
|
||||||
|
|
||||||
// fill chunks with all bytes from reader and reuse already instantiated chunks if possible
|
// fill chunks with all bytes from reader and reuse already instantiated chunks if possible
|
||||||
while (chunk.fill(reader)?).is_some() {
|
while chunk.fill(reader)?.is_some() {
|
||||||
self.bytes += chunk.bytes as u64;
|
self.bytes += chunk.bytes as u64;
|
||||||
self.chunks.push_back(chunk);
|
self.chunks.push_back(chunk);
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ impl LinesChunkBuffer {
|
||||||
pub fn fill(&mut self, reader: &mut impl BufRead) -> UResult<()> {
|
pub fn fill(&mut self, reader: &mut impl BufRead) -> UResult<()> {
|
||||||
let mut chunk = Box::new(LinesChunk::new(self.delimiter));
|
let mut chunk = Box::new(LinesChunk::new(self.delimiter));
|
||||||
|
|
||||||
while (chunk.fill(reader)?).is_some() {
|
while chunk.fill(reader)?.is_some() {
|
||||||
self.lines += chunk.lines as u64;
|
self.lines += chunk.lines as u64;
|
||||||
self.chunks.push_back(chunk);
|
self.chunks.push_back(chunk);
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ fn tail_file(
|
||||||
msg
|
msg
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if !(observer.follow_name_retry()) {
|
if !observer.follow_name_retry() {
|
||||||
// skip directory if not retry
|
// skip directory if not retry
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,23 +512,23 @@ mod tests {
|
||||||
|
|
||||||
for &(c, exp) in &suffixes {
|
for &(c, exp) in &suffixes {
|
||||||
let s = format!("2{c}B"); // KB
|
let s = format!("2{c}B"); // KB
|
||||||
assert_eq!(Ok(2 * (1000_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(2 * 1000_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("2{c}"); // K
|
let s = format!("2{c}"); // K
|
||||||
assert_eq!(Ok(2 * (1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(2 * 1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("2{c}iB"); // KiB
|
let s = format!("2{c}iB"); // KiB
|
||||||
assert_eq!(Ok(2 * (1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(2 * 1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("2{}iB", c.to_lowercase()); // kiB
|
let s = format!("2{}iB", c.to_lowercase()); // kiB
|
||||||
assert_eq!(Ok(2 * (1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(2 * 1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
|
|
||||||
// suffix only
|
// suffix only
|
||||||
let s = format!("{c}B"); // KB
|
let s = format!("{c}B"); // KB
|
||||||
assert_eq!(Ok((1000_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(1000_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("{c}"); // K
|
let s = format!("{c}"); // K
|
||||||
assert_eq!(Ok((1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("{c}iB"); // KiB
|
let s = format!("{c}iB"); // KiB
|
||||||
assert_eq!(Ok((1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
let s = format!("{}iB", c.to_lowercase()); // kiB
|
let s = format!("{}iB", c.to_lowercase()); // kiB
|
||||||
assert_eq!(Ok((1024_u128).pow(exp)), parse_size_u128(&s));
|
assert_eq!(Ok(1024_u128.pow(exp)), parse_size_u128(&s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -474,7 +474,7 @@ pub trait FromIo<T> {
|
||||||
impl FromIo<Box<UIoError>> for std::io::Error {
|
impl FromIo<Box<UIoError>> for std::io::Error {
|
||||||
fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError> {
|
fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError> {
|
||||||
Box::new(UIoError {
|
Box::new(UIoError {
|
||||||
context: Some((context)()),
|
context: Some(context()),
|
||||||
inner: self,
|
inner: self,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ impl<T> FromIo<UResult<T>> for std::io::Result<T> {
|
||||||
impl FromIo<Box<UIoError>> for std::io::ErrorKind {
|
impl FromIo<Box<UIoError>> for std::io::ErrorKind {
|
||||||
fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError> {
|
fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError> {
|
||||||
Box::new(UIoError {
|
Box::new(UIoError {
|
||||||
context: Some((context)()),
|
context: Some(context()),
|
||||||
inner: std::io::Error::new(self, ""),
|
inner: std::io::Error::new(self, ""),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
|
||||||
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
||||||
self.map_err(|e| {
|
self.map_err(|e| {
|
||||||
Box::new(UIoError {
|
Box::new(UIoError {
|
||||||
context: Some((context)()),
|
context: Some(context()),
|
||||||
inner: std::io::Error::from_raw_os_error(e as i32),
|
inner: std::io::Error::from_raw_os_error(e as i32),
|
||||||
}) as Box<dyn UError>
|
}) as Box<dyn UError>
|
||||||
})
|
})
|
||||||
|
@ -541,7 +541,7 @@ impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
|
||||||
impl<T> FromIo<UResult<T>> for nix::Error {
|
impl<T> FromIo<UResult<T>> for nix::Error {
|
||||||
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
||||||
Err(Box::new(UIoError {
|
Err(Box::new(UIoError {
|
||||||
context: Some((context)()),
|
context: Some(context()),
|
||||||
inner: std::io::Error::from_raw_os_error(self as i32),
|
inner: std::io::Error::from_raw_os_error(self as i32),
|
||||||
}) as Box<dyn UError>)
|
}) as Box<dyn UError>)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5787,11 +5787,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
|
||||||
} else {
|
} else {
|
||||||
libc::S_IRWXG | libc::S_IRWXO
|
libc::S_IRWXG | libc::S_IRWXO
|
||||||
} as u32;
|
} as u32;
|
||||||
assert_eq!(
|
assert_eq!(mode & mask, 0, "unwanted permissions are present - {attr}");
|
||||||
(mode & mask),
|
|
||||||
0,
|
|
||||||
"unwanted permissions are present - {attr}"
|
|
||||||
);
|
|
||||||
at.write(FIFO, "done");
|
at.write(FIFO, "done");
|
||||||
child.wait().unwrap().succeeded();
|
child.wait().unwrap().succeeded();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ use uutests::new_ucmd;
|
||||||
use uutests::util::TestScenario;
|
use uutests::util::TestScenario;
|
||||||
use uutests::util_name;
|
use uutests::util_name;
|
||||||
|
|
||||||
|
use std::fmt::Write;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use rand::distr::{Distribution, Uniform};
|
use rand::distr::{Distribution, Uniform};
|
||||||
|
@ -55,7 +56,7 @@ fn test_parallel() {
|
||||||
let n_integers = 100_000;
|
let n_integers = 100_000;
|
||||||
let mut input_string = String::new();
|
let mut input_string = String::new();
|
||||||
for i in 0..=n_integers {
|
for i in 0..=n_integers {
|
||||||
input_string.push_str(&(format!("{i} "))[..]);
|
let _ = write!(input_string, "{i} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
let tmp_dir = TempDir::new().unwrap();
|
let tmp_dir = TempDir::new().unwrap();
|
||||||
|
@ -100,7 +101,7 @@ fn test_first_1000_integers() {
|
||||||
let n_integers = 1000;
|
let n_integers = 1000;
|
||||||
let mut input_string = String::new();
|
let mut input_string = String::new();
|
||||||
for i in 0..=n_integers {
|
for i in 0..=n_integers {
|
||||||
input_string.push_str(&(format!("{i} "))[..]);
|
let _ = write!(input_string, "{i} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("STDIN='{input_string}'");
|
println!("STDIN='{input_string}'");
|
||||||
|
@ -124,7 +125,7 @@ fn test_first_1000_integers_with_exponents() {
|
||||||
let n_integers = 1000;
|
let n_integers = 1000;
|
||||||
let mut input_string = String::new();
|
let mut input_string = String::new();
|
||||||
for i in 0..=n_integers {
|
for i in 0..=n_integers {
|
||||||
input_string.push_str(&(format!("{i} "))[..]);
|
let _ = write!(input_string, "{i} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("STDIN='{input_string}'");
|
println!("STDIN='{input_string}'");
|
||||||
|
@ -197,11 +198,11 @@ fn test_random() {
|
||||||
let mut output_string = String::new();
|
let mut output_string = String::new();
|
||||||
for _ in 0..NUM_TESTS {
|
for _ in 0..NUM_TESTS {
|
||||||
let (product, factors) = rand_gt(1 << 63);
|
let (product, factors) = rand_gt(1 << 63);
|
||||||
input_string.push_str(&(format!("{product} "))[..]);
|
let _ = write!(input_string, "{product} ");
|
||||||
|
|
||||||
output_string.push_str(&(format!("{product}:"))[..]);
|
let _ = write!(output_string, "{product}:");
|
||||||
for factor in factors {
|
for factor in factors {
|
||||||
output_string.push_str(&(format!(" {factor}"))[..]);
|
let _ = write!(output_string, " {factor}");
|
||||||
}
|
}
|
||||||
output_string.push('\n');
|
output_string.push('\n');
|
||||||
}
|
}
|
||||||
|
@ -281,11 +282,11 @@ fn test_random_big() {
|
||||||
let mut output_string = String::new();
|
let mut output_string = String::new();
|
||||||
for _ in 0..NUM_TESTS {
|
for _ in 0..NUM_TESTS {
|
||||||
let (product, factors) = rand_64();
|
let (product, factors) = rand_64();
|
||||||
input_string.push_str(&(format!("{product} "))[..]);
|
let _ = write!(input_string, "{product} ");
|
||||||
|
|
||||||
output_string.push_str(&(format!("{product}:"))[..]);
|
let _ = write!(output_string, "{product}:");
|
||||||
for factor in factors {
|
for factor in factors {
|
||||||
output_string.push_str(&(format!(" {factor}"))[..]);
|
let _ = write!(output_string, " {factor}");
|
||||||
}
|
}
|
||||||
output_string.push('\n');
|
output_string.push('\n');
|
||||||
}
|
}
|
||||||
|
@ -298,8 +299,8 @@ fn test_big_primes() {
|
||||||
let mut input_string = String::new();
|
let mut input_string = String::new();
|
||||||
let mut output_string = String::new();
|
let mut output_string = String::new();
|
||||||
for prime in PRIMES64 {
|
for prime in PRIMES64 {
|
||||||
input_string.push_str(&(format!("{prime} "))[..]);
|
let _ = write!(input_string, "{prime} ");
|
||||||
output_string.push_str(&(format!("{prime}: {prime}\n"))[..]);
|
let _ = writeln!(output_string, "{prime}: {prime}");
|
||||||
}
|
}
|
||||||
|
|
||||||
run(input_string.as_bytes(), output_string.as_bytes());
|
run(input_string.as_bytes(), output_string.as_bytes());
|
||||||
|
@ -325,8 +326,8 @@ fn test_primes_with_exponents() {
|
||||||
let mut output_string = String::new();
|
let mut output_string = String::new();
|
||||||
for primes in PRIMES_BY_BITS {
|
for primes in PRIMES_BY_BITS {
|
||||||
for &prime in *primes {
|
for &prime in *primes {
|
||||||
input_string.push_str(&(format!("{prime} "))[..]);
|
let _ = write!(input_string, "{prime} ");
|
||||||
output_string.push_str(&(format!("{prime}: {prime}\n"))[..]);
|
let _ = writeln!(output_string, "{prime}: {prime}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1733,7 +1733,9 @@ fn test_ls_group_directories_first() {
|
||||||
.succeeds();
|
.succeeds();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.stdout_str().split('\n').collect::<Vec<_>>(),
|
result.stdout_str().split('\n').collect::<Vec<_>>(),
|
||||||
(dirnames.into_iter().rev())
|
dirnames
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
.chain(dots.into_iter().rev())
|
.chain(dots.into_iter().rev())
|
||||||
.chain(filenames.into_iter().rev())
|
.chain(filenames.into_iter().rev())
|
||||||
.chain([""].into_iter())
|
.chain([""].into_iter())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue