Skip to content

chore: use expect instead of allow #7705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 0 additions & 1 deletion src/bin/coreutils.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@ fn name(binary_path: &Path) -> Option<&str> {
binary_path.file_stem()?.to_str()
}

#[allow(clippy::cognitive_complexity)]
fn main() {
uucore::panic::mute_sigpipe_panic();

1 change: 0 additions & 1 deletion src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ struct Options {
///
/// * `options` - CLI options for the assigning checksum algorithm
/// * `files` - A iterator of OsStr which is a bunch of files that are using for calculating checksum
#[allow(clippy::cognitive_complexity)]
fn cksum<'a, I>(mut options: Options, files: I) -> UResult<()>
where
I: Iterator<Item = &'a OsStr>,
5 changes: 1 addition & 4 deletions src/uu/cp/src/copydir.rs
Original file line number Diff line number Diff line change
@@ -222,7 +222,6 @@ where
path.as_ref().display().to_string().ends_with("/.")
}

#[allow(clippy::too_many_arguments)]
/// Copy a single entry during a directory traversal.
fn copy_direntry(
progress_bar: Option<&ProgressBar>,
@@ -542,12 +541,10 @@ pub fn path_has_prefix(p1: &Path, p2: &Path) -> io::Result<bool> {
/// potentially change. (See `test_dir_perm_race_with_preserve_mode_and_ownership``)
/// - The `recursive` flag determines whether parent directories should be created
/// if they do not already exist.
// we need to allow unused_variable since `options` might be unused in non unix systems
#[allow(unused_variables)]
fn build_dir(
path: &PathBuf,
recursive: bool,
options: &Options,
#[cfg_attr(not(unix), expect(unused_variables))] options: &Options,
copy_attributes_from: Option<&Path>,
) -> CopyResult<()> {
let mut builder = fs::DirBuilder::new();
34 changes: 10 additions & 24 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
@@ -136,27 +136,21 @@
}

/// Possible arguments for `--reflink`.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum ReflinkMode {
Always,
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "macos"),
default
)]
Auto,
#[cfg_attr(
not(any(target_os = "linux", target_os = "android", target_os = "macos")),
default
)]
Never,
}

impl Default for ReflinkMode {
#[allow(clippy::derivable_impls)]
fn default() -> Self {
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
{
ReflinkMode::Auto
}
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))]
{
ReflinkMode::Never
}
}
}

/// Possible arguments for `--sparse`.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum SparseMode {
@@ -252,7 +246,6 @@
/// reason.
///
/// The fields are documented with the arguments that determine their value.
#[allow(dead_code)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Options {
/// `--attributes-only`
@@ -354,9 +347,8 @@

/// Enum representing various debug states of the offload and reflink actions.
#[derive(Debug)]
#[allow(dead_code)] // All of them are used on Linux
enum OffloadReflinkDebug {
Unknown,

Check failure on line 351 in src/uu/cp/src/cp.rs

GitHub Actions / Style and Lint (ubuntu-24.04, unix)

ERROR: `cargo clippy`: variants `Unknown`, `No`, `Yes`, and `Avoided` are never constructed (file:'src/uu/cp/src/cp.rs', line:351)
No,
Yes,
Avoided,
@@ -970,7 +962,6 @@
}

