Skip to content

Commit

Permalink
Merge pull request #7111 from cakebaker/clippy_fix_errors_rust_1_84
Browse files Browse the repository at this point in the history
clippy: fix errors introduced with Rust `1.84`
  • Loading branch information
sylvestre authored Jan 10, 2025
2 parents cef9a2b + 51f4bfa commit 505da7e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ multiple_crate_versions = "allow"
cargo_common_metadata = "allow"
uninlined_format_args = "allow"
missing_panics_doc = "allow"
# TODO remove when https://github.com/rust-lang/rust-clippy/issues/13774 is fixed
large_stack_arrays = "allow"

use_self = "warn"
needless_pass_by_value = "warn"
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl Options {
if backup_mode != BackupMode::NoBackup
&& matches
.get_one::<String>(update_control::arguments::OPT_UPDATE)
.map_or(false, |v| v == "none" || v == "none-fail")
.is_some_and(|v| v == "none" || v == "none-fail")
{
return Err(Error::InvalidArgument(
"--backup is mutually exclusive with -n or --update=none-fail".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cp/src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) fn copy_on_write(
// clonefile(2) fails if the destination exists. Remove it and try again. Do not
// bother to check if removal worked because we're going to try to clone again.
// first lets make sure the dest file is not read only
if fs::metadata(dest).map_or(false, |md| !md.permissions().readonly()) {
if fs::metadata(dest).is_ok_and(|md| !md.permissions().readonly()) {
// remove and copy again
// TODO: rewrite this to better match linux behavior
// linux first opens the source file and destination file then uses the file
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ pub fn path_ends_with_terminator(path: &Path) -> bool {
path.as_os_str()
.encode_wide()
.last()
.map_or(false, |wide| wide == b'/'.into() || wide == b'\\'.into())
.is_some_and(|wide| wide == b'/'.into() || wide == b'\\'.into())
}

/// Checks if the standard input (stdin) is a directory.
Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ fn test_cp_sparse_always_non_empty() {
const BUFFER_SIZE: usize = 4096 * 16 + 3;
let (at, mut ucmd) = at_and_ucmd!();

let mut buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
let mut buf = vec![0; BUFFER_SIZE].into_boxed_slice();
let blocks_to_touch = [buf.len() / 3, 2 * (buf.len() / 3)];

for i in blocks_to_touch {
Expand All @@ -2540,7 +2540,7 @@ fn test_cp_sparse_always_non_empty() {
let touched_block_count =
blocks_to_touch.len() as u64 * at.metadata("dst_file_sparse").blksize() / 512;

assert_eq!(at.read_bytes("dst_file_sparse"), buf);
assert_eq!(at.read_bytes("dst_file_sparse").into_boxed_slice(), buf);
assert_eq!(at.metadata("dst_file_sparse").blocks(), touched_block_count);
}

Expand Down
52 changes: 31 additions & 21 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,16 @@ fn test_ls_long() {
let at = &scene.fixtures;
at.touch(at.plus_as_string("test-long"));

#[cfg(not(windows))]
let regex = r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*";
#[cfg(windows)]
let regex = r"[-dl](r[w-]x){3}.*";

let re = &Regex::new(regex).unwrap();

for arg in LONG_ARGS {
let result = scene.ucmd().arg(arg).arg("test-long").succeeds();
#[cfg(not(windows))]
result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap());

#[cfg(windows)]
result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap());
result.stdout_matches(re);
}
}

Expand All @@ -1115,23 +1118,30 @@ fn test_ls_long_format() {
at.touch(at.plus_as_string("test-long-dir/test-long-file"));
at.mkdir(at.plus_as_string("test-long-dir/test-long-dir"));

for arg in LONG_ARGS {
// Assuming sane username do not have spaces within them.
// A line of the output should be:
// One of the characters -bcCdDlMnpPsStTx?
// rwx, with - for missing permissions, thrice.
// Zero or one "." for indicating a file with security context
// A number, preceded by column whitespace, and followed by a single space.
// A username, currently [^ ], followed by column whitespace, twice (or thrice for Hurd).
// A number, followed by a single space.
// A month, followed by a single space.
// A day, preceded by column whitespace, and followed by a single space.
// Either a year or a time, currently [0-9:]+, preceded by column whitespace,
// and followed by a single space.
// Whatever comes after is irrelevant to this specific test.
scene.ucmd().arg(arg).arg("test-long-dir").succeeds().stdout_matches(&Regex::new(
// Assuming sane username do not have spaces within them.
// A line of the output should be:
// One of the characters -bcCdDlMnpPsStTx?
// rwx, with - for missing permissions, thrice.
// Zero or one "." for indicating a file with security context
// A number, preceded by column whitespace, and followed by a single space.
// A username, currently [^ ], followed by column whitespace, twice (or thrice for Hurd).
// A number, followed by a single space.
// A month, followed by a single space.
// A day, preceded by column whitespace, and followed by a single space.
// Either a year or a time, currently [0-9:]+, preceded by column whitespace,
// and followed by a single space.
// Whatever comes after is irrelevant to this specific test.
let re = &Regex::new(
r"\n[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}\.? +\d+ [^ ]+ +[^ ]+( +[^ ]+)? +\d+ [A-Z][a-z]{2} {0,2}\d{0,2} {0,2}[0-9:]+ "
).unwrap());
).unwrap();

for arg in LONG_ARGS {
scene
.ucmd()
.arg(arg)
.arg("test-long-dir")
.succeeds()
.stdout_matches(re);
}

// This checks for the line with the .. entry. The uname and group should be digits.
Expand Down

0 comments on commit 505da7e

Please sign in to comment.