Skip to content

Commit c5c4ef7

Browse files
committed
chore: use expect instead of allow
The `#[expect(...)]` is usually better than `#[allow(...)]` because it verifies the assumption that disabling a warning is still relevant to the code - thus eliminating the dead code when warning is no longer there. Here I tried to replace most `allow` with `expect`, but kept back any cases which caused an issue - those will have to be dealt one by one.
1 parent 6ea1f52 commit c5c4ef7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+167
-169
lines changed

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn main() {
3030
if val == "1" && key.starts_with(ENV_FEATURE_PREFIX) {
3131
let krate = key[ENV_FEATURE_PREFIX.len()..].to_lowercase();
3232
// Allow this as we have a bunch of info in the comments
33-
#[allow(clippy::match_same_arms)]
33+
#[expect(clippy::match_same_arms)]
3434
match krate.as_ref() {
3535
"default" | "macos" | "unix" | "windows" | "selinux" | "zip" => continue, // common/standard feature names
3636
"nightly" | "test_unimplemented" | "expensive_tests" | "test_risky_names" => {
@@ -51,8 +51,8 @@ pub fn main() {
5151
mf.write_all(
5252
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
5353
\n\
54-
#[allow(clippy::too_many_lines)]
55-
#[allow(clippy::unreadable_literal)]
54+
#[expect(clippy::too_many_lines)]
55+
#[expect(clippy::unreadable_literal)]
5656
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
5757
.as_bytes(),
5858
)

fuzz/fuzz_targets/fuzz_echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn generate_echo() -> String {
2121
// Randomly decide whether to include options
2222
let include_n = rng.random_bool(0.1); // 10% chance
2323
let include_e = rng.random_bool(0.1); // 10% chance
24-
#[allow(non_snake_case)]
24+
#[expect(non_snake_case)]
2525
let include_E = rng.random_bool(0.1); // 10% chance
2626

2727
if include_n {

fuzz/fuzz_targets/fuzz_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::fuzz_common::{
1818
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
1919
};
2020

21-
#[allow(clippy::upper_case_acronyms)]
21+
#[expect(clippy::upper_case_acronyms)]
2222
#[derive(PartialEq, Debug, Clone)]
2323
enum ArgType {
2424
STRING,

src/bin/coreutils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn usage<T>(utils: &UtilityMap<T>, name: &str) {
2626
println!("Options:");
2727
println!(" --list lists all defined functions, one per row\n");
2828
println!("Currently defined functions:\n");
29-
#[allow(clippy::map_clone)]
29+
#[expect(clippy::map_clone)]
3030
let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect();
3131
utils.sort_unstable();
3232
let display_list = utils.join(", ");

src/bin/uudoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
1515

1616
/// # Errors
1717
/// Returns an error if the writer fails.
18-
#[allow(clippy::too_many_lines)]
18+
#[expect(clippy::too_many_lines)]
1919
fn main() -> io::Result<()> {
2020
let mut tldr_zip = File::open("docs/tldr.zip")
2121
.ok()

src/uu/chcon/src/chcon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (vars) RFILE
66
#![cfg(target_os = "linux")]
7-
#![allow(clippy::upper_case_acronyms)]
7+
#![expect(clippy::upper_case_acronyms)]
88

99
use clap::builder::ValueParser;
1010
use uucore::error::{UResult, USimpleError, UUsageError};
@@ -469,7 +469,7 @@ impl From<fs::Metadata> for DeviceAndINode {
469469
impl TryFrom<&libc::stat> for DeviceAndINode {
470470
type Error = Error;
471471

472-
#[allow(clippy::useless_conversion)]
472+
#[expect(clippy::useless_conversion)]
473473
fn try_from(st: &libc::stat) -> Result<Self> {
474474
let device_id = u64::try_from(st.st_dev).map_err(|_r| Error::OutOfRange)?;
475475
let inode = u64::try_from(st.st_ino).map_err(|_r| Error::OutOfRange)?;

src/uu/cp/src/copydir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn copy_direntry(
329329
///
330330
/// Any errors encountered copying files in the tree will be logged but
331331
/// will not cause a short-circuit.
332-
#[allow(clippy::too_many_arguments)]
332+
#[expect(clippy::too_many_arguments)]
333333
pub(crate) fn copy_directory(
334334
progress_bar: &Option<ProgressBar>,
335335
root: &Path,
@@ -579,7 +579,7 @@ fn build_dir(
579579

580580
// we need to allow trivial casts here because some systems like linux have u32 constants in
581581
// in libc while others don't.
582-
#[allow(clippy::unnecessary_cast)]
582+
#[expect(clippy::unnecessary_cast)]
583583
let mut excluded_perms =
584584
if matches!(options.attributes.ownership, crate::Preserve::Yes { .. }) {
585585
libc::S_IRWXG | libc::S_IRWXO // exclude rwx for group and other
@@ -613,7 +613,7 @@ mod tests {
613613
use super::ends_with_slash_dot;
614614

615615
#[test]
616-
#[allow(clippy::cognitive_complexity)]
616+
#[expect(clippy::cognitive_complexity)]
617617
fn test_ends_with_slash_dot() {
618618
assert!(ends_with_slash_dot("/."));
619619
assert!(ends_with_slash_dot("./."));

src/uu/cp/src/cp.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ enum OffloadReflinkDebug {
365365

366366
/// Enum representing various debug states of the sparse detection.
367367
#[derive(Debug)]
368-
#[allow(dead_code)] // silent for now until we use them
368+
#[expect(dead_code)] // silent for now until we use them
369369
enum SparseDebug {
370370
Unknown,
371371
No,
@@ -1431,7 +1431,7 @@ fn construct_dest_path(
14311431
TargetType::File => target.to_path_buf(),
14321432
})
14331433
}
1434-
#[allow(clippy::too_many_arguments)]
1434+
#[expect(clippy::too_many_arguments)]
14351435
fn copy_source(
14361436
progress_bar: &Option<ProgressBar>,
14371437
source: &Path,
@@ -1492,7 +1492,7 @@ fn copy_source(
14921492
// Should this metadata be read once and then reused throughout the execution?
14931493
// https://github.com/uutils/coreutils/issues/6658
14941494
fn file_mode_for_interactive_overwrite(
1495-
#[cfg_attr(not(unix), allow(unused_variables))] path: &Path,
1495+
#[cfg_attr(not(unix), expect(unused_variables))] path: &Path,
14961496
) -> Option<(String, String)> {
14971497
// Retain outer braces to ensure only one branch is included
14981498
{
@@ -1596,7 +1596,7 @@ fn copy_extended_attrs(source: &Path, dest: &Path) -> CopyResult<()> {
15961596

15971597
// Temporarily grant user write if it was read-only.
15981598
if was_readonly {
1599-
#[allow(clippy::permissions_set_readonly_false)]
1599+
#[expect(clippy::permissions_set_readonly_false)]
16001600
perms.set_readonly(false);
16011601
fs::set_permissions(dest, perms)?;
16021602
}
@@ -2017,7 +2017,7 @@ fn print_paths(parents: bool, source: &Path, dest: &Path) {
20172017
///
20182018
/// * `Ok(())` - The file was copied successfully.
20192019
/// * `Err(CopyError)` - An error occurred while copying the file.
2020-
#[allow(clippy::too_many_arguments)]
2020+
#[expect(clippy::too_many_arguments)]
20212021
fn handle_copy_mode(
20222022
source: &Path,
20232023
dest: &Path,
@@ -2203,7 +2203,7 @@ fn calculate_dest_permissions(
22032203
///
22042204
/// The original permissions of `source` will be copied to `dest`
22052205
/// after a successful copy.
2206-
#[allow(clippy::cognitive_complexity, clippy::too_many_arguments)]
2206+
#[expect(clippy::too_many_arguments)]
22072207
fn copy_file(
22082208
progress_bar: &Option<ProgressBar>,
22092209
source: &Path,
@@ -2479,7 +2479,7 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
24792479

24802480
/// Copy the file from `source` to `dest` either using the normal `fs::copy` or a
24812481
/// copy-on-write scheme if --reflink is specified and the filesystem supports it.
2482-
#[allow(clippy::too_many_arguments)]
2482+
#[expect(clippy::too_many_arguments)]
24832483
fn copy_helper(
24842484
source: &Path,
24852485
dest: &Path,

src/uu/cp/src/platform/linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where
6262
let src_fd = src_file.as_raw_fd();
6363
let dst_fd = dst_file.as_raw_fd();
6464
// Using .try_into().unwrap() is required as glibc, musl & android all have different type for ioctl()
65-
#[allow(clippy::unnecessary_fallible_conversions)]
65+
#[expect(clippy::unnecessary_fallible_conversions)]
6666
let result = unsafe {
6767
libc::ioctl(
6868
dst_fd,

src/uu/csplit/src/csplit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
// spell-checker:ignore rustdoc
6-
#![allow(rustdoc::private_intra_doc_links)]
6+
#![expect(rustdoc::private_intra_doc_links)]
77

88
use std::cmp::Ordering;
99
use std::io::{self, BufReader};
@@ -672,7 +672,7 @@ mod tests {
672672
use super::*;
673673

674674
#[test]
675-
#[allow(clippy::cognitive_complexity)]
675+
#[expect(clippy::cognitive_complexity)]
676676
fn input_splitter() {
677677
let input = vec![
678678
Ok(String::from("aaa")),
@@ -745,7 +745,7 @@ mod tests {
745745
}
746746

747747
#[test]
748-
#[allow(clippy::cognitive_complexity)]
748+
#[expect(clippy::cognitive_complexity)]
749749
fn input_splitter_interrupt_rewind() {
750750
let input = vec![
751751
Ok(String::from("aaa")),

0 commit comments

Comments
 (0)