From 2f85610cc34bc68fe883eee975996868cf02487d Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 30 Jan 2022 14:07:07 +0100 Subject: [PATCH] remove explicit iter loops --- src/uu/cp/src/cp.rs | 2 +- src/uu/dd/src/dd.rs | 2 +- src/uu/df/src/df.rs | 2 +- src/uu/dirname/src/dirname.rs | 2 +- src/uu/du/src/du.rs | 2 +- src/uu/expand/src/expand.rs | 2 +- src/uu/pr/src/pr.rs | 2 +- src/uu/sort/src/sort.rs | 2 +- src/uu/unexpand/src/unexpand.rs | 2 +- src/uucore/src/lib/features/fs.rs | 2 +- src/uucore/src/lib/features/memo.rs | 2 +- tests/by-util/test_relpath.rs | 8 ++++---- tests/by-util/test_tee.rs | 4 ++-- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 49cecfc00..871017f26 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -741,7 +741,7 @@ fn parse_path_args(path_args: &[String], options: &Options) -> CopyResult<(Vec( let mut blocks = block(&buf, cbs, rstat); if let Some(ct) = i.cflags.ctable { - for buf in blocks.iter_mut() { + for buf in &mut blocks { apply_conversion(buf, ct); } } diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 54b39cb15..b9512f6d8 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -367,7 +367,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } println!(); - for fs in fs_list.iter() { + for fs in &fs_list { print!("{0: <16} ", fs.mount_info.dev_name); if opt.show_fs_type { print!("{0: <5} ", fs.mount_info.fs_type); diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 343007d29..e47177ea2 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -56,7 +56,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect(); if !dirnames.is_empty() { - for path in dirnames.iter() { + for path in &dirnames { let p = Path::new(path); match p.parent() { Some(d) => { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index e95541cac..72a5f771f 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -853,7 +853,7 @@ mod test_du { (Some("K".to_string()), 1024), (None, 1024), ]; - for it in test_data.iter() { + for it in &test_data { assert_eq!(read_block_size(it.0.as_deref()), it.1); } } diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index ebddaa690..8e4bf43b8 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -278,7 +278,7 @@ fn expand(options: &Options) -> std::io::Result<()> { let ts = options.tabstops.as_ref(); let mut buf = Vec::new(); - for file in options.files.iter() { + for file in &options.files { let mut fh = open(file); while match fh.read_until(b'\n', &mut buf) { diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 561998b36..6e0cc76e0 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -1007,7 +1007,7 @@ fn mpr(paths: &[String], options: &OutputOptions) -> Result { let mut lines = Vec::new(); let mut page_counter = start_page; - for (_key, file_line_group) in file_line_groups.into_iter() { + for (_key, file_line_group) in &file_line_groups { for file_line in file_line_group { if let Err(e) = file_line.line_content { return Err(e.into()); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 239256aae..e9177654e 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -571,7 +571,7 @@ impl<'a> Line<'a> { let mut fields = vec![]; tokenize(self.line, settings.separator, &mut fields); - for selector in settings.selectors.iter() { + for selector in &settings.selectors { let mut selection = selector.get_range(self.line, Some(&fields)); match selector.settings.mode { SortMode::Numeric | SortMode::HumanNumeric => { diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index a1c5a91ef..3b419d854 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -249,7 +249,7 @@ fn unexpand(options: &Options) -> std::io::Result<()> { let mut buf = Vec::new(); let lastcol = if ts.len() > 1 { *ts.last().unwrap() } else { 0 }; - for file in options.files.iter() { + for file in &options.files { let mut fh = open(file); while match fh.read_until(b'\n', &mut buf) { diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index b1b86e73a..ccfd8318c 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -500,7 +500,7 @@ mod tests { #[test] fn test_normalize_path() { - for test in NORMALIZE_PATH_TESTS.iter() { + for test in &NORMALIZE_PATH_TESTS { let path = Path::new(test.path); let normalized = normalize_path(path); assert_eq!( diff --git a/src/uucore/src/lib/features/memo.rs b/src/uucore/src/lib/features/memo.rs index 232ead2ae..f2d1a33d9 100644 --- a/src/uucore/src/lib/features/memo.rs +++ b/src/uucore/src/lib/features/memo.rs @@ -67,7 +67,7 @@ impl Memo { pm } pub fn apply(&self, pf_args_it: &mut Peekable>) { - for tkn in self.tokens.iter() { + for tkn in &self.tokens { tkn.print(pf_args_it); } } diff --git a/tests/by-util/test_relpath.rs b/tests/by-util/test_relpath.rs index 44a685c90..5f7d4fccf 100644 --- a/tests/by-util/test_relpath.rs +++ b/tests/by-util/test_relpath.rs @@ -74,7 +74,7 @@ fn test_relpath_with_from_no_d() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - for test in TESTS.iter() { + for test in &TESTS { let from: &str = &convert_path(test.from); let to: &str = &convert_path(test.to); let expected: &str = &convert_path(test.expected); @@ -96,7 +96,7 @@ fn test_relpath_with_from_with_d() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - for test in TESTS.iter() { + for test in &TESTS { let from: &str = &convert_path(test.from); let to: &str = &convert_path(test.to); let pwd = at.as_string(); @@ -132,7 +132,7 @@ fn test_relpath_no_from_no_d() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - for test in TESTS.iter() { + for test in &TESTS { let to: &str = &convert_path(test.to); at.mkdir_all(to); @@ -150,7 +150,7 @@ fn test_relpath_no_from_with_d() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - for test in TESTS.iter() { + for test in &TESTS { let to: &str = &convert_path(test.to); let pwd = at.as_string(); at.mkdir_all(to); diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 0f41d7db7..17e3c05cf 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -9,7 +9,7 @@ fn test_tee_processing_multiple_operands() { // POSIX says: "Processing of at least 13 file operands shall be supported." let content = "tee_sample_content"; - for &n in [1, 2, 12, 13].iter() { + for &n in &[1, 2, 12, 13] { let files = (1..=n).map(|x| x.to_string()).collect::>(); let (at, mut ucmd) = at_and_ucmd!(); @@ -18,7 +18,7 @@ fn test_tee_processing_multiple_operands() { .succeeds() .stdout_is(content); - for file in files.iter() { + for file in &files { assert!(at.file_exists(file)); assert_eq!(at.read(file), content); }