impl Options {
#[allow(clippy::cognitive_complexity)]
fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
let not_implemented_opts = vec![
#[cfg(not(any(windows, unix)))]
@@ -1259,9 +1250,6 @@
};

if options.strip_trailing_slashes {
// clippy::assigning_clones added with Rust 1.78
// Rust version = 1.76 on OpenBSD stable/7.5
#[cfg_attr(not(target_os = "openbsd"), allow(clippy::assigning_clones))]
for source in &mut paths {
*source = source.components().as_path().to_owned();
}
@@ -2165,12 +2153,10 @@
/// * `Ok(Permissions)` - The calculated permissions for the destination file.
/// * `Err(CopyError)` - An error occurred while getting the metadata of the destination file.
///
// Allow unused variables for Windows (on options)
#[allow(unused_variables)]
fn calculate_dest_permissions(
dest: &Path,
source_metadata: &Metadata,
options: &Options,
#[cfg_attr(not(unix), expect(unused_variables))] options: &Options,
context: &str,
) -> CopyResult<Permissions> {
if dest.exists() {
1 change: 0 additions & 1 deletion src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
@@ -358,7 +358,6 @@ impl SplitWriter<'_> {
/// - if no line matched, an [`CsplitError::MatchNotFound`].
/// - if there are not enough lines to accommodate the offset, an
/// [`CsplitError::LineOutOfRange`].
#[allow(clippy::cognitive_complexity)]
fn do_to_match<I>(
&mut self,
pattern_as_str: &str,
1 change: 0 additions & 1 deletion src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
@@ -137,7 +137,6 @@ impl From<&str> for Rfc3339Format {
}

#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

46 changes: 22 additions & 24 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
@@ -453,20 +453,19 @@
/// the input file is no longer needed. If not possible, then this
/// function prints an error message to stderr and sets the exit
/// status code to 1.
#[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))]
#[cfg(target_os = "linux")]
fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) {
#[cfg(target_os = "linux")]
{
show_if_err!(self
.src
show_if_err!(
self.src
.discard_cache(offset, len)
.map_err_context(|| "failed to discard cache for: 'standard input'".to_string()));
}
#[cfg(not(target_os = "linux"))]
{
// TODO Is there a way to discard filesystem cache on
// these other operating systems?
}
.map_err_context(|| "failed to discard cache for: 'standard input'".to_string())
);
}

#[cfg(not(target_os = "linux"))]
fn discard_cache(&self, _offset: libc::off_t, _len: libc::off_t) {

Check failure on line 466 in src/uu/dd/src/dd.rs

GitHub Actions / Style and Lint (ubuntu-24.04, unix)

ERROR: `cargo clippy`: unused `self` argument (file:'src/uu/dd/src/dd.rs', line:466)
// TODO Is there a way to discard filesystem cache on
// these other operating systems?
}

/// Fills a given buffer.
@@ -828,19 +827,19 @@
/// the output file is no longer needed. If not possible, then
/// this function prints an error message to stderr and sets the
/// exit status code to 1.
#[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))]
#[cfg(target_os = "linux")]
fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) {
#[cfg(target_os = "linux")]
{
show_if_err!(self.dst.discard_cache(offset, len).map_err_context(|| {
show_if_err!(
self.dst.discard_cache(offset, len).map_err_context(|| {
"failed to discard cache for: 'standard output'".to_string()
}));
}
#[cfg(not(target_os = "linux"))]
{
// TODO Is there a way to discard filesystem cache on
// these other operating systems?
}
})
);
}

#[cfg(not(target_os = "linux"))]
fn discard_cache(&self, _offset: libc::off_t, _len: libc::off_t) {

Check failure on line 840 in src/uu/dd/src/dd.rs

GitHub Actions / Style and Lint (ubuntu-24.04, unix)

ERROR: `cargo clippy`: unused `self` argument (file:'src/uu/dd/src/dd.rs', line:840)
// TODO Is there a way to discard filesystem cache on
// these other operating systems?
}

/// writes a block of data. optionally retries when first try didn't complete
@@ -1207,7 +1206,6 @@
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(clippy::cognitive_complexity)]
fn make_linux_oflags(oflags: &OFlags) -> Option<libc::c_int> {
let mut flag = 0;

2 changes: 0 additions & 2 deletions src/uu/dd/src/parseargs.rs
Original file line number Diff line number Diff line change
@@ -317,7 +317,6 @@ impl Parser {
}
}

#[allow(clippy::cognitive_complexity)]
fn parse_input_flags(&mut self, val: &str) -> Result<(), ParseError> {
let i = &mut self.iflag;
for f in val.split(',') {
@@ -349,7 +348,6 @@ impl Parser {
Ok(())
}

#[allow(clippy::cognitive_complexity)]
fn parse_output_flags(&mut self, val: &str) -> Result<(), ParseError> {
let o = &mut self.oflag;
for f in val.split(',') {
2 changes: 0 additions & 2 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
@@ -301,7 +301,6 @@ fn read_block_size(s: Option<&str>) -> UResult<u64> {
}

// this takes `my_stat` to avoid having to stat files multiple times.
#[allow(clippy::cognitive_complexity)]
fn du(
mut my_stat: Stat,
options: &TraversalOptions,
@@ -616,7 +615,6 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
}

#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

2 changes: 0 additions & 2 deletions src/uu/env/src/native_int_str.rs
Original file line number Diff line number Diff line change
@@ -144,7 +144,6 @@ pub fn to_native_int_representation(input: &OsStr) -> Cow<'_, NativeIntStr> {
}
}

#[allow(clippy::needless_pass_by_value)] // needed on windows
pub fn from_native_int_representation(input: Cow<'_, NativeIntStr>) -> Cow<'_, OsStr> {
#[cfg(target_os = "windows")]
{
@@ -160,7 +159,6 @@ pub fn from_native_int_representation(input: Cow<'_, NativeIntStr>) -> Cow<'_, O
}
}

#[allow(clippy::needless_pass_by_value)] // needed on windows
pub fn from_native_int_representation_owned(input: NativeIntString) -> OsString {
#[cfg(target_os = "windows")]
{
1 change: 0 additions & 1 deletion src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
@@ -349,7 +349,6 @@ enum CharType {
Other,
}

#[allow(clippy::cognitive_complexity)]
fn expand_line(
buf: &mut Vec<u8>,
output: &mut BufWriter<std::io::Stdout>,
1 change: 0 additions & 1 deletion src/uu/fmt/src/linebreak.rs
Original file line number Diff line number Diff line change
@@ -215,7 +215,6 @@ struct LineBreak<'a> {
fresh: bool,
}

#[allow(clippy::cognitive_complexity)]
fn find_kp_breakpoints<'a, T: Iterator<Item = &'a WordInfo<'a>>>(
iter: T,
args: &BreakArgs<'a>,
1 change: 0 additions & 1 deletion src/uu/fmt/src/parasplit.rs
Original file line number Diff line number Diff line change
@@ -275,7 +275,6 @@ impl ParagraphStream<'_> {
impl Iterator for ParagraphStream<'_> {
type Item = Result<Paragraph, String>;

#[allow(clippy::cognitive_complexity)]
fn next(&mut self) -> Option<Result<Paragraph, String>> {
// return a NoFormatLine in an Err; it should immediately be output
let noformat = match self.lines.peek()? {
1 change: 0 additions & 1 deletion src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
@@ -205,7 +205,6 @@ fn fold_file_bytewise<T: Read>(mut file: BufReader<T>, spaces: bool, width: usiz
///
/// If `spaces` is `true`, attempt to break lines at whitespace boundaries.
#[allow(unused_assignments)]
#[allow(clippy::cognitive_complexity)]
fn fold_file<T: Read>(mut file: BufReader<T>, spaces: bool, width: usize) -> UResult<()> {
let mut line = String::new();
let mut output = String::new();
2 changes: 0 additions & 2 deletions src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
@@ -60,7 +60,6 @@ struct Options {
/// Returns a UResult of a tuple containing the algorithm name, the hasher instance, and
/// the output length in bits or an Err if multiple hash algorithms are specified or if a
/// required flag is missing.
#[allow(clippy::cognitive_complexity)]
fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult<HashAlgorithm> {
let mut alg: Option<HashAlgorithm> = None;

@@ -514,7 +513,6 @@ fn uu_app(binary_name: &str) -> (Command, bool) {
}
}

#[allow(clippy::cognitive_complexity)]
fn hashsum<'a, I>(mut options: Options, files: I) -> UResult<()>
where
I: Iterator<Item = &'a OsStr>,
1 change: 0 additions & 1 deletion src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
@@ -451,7 +451,6 @@ fn head_file(input: &mut File, options: &HeadOptions) -> io::Result<u64> {
}
}

#[allow(clippy::cognitive_complexity)]
fn uu_head(options: &HeadOptions) -> UResult<()> {
let mut first = true;
for file in &options.files {
2 changes: 0 additions & 2 deletions src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
@@ -280,7 +280,6 @@ fn exec(files: &[PathBuf], settings: &Settings) -> UResult<()> {
link(&files[0], &files[1], settings)
}

#[allow(clippy::cognitive_complexity)]
fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) -> UResult<()> {
if !target_dir.is_dir() {
return Err(LnError::TargetIsDirectory(target_dir.to_owned()).into());
@@ -365,7 +364,6 @@ fn relative_path<'a>(src: &'a Path, dst: &Path) -> Cow<'a, Path> {
src.into()
}

#[allow(clippy::cognitive_complexity)]
fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
let mut backup_path = None;
let source: Cow<'_, Path> = if settings.relative {
Loading