Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn main() {
mf.write_all(
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
\n\
#[allow(clippy::too_many_lines)]
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
.as_bytes(),
)
Expand Down
6 changes: 3 additions & 3 deletions src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
NumberingMode::None
};

let show_nonprint = vec![
let show_nonprint = [
options::SHOW_ALL.to_owned(),
options::SHOW_NONPRINTING_ENDS.to_owned(),
options::SHOW_NONPRINTING_TABS.to_owned(),
Expand All @@ -201,15 +201,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.iter()
.any(|v| matches.get_flag(v));

let show_ends = vec![
let show_ends = [
options::SHOW_ENDS.to_owned(),
options::SHOW_ALL.to_owned(),
options::SHOW_NONPRINTING_ENDS.to_owned(),
]
.iter()
.any(|v| matches.get_flag(v));

let show_tabs = vec![
let show_tabs = [
options::SHOW_ALL.to_owned(),
options::SHOW_TABS.to_owned(),
options::SHOW_NONPRINTING_TABS.to_owned(),
Expand Down
16 changes: 8 additions & 8 deletions src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,25 @@ mod tests {
fn test_extract_negative_modes() {
// "chmod -w -r file" becomes "chmod -w,-r file". clap does not accept "-w,-r" as MODE.
// Therefore, "w" is added as pseudo mode to pass clap.
let (c, a) = extract_negative_modes(vec!["-w", "-r", "file"].iter().map(OsString::from));
let (c, a) = extract_negative_modes(["-w", "-r", "file"].iter().map(OsString::from));
assert_eq!(c, Some("-w,-r".to_string()));
assert_eq!(a, vec!["w", "file"]);
assert_eq!(a, ["w", "file"]);

// "chmod -w file -r" becomes "chmod -w,-r file". clap does not accept "-w,-r" as MODE.
// Therefore, "w" is added as pseudo mode to pass clap.
let (c, a) = extract_negative_modes(vec!["-w", "file", "-r"].iter().map(OsString::from));
let (c, a) = extract_negative_modes(["-w", "file", "-r"].iter().map(OsString::from));
assert_eq!(c, Some("-w,-r".to_string()));
assert_eq!(a, vec!["w", "file"]);
assert_eq!(a, ["w", "file"]);

// "chmod -w -- -r file" becomes "chmod -w -r file", where "-r" is interpreted as file.
// Again, "w" is needed as pseudo mode.
let (c, a) = extract_negative_modes(vec!["-w", "--", "-r", "f"].iter().map(OsString::from));
let (c, a) = extract_negative_modes(["-w", "--", "-r", "f"].iter().map(OsString::from));
assert_eq!(c, Some("-w".to_string()));
assert_eq!(a, vec!["w", "--", "-r", "f"]);
assert_eq!(a, ["w", "--", "-r", "f"]);

// "chmod -- -r file" becomes "chmod -r file".
let (c, a) = extract_negative_modes(vec!["--", "-r", "file"].iter().map(OsString::from));
let (c, a) = extract_negative_modes(["--", "-r", "file"].iter().map(OsString::from));
assert_eq!(c, None);
assert_eq!(a, vec!["--", "-r", "file"]);
assert_eq!(a, ["--", "-r", "file"]);
}
}
4 changes: 1 addition & 3 deletions src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
println!("{s}");
Ok(())
}
Err(s) => {
return Err(USimpleError::new(1, s));
}
Err(s) => Err(USimpleError::new(1, s)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

if default_format {
id_print(&mut state, &groups);
id_print(&state, &groups);
}
print!("{line_ending}");

Expand Down Expand Up @@ -550,7 +550,7 @@ fn auditid() {
println!("asid={}", auditinfo.ai_asid);
}

fn id_print(state: &mut State, groups: &[u32]) {
fn id_print(state: &State, groups: &[u32]) {
let uid = state.ids.as_ref().unwrap().uid;
let gid = state.ids.as_ref().unwrap().gid;
let euid = state.ids.as_ref().unwrap().euid;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
if !target_dir.is_dir() {
return Err(InstallError::TargetDirIsntDir(target_dir.to_path_buf()).into());
}
for sourcepath in files.iter() {
for sourcepath in files {
if let Err(err) = sourcepath
.metadata()
.map_err_context(|| format!("cannot stat {}", sourcepath.quote()))
Expand Down
10 changes: 4 additions & 6 deletions src/uu/mknod/src/mknod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
matches.get_one::<u64>("major"),
matches.get_one::<u64>("minor"),
) {
(_, None) | (None, _) => {
return Err(UUsageError::new(
1,
"Special files require major and minor device numbers.",
));
}
(_, None) | (None, _) => Err(UUsageError::new(
1,
"Special files require major and minor device numbers.",
)),
(Some(&major), Some(&minor)) => {
let dev = makedev(major, minor);
let exit_code = match file_type {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
None
};

for sourcepath in files.iter() {
for sourcepath in files {
if let Some(ref pb) = count_progress {
pb.set_message(sourcepath.to_string_lossy().to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/od/src/prn_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn format_ascii_dump(bytes: &[u8]) -> String {
let mut result = String::new();

result.push('>');
for c in bytes.iter() {
for c in bytes {
if *c >= 0x20 && *c <= 0x7e {
result.push_str(C_CHARS[*c as usize]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sort/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn check(path: &OsStr, settings: &GlobalSettings) -> UResult<()> {

let mut prev_chunk: Option<Chunk> = None;
let mut line_idx = 0;
for chunk in loaded_receiver.iter() {
for chunk in loaded_receiver {
line_idx += 1;
if let Some(prev_chunk) = prev_chunk.take() {
// Check if the first element of the new chunk is greater than the last
Expand Down Expand Up @@ -107,7 +107,7 @@ fn reader(
settings: &GlobalSettings,
) -> UResult<()> {
let mut carry_over = vec![];
for recycled_chunk in receiver.iter() {
for recycled_chunk in receiver {
let should_continue = chunks::read(
sender,
recycled_chunk,
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn reader(
settings: &GlobalSettings,
separator: u8,
) -> UResult<()> {
for (file_idx, recycled_chunk) in recycled_receiver.iter() {
for (file_idx, recycled_chunk) in recycled_receiver {
if let Some(ReaderFile {
file,
sender,
Expand Down
6 changes: 3 additions & 3 deletions src/uu/stdbuf/src/stdbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn set_command_env(command: &mut process::Command, buffer_name: &str, buffer_typ
}
}

fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> {
fn get_preload_env(tmp_dir: &TempDir) -> io::Result<(String, PathBuf)> {
let (preload, extension) = preload_strings();
let inject_path = tmp_dir.path().join("libstdbuf").with_extension(extension);

Expand All @@ -152,8 +152,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut command = process::Command::new(command_values.next().unwrap());
let command_params: Vec<&str> = command_values.map(|s| s.as_ref()).collect();

let mut tmp_dir = tempdir().unwrap();
let (preload_env, libstdbuf) = get_preload_env(&mut tmp_dir).map_err_context(String::new)?;
let tmp_dir = tempdir().unwrap();
let (preload_env, libstdbuf) = get_preload_env(&tmp_dir).map_err_context(String::new)?;
command.env(preload_env, libstdbuf);
set_command_env(&mut command, "_STDBUF_I", &options.stdin);
set_command_env(&mut command, "_STDBUF_O", &options.stdout);
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sum/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
match reader.read(&mut buf) {
Ok(n) if n != 0 => {
bytes_read += n;
for &byte in buf[..n].iter() {
for &byte in &buf[..n] {
checksum = checksum.rotate_right(1);
checksum = checksum.wrapping_add(u16::from(byte));
}
Expand All @@ -56,7 +56,7 @@ fn sysv_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
match reader.read(&mut buf) {
Ok(n) if n != 0 => {
bytes_read += n;
for &byte in buf[..n].iter() {
for &byte in &buf[..n] {
ret = ret.wrapping_add(u32::from(byte));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let path = Path::new(&f);
if let Err(e) = open(path, OFlag::O_NONBLOCK, Mode::empty()) {
if e != Errno::EACCES || (e == Errno::EACCES && path.is_dir()) {
return e.map_err_context(|| format!("error opening {}", f.quote()))?;
e.map_err_context(|| format!("error opening {}", f.quote()))?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tail/src/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl LinesChunk {
fn calculate_bytes_offset_from(&self, offset: usize) -> usize {
let mut lines_offset = offset;
let mut bytes_offset = 0;
for byte in self.get_buffer().iter() {
for byte in self.get_buffer() {
if lines_offset == 0 {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ fn compute_number_width(inputs: &Inputs, settings: &Settings) -> usize {

let mut minimum_width = 1;
let mut total: u64 = 0;
for input in inputs.iter() {
for input in inputs {
match input {
Input::Stdin(_) => minimum_width = MINIMUM_WIDTH,
Input::Path(path) => {
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ mod tests {
let path1 = temp_file.path();
let path2 = temp_file.path();

assert_eq!(are_hardlinks_to_same_file(&path1, &path2), true);
assert!(are_hardlinks_to_same_file(&path1, &path2));
}

#[cfg(unix)]
Expand All @@ -860,7 +860,7 @@ mod tests {
let path1 = temp_file1.path();
let path2 = temp_file2.path();

assert_eq!(are_hardlinks_to_same_file(&path1, &path2), false);
assert!(!are_hardlinks_to_same_file(&path1, &path2));
}

#[cfg(unix)]
Expand All @@ -873,6 +873,6 @@ mod tests {
let path2 = temp_file.path().with_extension("hardlink");
fs::hard_link(&path1, &path2).unwrap();

assert_eq!(are_hardlinks_to_same_file(&path1, &path2), true);
assert!(are_hardlinks_to_same_file(&path1, &path2));
}
}
8 changes: 4 additions & 4 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,12 +2022,12 @@ fn test_cp_reflink_always_override() {
const USERDIR: &str = "dir/";
const MOUNTPOINT: &str = "mountpoint/";

let src1_path: &str = &vec![MOUNTPOINT, USERDIR, "src1"].concat();
let src2_path: &str = &vec![MOUNTPOINT, USERDIR, "src2"].concat();
let dst_path: &str = &vec![MOUNTPOINT, USERDIR, "dst"].concat();
let src1_path: &str = &[MOUNTPOINT, USERDIR, "src1"].concat();
let src2_path: &str = &[MOUNTPOINT, USERDIR, "src2"].concat();
let dst_path: &str = &[MOUNTPOINT, USERDIR, "dst"].concat();

scene.fixtures.mkdir(ROOTDIR);
scene.fixtures.mkdir(vec![ROOTDIR, USERDIR].concat());
scene.fixtures.mkdir([ROOTDIR, USERDIR].concat());

// Setup:
// Because neither `mkfs.btrfs` not btrfs `mount` options allow us to have a mountpoint owned
Expand Down
3 changes: 1 addition & 2 deletions tests/by-util/test_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ fn test_random() {
break;
}
}
let factor = factor;

match product.checked_mul(factor) {
Some(p) => {
Expand Down Expand Up @@ -317,7 +316,7 @@ fn run(input_string: &[u8], output_string: &[u8]) {
fn test_primes_with_exponents() {
let mut input_string = String::new();
let mut output_string = String::new();
for primes in PRIMES_BY_BITS.iter() {
for primes in PRIMES_BY_BITS {
for &prime in *primes {
input_string.push_str(&(format!("{prime} "))[..]);
output_string.push_str(&(format!("{prime}: {prime}\n"))[..]);
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_link_one_argument() {
#[test]
fn test_link_three_arguments() {
let (_, mut ucmd) = at_and_ucmd!();
let arguments = vec![
let arguments = [
"test_link_argument1",
"test_link_argument2",
"test_link_argument3",
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ fn test_mv_verbose() {

#[test]
#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
#[cfg(features = "mkdir")]
#[cfg(feature = "mkdir")]
fn test_mv_permission_error() {
let scene = TestScenario::new("mkdir");
let folder1 = "bar";
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn test_rm_prompts() {
// Needed for talking with stdin on platforms where CRLF or LF matters
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };

let mut answers = vec![
let mut answers = [
"rm: descend into directory 'a'?",
"rm: remove write-protected regular empty file 'a/empty-no-write'?",
"rm: remove symbolic link 'a/slink'?",
Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn test_echo() {
#[test]
fn test_head_count() {
let repeat_limit = 5;
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let input = input_seq
.iter()
.map(ToString::to_string)
Expand Down Expand Up @@ -102,7 +102,7 @@ fn test_head_count() {
#[test]
fn test_repeat() {
let repeat_limit = 15000;
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let input = input_seq
.iter()
.map(ToString::to_string)
Expand Down
Loading