From 30f300c52b55d3750c09a705ae432bc380fb60b6 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 7 Aug 2025 14:44:10 +0200 Subject: [PATCH] clippy: fix "hiding a lifetime" warnings from mismatched_lifetime_syntaxes lint --- src/uu/chcon/src/chcon.rs | 2 +- src/uu/chcon/src/fts.rs | 2 +- src/uu/cp/src/copydir.rs | 2 +- src/uu/csplit/src/csplit.rs | 2 +- src/uu/cut/src/cut.rs | 2 +- src/uu/od/src/input_decoder.rs | 4 ++-- src/uu/od/src/od.rs | 2 +- src/uu/od/src/output_info.rs | 2 +- src/uu/runcon/src/runcon.rs | 2 +- src/uu/sort/src/chunks.rs | 5 +++-- src/uu/sort/src/merge.rs | 2 +- src/uu/stat/src/stat.rs | 2 +- src/uu/stty/src/stty.rs | 6 +++--- src/uu/tail/src/follow/files.rs | 2 +- src/uu/wc/src/utf8/read.rs | 2 +- src/uu/wc/src/wc.rs | 2 +- src/uucore/src/lib/features/checksum.rs | 2 +- src/uucore/src/lib/lib.rs | 2 +- tests/by-util/test_env.rs | 2 +- tests/uutests/src/lib/util.rs | 6 +++--- 20 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 754f1c270..ca65cf4a7 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 c9a8599fa..b60ac7d3a 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 f05777cb4..ee9de9ebd 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 c04ed12e4..ba58479b2 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 b57f23cd5..4bf323507 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/od/src/input_decoder.rs b/src/uu/od/src/input_decoder.rs index 6ecf5f86c..a65e7613b 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 48b84ef1f..7db53b6b6 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 dc6a964d4..38218cde8 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/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index 2f98cb7de..3dfa5cc0c 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 5ac330c18..934a20a66 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 2183517b9..1e538c6d9 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/stat/src/stat.rs b/src/uu/stat/src/stat.rs index ebc50ed0f..6bc0aa0b3 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 a3c8706a2..5de8f9e36 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 8043201ef..af9ed39d4 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 07c8593a1..518248bda 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 5b5c2189e..920f4602f 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 6f134ab4e..0dfd4c84f 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); diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 7519e6025..ab28d657b 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 a4319b71f..82cec1889 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 18a7c048a..40784e3df 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"))]