diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 754f1c2703a..ca65cf4a7c2 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -794,7 +794,7 @@ enum SELinuxSecurityContext<'t> { } impl SELinuxSecurityContext<'_> { - fn to_c_string(&self) -> Result>> { + fn to_c_string(&self) -> Result>> { match self { Self::File(context) => context .to_c_string() diff --git a/src/uu/chcon/src/fts.rs b/src/uu/chcon/src/fts.rs index c9a8599fa2a..b60ac7d3ace 100644 --- a/src/uu/chcon/src/fts.rs +++ b/src/uu/chcon/src/fts.rs @@ -61,7 +61,7 @@ impl FTS { }) } - pub(crate) fn last_entry_ref(&mut self) -> Option { + pub(crate) fn last_entry_ref(&mut self) -> Option> { self.entry.map(move |entry| EntryRef::new(self, entry)) } diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index f05777cb485..ee9de9ebdf8 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -34,7 +34,7 @@ use crate::{ /// Ensure a Windows path starts with a `\\?`. #[cfg(target_os = "windows")] -fn adjust_canonicalization(p: &Path) -> Cow { +fn adjust_canonicalization(p: &Path) -> Cow<'_, Path> { // In some cases, \\? can be missing on some Windows paths. Add it at the // beginning unless the path is prefixed with a device namespace. const VERBATIM_PREFIX: &str = r"\\?"; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index c04ed12e437..ba58479b2fe 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -239,7 +239,7 @@ impl Drop for SplitWriter<'_> { } impl SplitWriter<'_> { - fn new(options: &CsplitOptions) -> SplitWriter { + fn new(options: &CsplitOptions) -> SplitWriter<'_> { SplitWriter { options, counter: 0, diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index b57f23cd55e..4bf323507aa 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -404,7 +404,7 @@ fn cut_files(mut filenames: Vec, mode: &Mode) { /// Get delimiter and output delimiter from `-d`/`--delimiter` and `--output-delimiter` options respectively /// Allow either delimiter to have a value that is neither UTF-8 nor ASCII to align with GNU behavior -fn get_delimiters(matches: &ArgMatches) -> UResult<(Delimiter, Option<&[u8]>)> { +fn get_delimiters(matches: &ArgMatches) -> UResult<(Delimiter<'_>, Option<&[u8]>)> { let whitespace_delimited = matches.get_flag(options::WHITESPACE_DELIMITED); let delim_opt = matches.get_one::(options::DELIMITER); let delim = match delim_opt { diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 7bc5757a037..6c8a1ee7af8 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -688,7 +688,7 @@ mod tests { fn test_different_dev_id() { let m1 = mount_info("0", "/mnt/bar"); let m2 = mount_info("1", "/mnt/bar"); - assert!(is_best(&[m1.clone()], &m2)); + assert!(is_best(std::slice::from_ref(&m1), &m2)); assert!(is_best(&[m2], &m1)); } @@ -699,7 +699,7 @@ mod tests { // one condition in this test. let m1 = mount_info("0", "/mnt/bar"); let m2 = mount_info("0", "/mnt/bar/baz"); - assert!(!is_best(&[m1.clone()], &m2)); + assert!(!is_best(std::slice::from_ref(&m1), &m2)); assert!(is_best(&[m2], &m1)); } } diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 10717c6590a..ac1948c516c 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -362,11 +362,13 @@ fn behavior(matches: &ArgMatches) -> UResult { } // Check if compare is used with non-permission mode bits - if compare && specified_mode.is_some() { - let mode = specified_mode.unwrap(); - let non_permission_bits = 0o7000; // setuid, setgid, sticky bits - if mode & non_permission_bits != 0 { - show_error!("{}", translate!("install-warning-compare-ignored")); + // TODO use a let chain once we have a MSRV of 1.88 or greater + if compare { + if let Some(mode) = specified_mode { + let non_permission_bits = 0o7000; // setuid, setgid, sticky bits + if mode & non_permission_bits != 0 { + show_error!("{}", translate!("install-warning-compare-ignored")); + } } } diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 90d0e0f7851..6008770b73e 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -198,20 +198,17 @@ impl Params { // Get the start and end indices of the randomized part of the template. // // For example, if the template is "abcXXXXyz", then `i` is 3 and `j` is 7. - let (i, j) = match find_last_contiguous_block_of_xs(&options.template) { - None => { - let s = match options.suffix { - // If a suffix is specified, the error message includes the template without the suffix. - Some(_) => options - .template - .chars() - .take(options.template.len()) - .collect::(), - None => options.template, - }; - return Err(MkTempError::TooFewXs(s)); - } - Some(indices) => indices, + let Some((i, j)) = find_last_contiguous_block_of_xs(&options.template) else { + let s = match options.suffix { + // If a suffix is specified, the error message includes the template without the suffix. + Some(_) => options + .template + .chars() + .take(options.template.len()) + .collect::(), + None => options.template, + }; + return Err(MkTempError::TooFewXs(s)); }; // Combine the directory given as an option and the prefix of the template. diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 4aa1a47f348..92dc510b5be 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -143,9 +143,8 @@ fn find_stdout() -> UResult { Ok(t) } Err(e1) => { - let home = match env::var("HOME") { - Err(_) => return Err(NohupError::OpenFailed(internal_failure_code, e1).into()), - Ok(h) => h, + let Ok(home) = env::var("HOME") else { + return Err(NohupError::OpenFailed(internal_failure_code, e1).into()); }; let mut homeout = PathBuf::from(home); homeout.push(NOHUP_OUT); diff --git a/src/uu/od/src/formatter_item_info.rs b/src/uu/od/src/formatter_item_info.rs index 89cd645273b..e530a0a3e89 100644 --- a/src/uu/od/src/formatter_item_info.rs +++ b/src/uu/od/src/formatter_item_info.rs @@ -7,6 +7,7 @@ use std::fmt; #[allow(clippy::enum_variant_names)] +#[allow(unpredictable_function_pointer_comparisons)] #[derive(Clone, Copy, PartialEq, Eq)] pub enum FormatWriter { IntWriter(fn(u64) -> String), diff --git a/src/uu/od/src/input_decoder.rs b/src/uu/od/src/input_decoder.rs index 6ecf5f86cf4..a65e7613ba5 100644 --- a/src/uu/od/src/input_decoder.rs +++ b/src/uu/od/src/input_decoder.rs @@ -44,7 +44,7 @@ impl InputDecoder<'_, I> { normal_length: usize, peek_length: usize, byte_order: ByteOrder, - ) -> InputDecoder { + ) -> InputDecoder<'_, I> { let bytes = vec![0; normal_length + peek_length]; InputDecoder { @@ -64,7 +64,7 @@ where { /// calls `peek_read` on the internal stream to (re)fill the buffer. Returns a /// `MemoryDecoder` providing access to the result or returns an i/o error. - pub fn peek_read(&mut self) -> io::Result { + pub fn peek_read(&mut self) -> io::Result> { match self .input .peek_read(self.data.as_mut_slice(), self.reserved_peek_length) diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 48b84ef1f90..7db53b6b6f9 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -603,7 +603,7 @@ fn open_input_peek_reader( input_strings: &[String], skip_bytes: u64, read_bytes: Option, -) -> PeekReader>> { +) -> PeekReader>>> { // should return "impl PeekRead + Read + HasError" when supported in (stable) rust let inputs = input_strings .iter() diff --git a/src/uu/od/src/output_info.rs b/src/uu/od/src/output_info.rs index dc6a964d42e..38218cde8b0 100644 --- a/src/uu/od/src/output_info.rs +++ b/src/uu/od/src/output_info.rs @@ -47,7 +47,7 @@ pub struct OutputInfo { impl OutputInfo { /// Returns an iterator over the `SpacedFormatterItemInfo` vector. - pub fn spaced_formatters_iter(&self) -> Iter { + pub fn spaced_formatters_iter(&self) -> Iter<'_, SpacedFormatterItemInfo> { self.spaced_formatters.iter() } diff --git a/src/uu/od/src/prn_float.rs b/src/uu/od/src/prn_float.rs index 37059e226d8..2e1ff698800 100644 --- a/src/uu/od/src/prn_float.rs +++ b/src/uu/od/src/prn_float.rs @@ -120,7 +120,7 @@ fn format_float(f: f64, width: usize, precision: usize) -> String { } else if l == -1 { format!("{f:width$.precision$}") } else { - return format_f64_exp_precision(f, width, precision - 1); // subnormal numbers + format_f64_exp_precision(f, width, precision - 1) // subnormal numbers } } diff --git a/src/uu/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index 2f98cb7de1b..3dfa5cc0c9e 100644 --- a/src/uu/runcon/src/runcon.rs +++ b/src/uu/runcon/src/runcon.rs @@ -282,7 +282,7 @@ fn get_plain_context(context: &OsStr) -> Result { .map_err(|r| Error::from_selinux("runcon-operation-creating-context", r)) } -fn get_transition_context(command: &OsStr) -> Result { +fn get_transition_context(command: &OsStr) -> Result> { // Generate context based on process transition. let sec_class = SecurityClass::from_name("process") .map_err(|r| Error::from_selinux("runcon-operation-getting-process-class", r))?; diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 5ac330c1802..934a20a665e 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -88,10 +88,11 @@ impl Chunk { } } - pub fn lines(&self) -> &Vec { + pub fn lines(&self) -> &Vec> { &self.borrow_dependent().lines } - pub fn line_data(&self) -> &LineData { + + pub fn line_data(&self) -> &LineData<'_> { &self.borrow_dependent().line_data } } diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index 2183517b975..1e538c6d931 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -144,7 +144,7 @@ pub fn merge_with_file_limit< fn merge_without_limit>>( files: F, settings: &GlobalSettings, -) -> UResult { +) -> UResult> { let (request_sender, request_receiver) = channel(); let mut reader_files = Vec::with_capacity(files.size_hint().0); let mut loaded_receivers = Vec::with_capacity(files.size_hint().0); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index ca4eb4e8443..b8351c31efb 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -630,9 +630,9 @@ where } else if input == "-" { // STDIN stream that did not fit all content into a buffer // Most likely continuous/infinite input stream - return Err(io::Error::other( + Err(io::Error::other( translate!("split-error-cannot-determine-input-size", "input" => input), - )); + )) } else { // Could be that file size is larger than set read limit // Get the file size from filesystem metadata @@ -655,9 +655,9 @@ where // Give up and return an error // TODO It might be possible to do more here // to address all possible file types and edge cases - return Err(io::Error::other( + Err(io::Error::other( translate!("split-error-cannot-determine-file-size", "input" => input), - )); + )) } } } diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index ebc50ed0f5e..6bc0aa0b3e9 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -228,7 +228,7 @@ impl ScanUtil for str { } } -fn group_num(s: &str) -> Cow { +fn group_num(s: &str) -> Cow<'_, str> { let is_negative = s.starts_with('-'); assert!(is_negative || s.chars().take(1).all(|c| c.is_ascii_digit())); assert!(s.chars().skip(1).all(|c| c.is_ascii_digit())); diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index a3c8706a2db..5de8f9e36c7 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -564,7 +564,7 @@ fn string_to_combo(arg: &str) -> Option<&str> { .map(|_| arg) } -fn string_to_baud(arg: &str) -> Option { +fn string_to_baud(arg: &str) -> Option> { // BSDs use a u32 for the baud rate, so any decimal number applies. #[cfg(any( target_os = "freebsd", @@ -595,7 +595,7 @@ fn string_to_baud(arg: &str) -> Option { } /// return `Some(flag)` if the input is a valid flag, `None` if not -fn string_to_flag(option: &str) -> Option { +fn string_to_flag(option: &str) -> Option> { let remove = option.starts_with('-'); let name = option.trim_start_matches('-'); @@ -868,7 +868,7 @@ fn string_to_control_char(s: &str) -> Result { } // decomposes a combination argument into a vec of corresponding flags -fn combo_to_flags(combo: &str) -> Vec { +fn combo_to_flags(combo: &str) -> Vec> { let mut flags = Vec::new(); let mut ccs = Vec::new(); match combo { diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index 8043201efef..af9ed39d4eb 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -74,7 +74,7 @@ impl FileHandling { self.get_mut(path).metadata.as_ref() } - pub fn keys(&self) -> Keys { + pub fn keys(&self) -> Keys<'_, PathBuf, PathData> { self.map.keys() } diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index 07c8593a1da..518248bdac1 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -46,7 +46,7 @@ impl BufReadDecoder { /// except that decoded chunks borrow the decoder (~iterator) /// so they need to be handled or copied before the next chunk can start decoding. #[allow(clippy::cognitive_complexity)] - pub fn next_strict(&mut self) -> Option> { + pub fn next_strict(&mut self) -> Option>> { enum BytesSource { BufRead(usize), Incomplete, diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 5b5c2189ee8..920f4602f64 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -242,7 +242,7 @@ impl<'a> Input<'a> { } /// Converts input to title that appears in stats. - fn to_title(&self) -> Option> { + fn to_title(&self) -> Option> { match self { Self::Path(path) => { let path = path.as_os_str(); diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 6f134ab4e2f..7030987945d 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -701,7 +701,7 @@ fn get_filename_for_output(filename: &OsStr, input_is_stdin: bool) -> String { fn get_expected_digest_as_hex_string( line_info: &LineInfo, len_hint: Option, -) -> Option> { +) -> Option> { let ck = &line_info.checksum; let against_hint = |len| len_hint.is_none_or(|l| l == len); @@ -989,7 +989,7 @@ fn process_checksum_line( process_non_algo_based_line(i, &line_info, cli_algo, cli_algo_length, opts) } else { // We have no clue of what algorithm to use - return Err(LineCheckError::ImproperlyFormatted); + Err(LineCheckError::ImproperlyFormatted) } } diff --git a/src/uucore/src/lib/features/selinux.rs b/src/uucore/src/lib/features/selinux.rs index 939210ae810..3e692905327 100644 --- a/src/uucore/src/lib/features/selinux.rs +++ b/src/uucore/src/lib/features/selinux.rs @@ -474,58 +474,54 @@ mod tests { let result = get_selinux_security_context(path, false); - if result.is_ok() { - let context = result.unwrap(); - println!("Retrieved SELinux context: {context}"); - - assert!( - is_selinux_enabled(), - "Got a successful context result but SELinux is not enabled" - ); + match result { + Ok(context) => { + println!("Retrieved SELinux context: {context}"); - if !context.is_empty() { assert!( - context.contains(':'), - "SELinux context '{context}' doesn't match expected format" + is_selinux_enabled(), + "Got a successful context result but SELinux is not enabled" ); - } - } else { - let err = result.unwrap_err(); - match err { - SeLinuxError::SELinuxNotEnabled => { + if !context.is_empty() { assert!( - !is_selinux_enabled(), - "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true" - ); - } - SeLinuxError::ContextRetrievalFailure(e) => { - assert!( - is_selinux_enabled(), - "Got ContextRetrievalFailure when SELinux is not enabled" - ); - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context retrieval failure: {e}"); - } - SeLinuxError::ContextConversionFailure(ctx, e) => { - assert!( - is_selinux_enabled(), - "Got ContextConversionFailure when SELinux is not enabled" - ); - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context conversion failure for '{ctx}': {e}"); - } - SeLinuxError::ContextSetFailure(ctx, e) => { - assert!(!e.is_empty(), "Error message should not be empty"); - println!("Context conversion failure for '{ctx}': {e}"); - } - SeLinuxError::FileOpenFailure(e) => { - assert!( - Path::new(path).exists(), - "File open failure occurred despite file being created: {e}" + context.contains(':'), + "SELinux context '{context}' doesn't match expected format" ); } } + Err(SeLinuxError::SELinuxNotEnabled) => { + assert!( + !is_selinux_enabled(), + "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true" + ); + } + Err(SeLinuxError::ContextRetrievalFailure(e)) => { + assert!( + is_selinux_enabled(), + "Got ContextRetrievalFailure when SELinux is not enabled" + ); + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context retrieval failure: {e}"); + } + Err(SeLinuxError::ContextConversionFailure(ctx, e)) => { + assert!( + is_selinux_enabled(), + "Got ContextConversionFailure when SELinux is not enabled" + ); + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context conversion failure for '{ctx}': {e}"); + } + Err(SeLinuxError::ContextSetFailure(ctx, e)) => { + assert!(!e.is_empty(), "Error message should not be empty"); + println!("Context conversion failure for '{ctx}': {e}"); + } + Err(SeLinuxError::FileOpenFailure(e)) => { + assert!( + Path::new(path).exists(), + "File open failure occurred despite file being created: {e}" + ); + } } } diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 7519e602513..ab28d657b4e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -344,7 +344,7 @@ pub fn os_str_as_bytes(os_string: &OsStr) -> Result<&[u8], NonUtf8OsStrError> { /// /// This is always lossless on unix platforms, /// and wraps [`OsStr::to_string_lossy`] on non-unix platforms. -pub fn os_str_as_bytes_lossy(os_string: &OsStr) -> Cow<[u8]> { +pub fn os_str_as_bytes_lossy(os_string: &OsStr) -> Cow<'_, [u8]> { #[cfg(unix)] return Cow::from(os_string.as_bytes()); diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index a4319b71ff4..82cec188976 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -1009,7 +1009,7 @@ mod tests_split_iterator { /// /// It tries to avoid introducing any unnecessary quotes or escape characters, /// but specifics regarding quoting style are left unspecified. - pub fn quote(s: &str) -> std::borrow::Cow { + pub fn quote(s: &str) -> std::borrow::Cow<'_, str> { // We are going somewhat out of the way to provide // minimal amount of quoting in typical cases. match escape_style(s) { diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 18a7c048af7..40784e3df1b 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -2318,12 +2318,12 @@ impl UChild { } /// Return a [`UChildAssertion`] - pub fn make_assertion(&mut self) -> UChildAssertion { + pub fn make_assertion(&mut self) -> UChildAssertion<'_> { UChildAssertion::new(self) } /// Convenience function for calling [`UChild::delay`] and then [`UChild::make_assertion`] - pub fn make_assertion_with_delay(&mut self, millis: u64) -> UChildAssertion { + pub fn make_assertion_with_delay(&mut self, millis: u64) -> UChildAssertion<'_> { self.delay(millis).make_assertion() } @@ -2879,7 +2879,7 @@ pub fn whoami() -> String { /// Add prefix 'g' for `util_name` if not on linux #[cfg(unix)] -pub fn host_name_for(util_name: &str) -> Cow { +pub fn host_name_for(util_name: &str) -> Cow<'_, str> { // In some environments, e.g. macOS/freebsd, the GNU coreutils are prefixed with "g" // to not interfere with the BSD counterparts already in `$PATH`. #[cfg(not(target_os = "linux"))]