Merge pull request #6898 from sylvestre/fix-clipp

Fix new clippy warnings
This commit is contained in:
Daniel Hofstetter
2024-11-29 09:48:21 +01:00
committed by GitHub
27 changed files with 107 additions and 126 deletions
+2 -2
View File
@@ -197,7 +197,7 @@ struct SplitWriter<'a> {
dev_null: bool,
}
impl<'a> Drop for SplitWriter<'a> {
impl Drop for SplitWriter<'_> {
fn drop(&mut self) {
if self.options.elide_empty_files && self.size == 0 {
let file_name = self.options.split_name.get(self.counter);
@@ -206,7 +206,7 @@ impl<'a> Drop for SplitWriter<'a> {
}
}
impl<'a> SplitWriter<'a> {
impl SplitWriter<'_> {
fn new(options: &CsplitOptions) -> SplitWriter {
SplitWriter {
options,
+1 -1
View File
@@ -23,7 +23,7 @@ impl<'a> ExactMatcher<'a> {
}
}
impl<'a> Matcher for ExactMatcher<'a> {
impl Matcher for ExactMatcher<'_> {
fn next_match(&self, haystack: &[u8]) -> Option<(usize, usize)> {
let mut pos = 0usize;
loop {
+1 -1
View File
@@ -27,7 +27,7 @@ impl<'a, 'b, M: Matcher> Searcher<'a, 'b, M> {
// Iterate over field delimiters
// Returns (first, last) positions of each sequence, where `haystack[first..last]`
// corresponds to the delimiter.
impl<'a, 'b, M: Matcher> Iterator for Searcher<'a, 'b, M> {
impl<M: Matcher> Iterator for Searcher<'_, '_, M> {
type Item = (usize, usize);
fn next(&mut self) -> Option<Self::Item> {
+2 -2
View File
@@ -103,7 +103,7 @@ enum Iso8601Format {
Ns,
}
impl<'a> From<&'a str> for Iso8601Format {
impl From<&str> for Iso8601Format {
fn from(s: &str) -> Self {
match s {
HOURS => Self::Hours,
@@ -123,7 +123,7 @@ enum Rfc3339Format {
Ns,
}
impl<'a> From<&'a str> for Rfc3339Format {
impl From<&str> for Rfc3339Format {
fn from(s: &str) -> Self {
match s {
DATE => Self::Date,
+3 -3
View File
@@ -424,7 +424,7 @@ fn make_linux_iflags(iflags: &IFlags) -> Option<libc::c_int> {
}
}
impl<'a> Read for Input<'a> {
impl Read for Input<'_> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut base_idx = 0;
let target_len = buf.len();
@@ -447,7 +447,7 @@ impl<'a> Read for Input<'a> {
}
}
impl<'a> Input<'a> {
impl Input<'_> {
/// Discard the system file cache for the given portion of the input.
///
/// `offset` and `len` specify a contiguous portion of the input.
@@ -928,7 +928,7 @@ enum BlockWriter<'a> {
Unbuffered(Output<'a>),
}
impl<'a> BlockWriter<'a> {
impl BlockWriter<'_> {
fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) {
match self {
Self::Unbuffered(o) => o.discard_cache(offset, len),
+2 -1
View File
@@ -2,7 +2,8 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
/// Functions for formatting a number as a magnitude and a unit suffix.
//! Functions for formatting a number as a magnitude and a unit suffix.
/// The first ten powers of 1024.
const IEC_BASES: [u128; 10] = [
-2
View File
@@ -311,7 +311,6 @@ fn is_best(previous: &[MountInfo], mi: &MountInfo) -> bool {
///
/// Finally, if there are duplicate entries, the one with the shorter
/// path is kept.
fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
let mut result = vec![];
for mi in vmi {
@@ -331,7 +330,6 @@ fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
///
/// `opt` excludes certain filesystems from consideration and allows for the synchronization of filesystems before running; see
/// [`Options`] for more information.
fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
// Run a sync call before any operation if so instructed.
if opt.sync {
+2 -3
View File
@@ -114,10 +114,9 @@ impl<'a> StringParser<'a> {
}
pub fn peek_chunk(&self) -> Option<Chunk<'a>> {
return self
.get_chunk_with_length_at(self.pointer)
self.get_chunk_with_length_at(self.pointer)
.ok()
.map(|(chunk, _)| chunk);
.map(|(chunk, _)| chunk)
}
pub fn consume_chunk(&mut self) -> Result<Chunk<'a>, Error> {
+1 -1
View File
@@ -11,7 +11,7 @@ pub struct VariableParser<'a, 'b> {
pub parser: &'b mut StringParser<'a>,
}
impl<'a, 'b> VariableParser<'a, 'b> {
impl<'a> VariableParser<'a, '_> {
fn get_current_char(&self) -> Option<char> {
self.parser.peek().ok()
}
+1 -1
View File
@@ -20,7 +20,7 @@ struct BreakArgs<'a> {
ostream: &'a mut BufWriter<Stdout>,
}
impl<'a> BreakArgs<'a> {
impl BreakArgs<'_> {
fn compute_width(&self, winfo: &WordInfo, posn: usize, fresh: bool) -> usize {
if fresh {
0
+6 -6
View File
@@ -73,7 +73,7 @@ pub struct FileLines<'a> {
lines: Lines<&'a mut FileOrStdReader>,
}
impl<'a> FileLines<'a> {
impl FileLines<'_> {
fn new<'b>(opts: &'b FmtOptions, lines: Lines<&'b mut FileOrStdReader>) -> FileLines<'b> {
FileLines { opts, lines }
}
@@ -144,7 +144,7 @@ impl<'a> FileLines<'a> {
}
}
impl<'a> Iterator for FileLines<'a> {
impl Iterator for FileLines<'_> {
type Item = Line;
fn next(&mut self) -> Option<Line> {
@@ -232,7 +232,7 @@ pub struct ParagraphStream<'a> {
opts: &'a FmtOptions,
}
impl<'a> ParagraphStream<'a> {
impl ParagraphStream<'_> {
pub fn new<'b>(opts: &'b FmtOptions, reader: &'b mut FileOrStdReader) -> ParagraphStream<'b> {
let lines = FileLines::new(opts, reader.lines()).peekable();
// at the beginning of the file, we might find mail headers
@@ -273,7 +273,7 @@ impl<'a> ParagraphStream<'a> {
}
}
impl<'a> Iterator for ParagraphStream<'a> {
impl Iterator for ParagraphStream<'_> {
type Item = Result<Paragraph, String>;
#[allow(clippy::cognitive_complexity)]
@@ -491,7 +491,7 @@ struct WordSplit<'a> {
prev_punct: bool,
}
impl<'a> WordSplit<'a> {
impl WordSplit<'_> {
fn analyze_tabs(&self, string: &str) -> (Option<usize>, usize, Option<usize>) {
// given a string, determine (length before tab) and (printed length after first tab)
// if there are no tabs, beforetab = -1 and aftertab is the printed length
@@ -517,7 +517,7 @@ impl<'a> WordSplit<'a> {
}
}
impl<'a> WordSplit<'a> {
impl WordSplit<'_> {
fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> {
// wordsplits *must* start at a non-whitespace character
let trim_string = string.trim_start();
+1 -1
View File
@@ -109,7 +109,7 @@ struct MultiByteSep<'a> {
finder: Finder<'a>,
}
impl<'a> Separator for MultiByteSep<'a> {
impl Separator for MultiByteSep<'_> {
fn field_ranges(&self, haystack: &[u8], len_guess: usize) -> Vec<(usize, usize)> {
let mut field_ranges = Vec::with_capacity(len_guess);
let mut last_end = 0;
+4 -4
View File
@@ -33,7 +33,7 @@ where
byte_order: ByteOrder,
}
impl<'a, I> InputDecoder<'a, I> {
impl<I> InputDecoder<'_, I> {
/// Creates a new `InputDecoder` with an allocated buffer of `normal_length` + `peek_length` bytes.
/// `byte_order` determines how to read multibyte formats from the buffer.
pub fn new(
@@ -55,7 +55,7 @@ impl<'a, I> InputDecoder<'a, I> {
}
}
impl<'a, I> InputDecoder<'a, I>
impl<I> InputDecoder<'_, I>
where
I: PeekRead,
{
@@ -81,7 +81,7 @@ where
}
}
impl<'a, I> HasError for InputDecoder<'a, I>
impl<I> HasError for InputDecoder<'_, I>
where
I: HasError,
{
@@ -103,7 +103,7 @@ pub struct MemoryDecoder<'a> {
byte_order: ByteOrder,
}
impl<'a> MemoryDecoder<'a> {
impl MemoryDecoder<'_> {
/// Set a part of the internal buffer to zero.
/// access to the whole buffer is possible, not just to the valid data.
pub fn zero_out_buffer(&mut self, start: usize, end: usize) {
+3 -3
View File
@@ -28,7 +28,7 @@ pub trait HasError {
fn has_error(&self) -> bool;
}
impl<'b> MultifileReader<'b> {
impl MultifileReader<'_> {
pub fn new(fnames: Vec<InputSource>) -> MultifileReader {
let mut mf = MultifileReader {
ni: fnames,
@@ -76,7 +76,7 @@ impl<'b> MultifileReader<'b> {
}
}
impl<'b> io::Read for MultifileReader<'b> {
impl io::Read for MultifileReader<'_> {
// Fill buf with bytes read from the list of files
// Returns Ok(<number of bytes read>)
// Handles io errors itself, thus always returns OK
@@ -113,7 +113,7 @@ impl<'b> io::Read for MultifileReader<'b> {
}
}
impl<'b> HasError for MultifileReader<'b> {
impl HasError for MultifileReader<'_> {
fn has_error(&self) -> bool {
self.any_err
}
+10 -4
View File
@@ -279,7 +279,10 @@ impl<'a> Shufable for Vec<&'a [u8]> {
// this is safe.
(**self).choose(rng).unwrap()
}
type PartialShuffleIterator<'b> = std::iter::Copied<std::slice::Iter<'b, &'a [u8]>> where Self: 'b;
type PartialShuffleIterator<'b>
= std::iter::Copied<std::slice::Iter<'b, &'a [u8]>>
where
Self: 'b;
fn partial_shuffle<'b>(
&'b mut self,
rng: &'b mut WrappedRng,
@@ -298,7 +301,10 @@ impl Shufable for RangeInclusive<usize> {
fn choose(&self, rng: &mut WrappedRng) -> usize {
rng.gen_range(self.clone())
}
type PartialShuffleIterator<'b> = NonrepeatingIterator<'b> where Self: 'b;
type PartialShuffleIterator<'b>
= NonrepeatingIterator<'b>
where
Self: 'b;
fn partial_shuffle<'b>(
&'b mut self,
rng: &'b mut WrappedRng,
@@ -374,7 +380,7 @@ impl<'a> NonrepeatingIterator<'a> {
}
}
impl<'a> Iterator for NonrepeatingIterator<'a> {
impl Iterator for NonrepeatingIterator<'_> {
type Item = usize;
fn next(&mut self) -> Option<usize> {
@@ -401,7 +407,7 @@ trait Writable {
fn write_all_to(&self, output: &mut impl Write) -> Result<(), Error>;
}
impl<'a> Writable for &'a [u8] {
impl Writable for &[u8] {
fn write_all_to(&self, output: &mut impl Write) -> Result<(), Error> {
output.write_all(self)
}
+2 -2
View File
@@ -267,7 +267,7 @@ pub struct FileMerger<'a> {
reader_join_handle: JoinHandle<UResult<()>>,
}
impl<'a> FileMerger<'a> {
impl FileMerger<'_> {
/// Write the merged contents to the output file.
pub fn write_all(self, settings: &GlobalSettings, output: Output) -> UResult<()> {
let mut out = output.into_write();
@@ -341,7 +341,7 @@ struct FileComparator<'a> {
settings: &'a GlobalSettings,
}
impl<'a> Compare<MergeableFile> for FileComparator<'a> {
impl Compare<MergeableFile> for FileComparator<'_> {
fn compare(&self, a: &MergeableFile, b: &MergeableFile) -> Ordering {
let mut cmp = compare_by(
&a.current_chunk.lines()[a.line_idx],
+1 -1
View File
@@ -341,7 +341,7 @@ impl<'a> FilenameIterator<'a> {
}
}
impl<'a> Iterator for FilenameIterator<'a> {
impl Iterator for FilenameIterator<'_> {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
+3 -3
View File
@@ -748,7 +748,7 @@ impl<'a> ByteChunkWriter<'a> {
}
}
impl<'a> Write for ByteChunkWriter<'a> {
impl Write for ByteChunkWriter<'_> {
/// Implements `--bytes=SIZE`
fn write(&mut self, mut buf: &[u8]) -> std::io::Result<usize> {
// If the length of `buf` exceeds the number of bytes remaining
@@ -872,7 +872,7 @@ impl<'a> LineChunkWriter<'a> {
}
}
impl<'a> Write for LineChunkWriter<'a> {
impl Write for LineChunkWriter<'_> {
/// Implements `--lines=NUMBER`
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
// If the number of lines in `buf` exceeds the number of lines
@@ -978,7 +978,7 @@ impl<'a> LineBytesChunkWriter<'a> {
}
}
impl<'a> Write for LineBytesChunkWriter<'a> {
impl Write for LineBytesChunkWriter<'_> {
/// Write as many lines to a chunk as possible without
/// exceeding the byte limit. If a single line has more bytes
/// than the limit, then fill an entire single chunk with those
+1 -1
View File
@@ -64,7 +64,7 @@ impl<'a> ReverseChunks<'a> {
}
}
impl<'a> Iterator for ReverseChunks<'a> {
impl Iterator for ReverseChunks<'_> {
type Item = Vec<u8>;
fn next(&mut self) -> Option<Self::Item> {
-1
View File
@@ -288,7 +288,6 @@ fn preserve_signal_info(signal: libc::c_int) -> libc::c_int {
}
/// TODO: Improve exit codes, and make them consistent with the GNU Coreutils exit codes.
fn timeout(
cmd: &[String],
duration: Duration,

Some files were not shown because too many files have changed in this diff Show More