diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 11bbdff29..0c431c235 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -27,7 +27,7 @@ const USAGE: &str = "\ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option, Option, IfFrom)> { let dest_gid = if let Some(file) = matches.get_one::(options::REFERENCE) { - fs::metadata(&file) + fs::metadata(file) .map(|meta| Some(meta.gid())) .map_err_context(|| format!("failed to get attributes of {}", file.quote()))? } else { diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index ddecc4a33..2aefb4879 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -40,7 +40,7 @@ fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option, Optio let dest_uid: Option; let dest_gid: Option; if let Some(file) = matches.get_one::(options::REFERENCE) { - let meta = fs::metadata(&file) + let meta = fs::metadata(file) .map_err_context(|| format!("failed to get attributes of {}", file.quote()))?; dest_gid = Some(meta.gid()); dest_uid = Some(meta.uid()); diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 1d5bea8e7..fe6236efe 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -124,7 +124,7 @@ fn open_file(name: &str) -> io::Result { match name { "-" => Ok(LineReader::Stdin(stdin())), _ => { - let f = File::open(&Path::new(name))?; + let f = File::open(Path::new(name))?; Ok(LineReader::FileIn(BufReader::new(f))) } } diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index c69fe7dd0..16d498744 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1115,7 +1115,7 @@ fn copy_directory( .follow_links(options.dereference) { let p = or_continue!(path); - let path = current_dir.join(&p.path()); + let path = current_dir.join(p.path()); let local_to_root_parent = match root_parent { Some(parent) => { @@ -1131,7 +1131,7 @@ fn copy_directory( } #[cfg(not(windows))] { - or_continue!(path.strip_prefix(&parent)).to_path_buf() + or_continue!(path.strip_prefix(parent)).to_path_buf() } } None => path.clone(), @@ -1351,7 +1351,7 @@ fn context_for(src: &Path, dest: &Path) -> String { /// Implements a simple backup copy for the destination file. /// TODO: for the backup, should this function be replaced by `copy_file(...)`? fn backup_dest(dest: &Path, backup_path: &Path) -> CopyResult { - fs::copy(dest, &backup_path)?; + fs::copy(dest, backup_path)?; Ok(backup_path.into()) } @@ -1566,7 +1566,7 @@ fn copy_file( .write(true) .truncate(false) .create(true) - .open(&dest) + .open(dest) .unwrap(); } }; @@ -1630,7 +1630,7 @@ fn copy_helper( fn copy_fifo(dest: &Path, overwrite: OverwriteMode) -> CopyResult<()> { if dest.exists() { overwrite.verify(dest)?; - fs::remove_file(&dest)?; + fs::remove_file(dest)?; } let name = CString::new(dest.as_os_str().as_bytes()).unwrap(); @@ -1647,7 +1647,7 @@ fn copy_link( symlinked_files: &mut HashSet, ) -> CopyResult<()> { // Here, we will copy the symlink itself (actually, just recreate it) - let link = fs::read_link(&source)?; + let link = fs::read_link(source)?; let dest: Cow<'_, Path> = if dest.is_dir() { match source.file_name() { Some(name) => dest.join(name).into(), @@ -1695,8 +1695,8 @@ pub fn verify_target_type(target: &Path, target_type: &TargetType) -> CopyResult /// ).unwrap() == Path::new("target/c.txt")) /// ``` pub fn localize_to_target(root: &Path, source: &Path, target: &Path) -> CopyResult { - let local_to_root = source.strip_prefix(&root)?; - Ok(target.join(&local_to_root)) + let local_to_root = source.strip_prefix(root)?; + Ok(target.join(local_to_root)) } pub fn path_has_prefix(p1: &Path, p2: &Path) -> io::Result { diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 70ff42054..7a8ced455 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -368,7 +368,7 @@ fn cut_files(mut filenames: Vec, mode: &Mode) -> UResult<()> { continue; } - show_if_err!(File::open(&path) + show_if_err!(File::open(path) .map_err_context(|| filename.maybe_quote().to_string()) .and_then(|file| { match &mode { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 2f573bc7e..493ddd3f8 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -492,7 +492,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { let exclude_from_iterator = matches .get_many::(options::EXCLUDE_FROM) .unwrap_or_default() - .flat_map(|f| file_as_vec(&f)); + .flat_map(file_as_vec); let excludes_iterator = matches .get_many::(options::EXCLUDE) @@ -913,7 +913,7 @@ impl FromStr for Threshold { type Err = ParseSizeError; fn from_str(s: &str) -> std::result::Result { - let offset = if s.starts_with(&['-', '+'][..]) { 1 } else { 0 }; + let offset = usize::from(s.starts_with(&['-', '+'][..])); let size = parse_size(&s[offset..])?; diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index 8c96684b8..dbd197017 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -505,11 +505,7 @@ fn prefix_operator_substr(values: &[String]) -> String { } fn bool_as_int(b: bool) -> u8 { - if b { - 1 - } else { - 0 - } + u8::from(b) } fn bool_as_string(b: bool) -> String { if b { diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 6c5c5a57c..54e03ebc1 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -275,7 +275,7 @@ impl Params { // For example, if `tmpdir` is "a/b" and the template is "c/dXXX", // then `prefix` is "a/b/c/d". let tmpdir = options.tmpdir; - let prefix_from_option = tmpdir.clone().unwrap_or_else(|| "".to_string()); + let prefix_from_option = tmpdir.clone().unwrap_or_default(); let prefix_from_template = &options.template[..i]; let prefix = Path::new(&prefix_from_option) .join(prefix_from_template) @@ -311,7 +311,7 @@ impl Params { // // For example, if the suffix command-line argument is ".txt" and // the template is "XXXabc", then `suffix` is "abc.txt". - let suffix_from_option = options.suffix.unwrap_or_else(|| "".to_string()); + let suffix_from_option = options.suffix.unwrap_or_default(); let suffix_from_template = &options.template[j..]; let suffix = format!("{}{}", suffix_from_template, suffix_from_option); if suffix.contains(MAIN_SEPARATOR) { @@ -484,7 +484,7 @@ pub fn dry_exec(tmpdir: &str, prefix: &str, rand: usize, suffix: &str) -> UResul fn make_temp_dir(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult { let mut builder = Builder::new(); builder.prefix(prefix).rand_bytes(rand).suffix(suffix); - match builder.tempdir_in(&dir) { + match builder.tempdir_in(dir) { Ok(d) => { // `into_path` consumes the TempDir without removing it let path = d.into_path(); @@ -516,7 +516,7 @@ fn make_temp_dir(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult< fn make_temp_file(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult { let mut builder = Builder::new(); builder.prefix(prefix).rand_bytes(rand).suffix(suffix); - match builder.tempfile_in(&dir) { + match builder.tempfile_in(dir) { // `keep` ensures that the file is not deleted Ok(named_tempfile) => match named_tempfile.keep() { Ok((_, pathbuf)) => Ok(pathbuf), diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 17cc01f00..a21d24eab 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -453,7 +453,7 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> { let path_symlink_points_to = fs::read_link(from)?; #[cfg(unix)] { - unix::fs::symlink(&path_symlink_points_to, &to).and_then(|_| fs::remove_file(&from))?; + unix::fs::symlink(&path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?; } #[cfg(windows)] { diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 807a6a072..f754ca1a3 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -279,7 +279,7 @@ fn nl(reader: &mut BufReader, settings: &Settings) -> UResult<()> { // If we have already seen three groups (corresponding to // a header) or the current char does not form part of // a new group, then this line is not a segment indicator. - if matched_groups >= 3 || settings.section_delimiter[if odd { 1 } else { 0 }] != c { + if matched_groups >= 3 || settings.section_delimiter[usize::from(odd)] != c { matched_groups = 0; break; } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index ecc290849..5f21c508e 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1086,7 +1086,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut files = Vec::new(); for path in &files0_from { - let reader = open(&path)?; + let reader = open(path)?; let buf_reader = BufReader::new(reader); for line in buf_reader.split(b'\0').flatten() { files.push(OsString::from( diff --git a/src/uu/sort/src/tmp_dir.rs b/src/uu/sort/src/tmp_dir.rs index 3fc405244..f9fe373da 100644 --- a/src/uu/sort/src/tmp_dir.rs +++ b/src/uu/sort/src/tmp_dir.rs @@ -80,7 +80,7 @@ impl TmpDirWrapper { /// Remove the directory at `path` by deleting its child files and then itself. /// Errors while deleting child files are ignored. fn remove_tmp_dir(path: &Path) -> std::io::Result<()> { - if let Ok(read_dir) = std::fs::read_dir(&path) { + if let Ok(read_dir) = std::fs::read_dir(path) { for file in read_dir.flatten() { // if we fail to delete the file here it was probably deleted by another thread // in the meantime, but that's ok. diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index 09326244b..46f89eff5 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -56,7 +56,7 @@ impl Drop for WithEnvVarSet { /// Restore previous value now that this is being dropped by context fn drop(&mut self) { if let Ok(ref prev_value) = self._previous_var_value { - env::set_var(&self._previous_var_key, &prev_value); + env::set_var(&self._previous_var_key, prev_value); } else { env::remove_var(&self._previous_var_key); } diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index b00a334f1..1c29d3ceb 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -207,7 +207,7 @@ pub fn uu_app<'a>() -> Command<'a> { .short(options::INPUT_SHORT) .help("adjust standard input stream buffering") .value_name("MODE") - .required_unless_present_any(&[options::OUTPUT, options::ERROR]), + .required_unless_present_any([options::OUTPUT, options::ERROR]), ) .arg( Arg::new(options::OUTPUT) @@ -215,7 +215,7 @@ pub fn uu_app<'a>() -> Command<'a> { .short(options::OUTPUT_SHORT) .help("adjust standard output stream buffering") .value_name("MODE") - .required_unless_present_any(&[options::INPUT, options::ERROR]), + .required_unless_present_any([options::INPUT, options::ERROR]), ) .arg( Arg::new(options::ERROR) @@ -223,7 +223,7 @@ pub fn uu_app<'a>() -> Command<'a> { .short(options::ERROR_SHORT) .help("adjust standard error stream buffering") .value_name("MODE") - .required_unless_present_any(&[options::INPUT, options::OUTPUT]), + .required_unless_present_any([options::INPUT, options::OUTPUT]), ) .arg( Arg::new(options::COMMAND) diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index 1be090217..556defd1f 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -122,7 +122,7 @@ impl FileHandling { */ self.get_mut(path) .reader - .replace(Box::new(BufReader::new(File::open(&path)?))); + .replace(Box::new(BufReader::new(File::open(path)?))); Ok(()) } diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 7f7d0d9a3..0a231decc 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -155,7 +155,7 @@ fn tail_file( watcher_service.add_bad_path(path, input.display_name.as_str(), false)?; } else if input.is_tailable() { let metadata = path.metadata().ok(); - match File::open(&path) { + match File::open(path) { Ok(mut file) => { input_service.print_header(input); let mut reader; diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 4aef9b76a..ef0d48c7c 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -220,7 +220,7 @@ fn open(path: &str) -> BufReader> { if path == "-" { BufReader::new(Box::new(stdin()) as Box) } else { - file_buf = match File::open(&path) { + file_buf = match File::open(path) { Ok(a) => a, Err(e) => crash!(1, "{}: {}", path.maybe_quote(), e), }; diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 39d4ecc4a..e2edae335 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -424,7 +424,7 @@ fn open_input_file(in_file_name: &str) -> UResult } else { let path = Path::new(in_file_name); - let in_file = File::open(&path) + let in_file = File::open(path) .map_err_context(|| format!("Could not open {}", in_file_name.maybe_quote()))?; Box::new(in_file) as Box }; @@ -436,7 +436,7 @@ fn open_output_file(out_file_name: &str) -> UResult } else { let path = Path::new(out_file_name); - let out_file = File::create(&path) + let out_file = File::create(path) .map_err_context(|| format!("Could not create {}", out_file_name.maybe_quote()))?; Box::new(out_file) as Box }; diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 2d41db418..42b7edf35 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -355,7 +355,7 @@ pub fn canonicalize>( followed_symlinks += 1; } else { let file_info = - FileInformation::from_path(&result.parent().unwrap(), false).unwrap(); + FileInformation::from_path(result.parent().unwrap(), false).unwrap(); let mut path_to_follow = PathBuf::new(); for part in &parts { path_to_follow.push(part.as_os_str()); diff --git a/tests/by-util/test_base64.rs b/tests/by-util/test_base64.rs index 11d345347..bbb0da5ad 100644 --- a/tests/by-util/test_base64.rs +++ b/tests/by-util/test_base64.rs @@ -76,9 +76,10 @@ fn test_wrap() { #[test] fn test_wrap_no_arg() { for wrap_param in ["-w", "--wrap"] { - new_ucmd!().arg(wrap_param).fails().stderr_contains( - &"The argument '--wrap ' requires a value but none was supplied", - ); + new_ucmd!() + .arg(wrap_param) + .fails() + .stderr_contains("The argument '--wrap ' requires a value but none was supplied"); } } diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index f5bb5c96a..74e8b0921 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -8,7 +8,7 @@ use std::ffi::OsStr; fn test_help() { for help_flg in ["-h", "--help"] { new_ucmd!() - .arg(&help_flg) + .arg(help_flg) .succeeds() .no_stderr() .stdout_contains("USAGE:"); @@ -19,7 +19,7 @@ fn test_help() { fn test_version() { for version_flg in ["-V", "--version"] { assert!(new_ucmd!() - .arg(&version_flg) + .arg(version_flg) .succeeds() .no_stderr() .stdout_str() diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 9eb576f34..fd296ba89 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -380,7 +380,7 @@ fn test_chmod_non_existing_file() { .arg("-r,a+w") .arg("does-not-exist") .fails() - .stderr_contains(&"cannot access 'does-not-exist': No such file or directory"); + .stderr_contains("cannot access 'does-not-exist': No such file or directory"); } #[test] @@ -403,7 +403,7 @@ fn test_chmod_preserve_root() { .arg("755") .arg("/") .fails() - .stderr_contains(&"chmod: it is dangerous to operate recursively on '/'"); + .stderr_contains("chmod: it is dangerous to operate recursively on '/'"); } #[test] diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index c51d5ba69..b54412857 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -107,7 +107,7 @@ fn test_chown_only_owner() { .arg("--verbose") .arg(file1) .run(); - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); // try to change to another existing user, e.g. 'root' scene @@ -116,7 +116,7 @@ fn test_chown_only_owner() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -142,7 +142,7 @@ fn test_chown_only_owner_colon() { .arg("--verbose") .arg(file1) .succeeds() - .stderr_contains(&"retained as"); + .stderr_contains("retained as"); scene .ucmd() @@ -150,7 +150,7 @@ fn test_chown_only_owner_colon() { .arg("--verbose") .arg(file1) .succeeds() - .stderr_contains(&"retained as"); + .stderr_contains("retained as"); scene .ucmd() @@ -158,7 +158,7 @@ fn test_chown_only_owner_colon() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -179,7 +179,7 @@ fn test_chown_only_colon() { if skipping_test_is_okay(&result, "No such id") { return; } - result.stderr_contains(&"retained as"); // TODO: verbose is not printed to stderr in GNU chown + result.stderr_contains("retained as"); // TODO: verbose is not printed to stderr in GNU chown // test chown : file.txt // expected: @@ -192,7 +192,7 @@ fn test_chown_only_colon() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"invalid group: '::'"); + .stderr_contains("invalid group: '::'"); scene .ucmd() @@ -200,7 +200,7 @@ fn test_chown_only_colon() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"invalid group: '..'"); + .stderr_contains("invalid group: '..'"); } #[test] @@ -251,7 +251,7 @@ fn test_chown_owner_group() { if skipping_test_is_okay(&result, "chown: invalid group:") { return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); scene .ucmd() @@ -259,7 +259,7 @@ fn test_chown_owner_group() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"invalid group"); + .stderr_contains("invalid group"); scene .ucmd() @@ -267,7 +267,7 @@ fn test_chown_owner_group() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"invalid group"); + .stderr_contains("invalid group"); // TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root' #[cfg(any(windows, all(unix, not(target_os = "macos"))))] @@ -277,7 +277,7 @@ fn test_chown_owner_group() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -316,7 +316,7 @@ fn test_chown_various_input() { if skipping_test_is_okay(&result, "chown: invalid group:") { return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); // check that username.groupname is understood let result = scene @@ -328,7 +328,7 @@ fn test_chown_various_input() { if skipping_test_is_okay(&result, "chown: invalid group:") { return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); // Fails as user.name doesn't exist in the CI // but it is valid @@ -338,7 +338,7 @@ fn test_chown_various_input() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"chown: invalid user: 'user.name:groupname'"); + .stderr_contains("chown: invalid user: 'user.name:groupname'"); } #[test] @@ -377,7 +377,7 @@ fn test_chown_only_group() { // With mac into the CI, we can get this answer return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); result.success(); scene @@ -386,7 +386,7 @@ fn test_chown_only_group() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -412,7 +412,7 @@ fn test_chown_only_user_id() { // stderr: "chown: invalid user: '1001' return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); scene .ucmd() @@ -420,7 +420,7 @@ fn test_chown_only_user_id() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } /// Test for setting the owner to a user ID for a user that does not exist. @@ -475,7 +475,7 @@ fn test_chown_only_group_id() { // With mac into the CI, we can get this answer return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); // Apparently on CI "macos-latest, x86_64-apple-darwin, feat_os_macos" // the process has the rights to change from runner:staff to runner:wheel @@ -486,7 +486,7 @@ fn test_chown_only_group_id() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } /// Test for setting the group to a group ID for a group that does not exist. @@ -547,7 +547,7 @@ fn test_chown_owner_group_id() { // stderr: "chown: invalid user: '1001:116' return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); let result = scene .ucmd() @@ -560,7 +560,7 @@ fn test_chown_owner_group_id() { // stderr: "chown: invalid user: '1001.116' return; } - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); scene .ucmd() @@ -568,7 +568,7 @@ fn test_chown_owner_group_id() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -603,7 +603,7 @@ fn test_chown_owner_group_mix() { .arg("--verbose") .arg(file1) .run(); - result.stderr_contains(&"retained as"); + result.stderr_contains("retained as"); // TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root' #[cfg(any(windows, all(unix, not(target_os = "macos"))))] @@ -613,7 +613,7 @@ fn test_chown_owner_group_mix() { .arg("--verbose") .arg(file1) .fails() - .stderr_contains(&"failed to change"); + .stderr_contains("failed to change"); } #[test] @@ -643,8 +643,8 @@ fn test_chown_recursive() { .arg("a") .arg("z") .run(); - result.stderr_contains(&"ownership of 'a/a' retained as"); - result.stderr_contains(&"ownership of 'z/y' retained as"); + result.stderr_contains("ownership of 'a/a' retained as"); + result.stderr_contains("ownership of 'z/y' retained as"); } #[test] @@ -665,7 +665,7 @@ fn test_root_preserve() { .arg(user_name) .arg("/") .fails(); - result.stderr_contains(&"chown: it is dangerous to operate recursively"); + result.stderr_contains("chown: it is dangerous to operate recursively"); } #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 252aeb1b7..7598382a6 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -352,7 +352,7 @@ fn test_install_target_new_file_failing_nonexistent_parent() { ucmd.arg(file1) .arg(format!("{}/{}", dir, file2)) .fails() - .stderr_contains(&"No such file or directory"); + .stderr_contains("No such file or directory"); } #[test] diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index a2a88a20a..a7891e737 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -561,8 +561,8 @@ fn test_ls_a() { .arg("-a") .arg("-1") .succeeds() - .stdout_contains(&".test-1") - .stdout_contains(&"..") + .stdout_contains(".test-1") + .stdout_contains("..") .stdout_matches(&re_pwd); scene @@ -590,8 +590,8 @@ fn test_ls_a() { .arg("-1") .arg("some-dir") .succeeds() - .stdout_contains(&".test-2") - .stdout_contains(&"..") + .stdout_contains(".test-2") + .stdout_contains("..") .no_stderr() .stdout_matches(&re_pwd); @@ -1821,7 +1821,7 @@ fn test_ls_files_dirs() { .ucmd() .arg("doesntexist") .fails() - .stderr_contains(&"'doesntexist': No such file or directory"); + .stderr_contains("'doesntexist': No such file or directory"); // One exists, the other doesn't scene @@ -1829,8 +1829,8 @@ fn test_ls_files_dirs() { .arg("a") .arg("doesntexist") .fails() - .stderr_contains(&"'doesntexist': No such file or directory") - .stdout_contains(&"a:"); + .stderr_contains("'doesntexist': No such file or directory") + .stdout_contains("a:"); } #[test] @@ -1851,7 +1851,7 @@ fn test_ls_recursive() { .arg("z") .arg("-R") .succeeds() - .stdout_contains(&"z:"); + .stdout_contains("z:"); let result = scene .ucmd() .arg("--color=never") @@ -1861,7 +1861,7 @@ fn test_ls_recursive() { .succeeds(); #[cfg(not(windows))] - result.stdout_contains(&"a/b:\nb"); + result.stdout_contains("a/b:\nb"); #[cfg(windows)] result.stdout_contains(&"a\\b:\nb"); } @@ -2014,7 +2014,7 @@ fn test_ls_indicator_style() { "-p", ] { // Verify that classify and file-type both contain indicators for symlinks. - scene.ucmd().arg(opt).succeeds().stdout_contains(&"/"); + scene.ucmd().arg(opt).succeeds().stdout_contains("/"); } // Classify, Indicator options should not contain any indicators when value is none. @@ -2030,9 +2030,9 @@ fn test_ls_indicator_style() { .ucmd() .arg(opt) .succeeds() - .stdout_does_not_contain(&"/") - .stdout_does_not_contain(&"@") - .stdout_does_not_contain(&"|"); + .stdout_does_not_contain("/") + .stdout_does_not_contain("@") + .stdout_does_not_contain("|"); } // Classify and File-Type all contain indicators for pipes and links. @@ -2043,8 +2043,8 @@ fn test_ls_indicator_style() { .ucmd() .arg(format!("--indicator-style={}", opt)) .succeeds() - .stdout_contains(&"@") - .stdout_contains(&"|"); + .stdout_contains("@") + .stdout_contains("|"); } // Test sockets. Because the canonical way of making sockets to test is with @@ -2631,7 +2631,7 @@ fn test_ls_ignore_hide() { .arg("--ignore=READ[ME") .arg("-1") .succeeds() - .stderr_contains(&"Invalid pattern") + .stderr_contains("Invalid pattern") .stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n"); scene @@ -2639,7 +2639,7 @@ fn test_ls_ignore_hide() { .arg("--hide=READ[ME") .arg("-1") .succeeds() - .stderr_contains(&"Invalid pattern") + .stderr_contains("Invalid pattern") .stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n"); } diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index 291b56b72..15437b9b2 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -67,7 +67,7 @@ fn test_mknod_fifo_invalid_extra_operand() { .arg("1") .arg("2") .fails() - .stderr_contains(&"Fifos do not have major and minor device numbers"); + .stderr_contains("Fifos do not have major and minor device numbers"); } #[test] @@ -78,28 +78,28 @@ fn test_mknod_character_device_requires_major_and_minor() { .arg("c") .fails() .status_code(1) - .stderr_contains(&"Special files require major and minor device numbers."); + .stderr_contains("Special files require major and minor device numbers."); new_ucmd!() .arg("test_file") .arg("c") .arg("1") .fails() .status_code(1) - .stderr_contains(&"Special files require major and minor device numbers."); + .stderr_contains("Special files require major and minor device numbers."); new_ucmd!() .arg("test_file") .arg("c") .arg("1") .arg("c") .fails() - .stderr_contains(&"Invalid value \"c\" for ''"); + .stderr_contains("Invalid value \"c\" for ''"); new_ucmd!() .arg("test_file") .arg("c") .arg("c") .arg("1") .fails() - .stderr_contains(&"Invalid value \"c\" for ''"); + .stderr_contains("Invalid value \"c\" for ''"); } #[test] @@ -109,7 +109,7 @@ fn test_mknod_invalid_arg() { .arg("--foo") .fails() .no_stdout() - .stderr_contains(&"Found argument '--foo' which wasn't expected"); + .stderr_contains("Found argument '--foo' which wasn't expected"); } #[test] @@ -123,5 +123,5 @@ fn test_mknod_invalid_mode() { .fails() .no_stdout() .status_code(1) - .stderr_contains(&"invalid mode"); + .stderr_contains("invalid mode"); } diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index a5dc49554..00a408d56 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -81,7 +81,7 @@ fn test_2files() { // spell-checker:disable-next-line for (path, data) in [(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] { - let mut f = File::create(&path).unwrap(); + let mut f = File::create(path).unwrap(); assert!( f.write_all(data.as_bytes()).is_ok(), "Test setup failed - could not write file" @@ -133,7 +133,7 @@ fn test_from_mixed() { // spell-checker:disable-next-line let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n"); for (path, data) in [(&file1, data1), (&file3, data3)] { - let mut f = File::create(&path).unwrap(); + let mut f = File::create(path).unwrap(); assert!( f.write_all(data.as_bytes()).is_ok(), "Test setup failed - could not write file" diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 2527f4562..43577f99b 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -282,7 +282,7 @@ fn test_filter_with_env_var_set() { RandomFile::new(&at, name).add_lines(n_lines); let env_var_value = "some-value"; - env::set_var("FILE", &env_var_value); + env::set_var("FILE", env_var_value); ucmd.args(&[format!("--filter={}", "cat > $FILE").as_str(), name]) .succeeds(); diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 54b77d3b4..d37f1a3ba 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -78,7 +78,7 @@ fn test_tee_no_more_writeable_1() { .pipe_in(&content[..]) .fails() .stdout_contains(&content) - .stderr_contains(&"No space left on device"); + .stderr_contains("No space left on device"); assert_eq!(at.read(file_out), content); } diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index 9b4f053ac..db0df44a0 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -31,7 +31,7 @@ fn test_count_bytes_large_stdin() { .args(&["-c"]) .pipe_in(data) .succeeds() - .stdout_is_bytes(&expected.as_bytes()); + .stdout_is_bytes(expected.as_bytes()); } } diff --git a/tests/common/random.rs b/tests/common/random.rs index 36ca3ab4f..0e422572f 100644 --- a/tests/common/random.rs +++ b/tests/common/random.rs @@ -183,25 +183,25 @@ mod tests { #[test] fn test_random_string_generate() { - let random_string = RandomString::generate(&AlphanumericNewline, 0); + let random_string = RandomString::generate(AlphanumericNewline, 0); assert_eq!(0, random_string.len()); - let random_string = RandomString::generate(&AlphanumericNewline, 1); + let random_string = RandomString::generate(AlphanumericNewline, 1); assert_eq!(1, random_string.len()); - let random_string = RandomString::generate(&AlphanumericNewline, 100); + let random_string = RandomString::generate(AlphanumericNewline, 100); assert_eq!(100, random_string.len()); } #[test] fn test_random_string_generate_with_delimiter_when_length_is_zero() { - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 0); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 0); assert_eq!(0, random_string.len()); } #[test] fn test_random_string_generate_with_delimiter_when_num_delimiter_is_greater_than_length() { - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 1); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 1); assert_eq!(1, random_string.len()); assert!(random_string.as_bytes().contains(&0)); assert!(random_string.as_bytes().ends_with(&[0])); @@ -209,7 +209,7 @@ mod tests { #[test] fn test_random_string_generate_with_delimiter_should_end_with_delimiter() { - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 1); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 1); assert_eq!(1, random_string.len()); assert_eq!( 1, @@ -217,7 +217,7 @@ mod tests { ); assert!(random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 1); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 1); assert_eq!(1, random_string.len()); assert_eq!( 1, @@ -225,7 +225,7 @@ mod tests { ); assert!(random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 2); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 2); assert_eq!(2, random_string.len()); assert_eq!( 1, @@ -233,7 +233,7 @@ mod tests { ); assert!(random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, true, 2); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, true, 2); assert_eq!(2, random_string.len()); assert_eq!( 2, @@ -241,7 +241,7 @@ mod tests { ); assert!(random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 3); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 3); assert_eq!(3, random_string.len()); assert_eq!( 1, @@ -252,21 +252,21 @@ mod tests { #[test] fn test_random_string_generate_with_delimiter_should_not_end_with_delimiter() { - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 1); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 1); assert_eq!(1, random_string.len()); assert_eq!( 0, random_string.as_bytes().iter().filter(|p| **p == 0).count() ); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, true, 1); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, true, 1); assert_eq!(1, random_string.len()); assert_eq!( 0, random_string.as_bytes().iter().filter(|p| **p == 0).count() ); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 2); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 2); assert_eq!(2, random_string.len()); assert_eq!( 1, @@ -274,7 +274,7 @@ mod tests { ); assert!(!random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 3); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 3); assert_eq!(3, random_string.len()); assert_eq!( 1, @@ -282,7 +282,7 @@ mod tests { ); assert!(!random_string.as_bytes().ends_with(&[0])); - let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 3); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 3); assert_eq!(3, random_string.len()); assert_eq!( 2, @@ -294,7 +294,7 @@ mod tests { #[test] fn test_generate_with_delimiter_with_greater_length() { let random_string = - RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, false, 1000); + RandomString::generate_with_delimiter(Alphanumeric, 0, 100, false, 1000); assert_eq!(1000, random_string.len()); assert_eq!( 100, @@ -302,8 +302,7 @@ mod tests { ); assert!(!random_string.as_bytes().ends_with(&[0])); - let random_string = - RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, true, 1000); + let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 100, true, 1000); assert_eq!(1000, random_string.len()); assert_eq!( 100, @@ -325,7 +324,7 @@ mod tests { let length = 8192 * 3 + 1; let random_string = - RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 100, true, length); + RandomString::generate_with_delimiter(Alphanumeric, b'\n', 100, true, length); assert_eq!(length, random_string.len()); assert_eq!( 100, diff --git a/tests/common/util.rs b/tests/common/util.rs index b65e6cebf..bdf4ebd20 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -710,7 +710,7 @@ impl AtPath { "symlink", &format!("{},{}", &original, &self.plus_as_string(link)), ); - symlink_file(&original, &self.plus(link)).unwrap(); + symlink_file(original, &self.plus(link)).unwrap(); } pub fn symlink_dir(&self, original: &str, link: &str) { @@ -732,7 +732,7 @@ impl AtPath { "symlink", &format!("{},{}", &original, &self.plus_as_string(link)), ); - symlink_dir(&original, &self.plus(link)).unwrap(); + symlink_dir(original, &self.plus(link)).unwrap(); } pub fn is_symlink(&self, path: &str) -> bool { @@ -1445,7 +1445,7 @@ pub fn run_ucmd_as_root( log_info("run", "sudo -E --non-interactive whoami"); match Command::new("sudo") .env("LC_ALL", "C") - .args(&["-E", "--non-interactive", "whoami"]) + .args(["-E", "--non-interactive", "whoami"]) .output() { Ok(output) if String::from_utf8_lossy(&output.stdout).eq("root\n") => { @@ -1833,7 +1833,7 @@ mod tests { // Skip test if we can't guarantee non-interactive `sudo`, or if we're not "root" if let Ok(output) = Command::new("sudo") .env("LC_ALL", "C") - .args(&["-E", "--non-interactive", "whoami"]) + .args(["-E", "--non-interactive", "whoami"]) .output() { if output.status.success() && String::from_utf8_lossy(&output.stdout).eq("root\n") {