Merge pull request #6468 from cakebaker/clippy_fix_warnings_introduced_by_rust_1_79

clippy: fix warnings introduced by Rust 1.79
This commit is contained in:
Sylvestre Ledru 2024-06-14 12:43:00 +02:00 committed by GitHub
commit f5cdca0674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 19 additions and 29 deletions

View file

@ -259,7 +259,7 @@ fn catch_too_large_numbers_in_backwards_bytes_or_lines(n: u64) -> Option<usize>
fn read_but_last_n_bytes(input: &mut impl std::io::BufRead, n: u64) -> std::io::Result<()> { fn read_but_last_n_bytes(input: &mut impl std::io::BufRead, n: u64) -> std::io::Result<()> {
if n == 0 { if n == 0 {
//prints everything //prints everything
return read_n_bytes(input, std::u64::MAX); return read_n_bytes(input, u64::MAX);
} }
if let Some(n) = catch_too_large_numbers_in_backwards_bytes_or_lines(n) { if let Some(n) = catch_too_large_numbers_in_backwards_bytes_or_lines(n) {

View file

@ -119,12 +119,7 @@ struct Repr<'a> {
} }
impl<'a> Repr<'a> { impl<'a> Repr<'a> {
fn new( fn new(line_ending: LineEnding, separator: u8, format: &'a [Spec], empty: &'a [u8]) -> Self {
line_ending: LineEnding,
separator: u8,
format: &'a [Spec],
empty: &'a [u8],
) -> Repr<'a> {
Repr { Repr {
line_ending, line_ending,
separator, separator,
@ -333,7 +328,7 @@ impl<'a> State<'a> {
key: usize, key: usize,
line_ending: LineEnding, line_ending: LineEnding,
print_unpaired: bool, print_unpaired: bool,
) -> UResult<State<'a>> { ) -> UResult<Self> {
let file_buf = if name == "-" { let file_buf = if name == "-" {
Box::new(stdin.lock()) as Box<dyn BufRead> Box::new(stdin.lock()) as Box<dyn BufRead>
} else { } else {

View file

@ -177,7 +177,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
let fields = if fields.split(&[',', ' ']).any(|x| x == "-") { let fields = if fields.split(&[',', ' ']).any(|x| x == "-") {
vec![Range { vec![Range {
low: 1, low: 1,
high: std::usize::MAX, high: usize::MAX,
}] }]
} else { } else {
Range::from_list(fields)? Range::from_list(fields)?

View file

@ -321,14 +321,10 @@ struct NonrepeatingIterator<'a> {
} }
impl<'a> NonrepeatingIterator<'a> { impl<'a> NonrepeatingIterator<'a> {
fn new( fn new(range: RangeInclusive<usize>, rng: &'a mut WrappedRng, amount: usize) -> Self {
range: RangeInclusive<usize>,
rng: &'a mut WrappedRng,
amount: usize,
) -> NonrepeatingIterator {
let capped_amount = if range.start() > range.end() { let capped_amount = if range.start() > range.end() {
0 0
} else if *range.start() == 0 && *range.end() == std::usize::MAX { } else if *range.start() == 0 && *range.end() == usize::MAX {
amount amount
} else { } else {
amount.min(range.end() - range.start() + 1) amount.min(range.end() - range.start() + 1)
@ -482,7 +478,7 @@ fn parse_range(input_range: &str) -> Result<RangeInclusive<usize>, String> {
} }
fn parse_head_count(headcounts: Vec<String>) -> Result<usize, String> { fn parse_head_count(headcounts: Vec<String>) -> Result<usize, String> {
let mut result = std::usize::MAX; let mut result = usize::MAX;
for count in headcounts { for count in headcounts {
match count.parse::<usize>() { match count.parse::<usize>() {
Ok(pv) => result = std::cmp::min(result, pv), Ok(pv) => result = std::cmp::min(result, pv),

View file

@ -1728,8 +1728,8 @@ fn general_f64_parse(a: &str) -> GeneralF64ParseResult {
// TODO: Once our minimum supported Rust version is 1.53 or above, we should add tests for those cases. // TODO: Once our minimum supported Rust version is 1.53 or above, we should add tests for those cases.
match a.parse::<f64>() { match a.parse::<f64>() {
Ok(a) if a.is_nan() => GeneralF64ParseResult::NaN, Ok(a) if a.is_nan() => GeneralF64ParseResult::NaN,
Ok(a) if a == std::f64::NEG_INFINITY => GeneralF64ParseResult::NegInfinity, Ok(a) if a == f64::NEG_INFINITY => GeneralF64ParseResult::NegInfinity,
Ok(a) if a == std::f64::INFINITY => GeneralF64ParseResult::Infinity, Ok(a) if a == f64::INFINITY => GeneralF64ParseResult::Infinity,
Ok(a) => GeneralF64ParseResult::Number(a), Ok(a) => GeneralF64ParseResult::Number(a),
Err(_) => GeneralF64ParseResult::Invalid, Err(_) => GeneralF64ParseResult::Invalid,
} }

View file

@ -316,7 +316,7 @@ pub struct FilenameIterator<'a> {
} }
impl<'a> FilenameIterator<'a> { impl<'a> FilenameIterator<'a> {
pub fn new(prefix: &'a str, suffix: &'a Suffix) -> UResult<FilenameIterator<'a>> { pub fn new(prefix: &'a str, suffix: &'a Suffix) -> UResult<Self> {
let radix = suffix.stype.radix(); let radix = suffix.stype.radix();
let number = if suffix.auto_widening { let number = if suffix.auto_widening {
Number::DynamicWidth(DynamicWidthNumber::new(radix, suffix.start)) Number::DynamicWidth(DynamicWidthNumber::new(radix, suffix.start))

View file

@ -20,7 +20,6 @@ use std::fs::{metadata, File};
use std::io; use std::io;
use std::io::{stdin, BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write}; use std::io::{stdin, BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write};
use std::path::Path; use std::path::Path;
use std::u64;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError};
use uucore::parse_size::parse_size_u64; use uucore::parse_size::parse_size_u64;
@ -729,7 +728,7 @@ struct ByteChunkWriter<'a> {
} }
impl<'a> ByteChunkWriter<'a> { impl<'a> ByteChunkWriter<'a> {
fn new(chunk_size: u64, settings: &'a Settings) -> UResult<ByteChunkWriter<'a>> { fn new(chunk_size: u64, settings: &'a Settings) -> UResult<Self> {
let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?; let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?;
let filename = filename_iterator let filename = filename_iterator
.next() .next()
@ -853,7 +852,7 @@ struct LineChunkWriter<'a> {
} }
impl<'a> LineChunkWriter<'a> { impl<'a> LineChunkWriter<'a> {
fn new(chunk_size: u64, settings: &'a Settings) -> UResult<LineChunkWriter<'a>> { fn new(chunk_size: u64, settings: &'a Settings) -> UResult<Self> {
let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?; let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?;
let filename = filename_iterator let filename = filename_iterator
.next() .next()
@ -959,7 +958,7 @@ struct LineBytesChunkWriter<'a> {
} }
impl<'a> LineBytesChunkWriter<'a> { impl<'a> LineBytesChunkWriter<'a> {
fn new(chunk_size: u64, settings: &'a Settings) -> UResult<LineBytesChunkWriter<'a>> { fn new(chunk_size: u64, settings: &'a Settings) -> UResult<Self> {
let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?; let mut filename_iterator = FilenameIterator::new(&settings.prefix, &settings.suffix)?;
let filename = filename_iterator let filename = filename_iterator
.next() .next()

View file

@ -46,7 +46,7 @@ pub struct ReverseChunks<'a> {
} }
impl<'a> ReverseChunks<'a> { impl<'a> ReverseChunks<'a> {
pub fn new(file: &'a mut File) -> ReverseChunks<'a> { pub fn new(file: &'a mut File) -> Self {
let current = if cfg!(unix) { let current = if cfg!(unix) {
file.stream_position().unwrap() file.stream_position().unwrap()
} else { } else {

View file

@ -391,7 +391,7 @@ pub struct DigestWriter<'a> {
} }
impl<'a> DigestWriter<'a> { impl<'a> DigestWriter<'a> {
pub fn new(digest: &'a mut Box<dyn Digest>, binary: bool) -> DigestWriter { pub fn new(digest: &'a mut Box<dyn Digest>, binary: bool) -> Self {
let was_last_character_carriage_return = false; let was_last_character_carriage_return = false;
DigestWriter { DigestWriter {
digest, digest,

View file

@ -158,7 +158,7 @@ fn test_range_repeat_no_overflow_1_max() {
#[test] #[test]
fn test_range_repeat_no_overflow_0_max_minus_1() { fn test_range_repeat_no_overflow_0_max_minus_1() {
let upper_bound = std::usize::MAX - 1; let upper_bound = usize::MAX - 1;
let result = new_ucmd!() let result = new_ucmd!()
.arg("-rn1") .arg("-rn1")
.arg(&format!("-i0-{upper_bound}")) .arg(&format!("-i0-{upper_bound}"))
@ -176,7 +176,7 @@ fn test_range_repeat_no_overflow_0_max_minus_1() {
#[test] #[test]
fn test_range_permute_no_overflow_1_max() { fn test_range_permute_no_overflow_1_max() {
let upper_bound = std::usize::MAX; let upper_bound = usize::MAX;
let result = new_ucmd!() let result = new_ucmd!()
.arg("-n1") .arg("-n1")
.arg(&format!("-i1-{upper_bound}")) .arg(&format!("-i1-{upper_bound}"))
@ -194,7 +194,7 @@ fn test_range_permute_no_overflow_1_max() {
#[test] #[test]
fn test_range_permute_no_overflow_0_max_minus_1() { fn test_range_permute_no_overflow_0_max_minus_1() {
let upper_bound = std::usize::MAX - 1; let upper_bound = usize::MAX - 1;
let result = new_ucmd!() let result = new_ucmd!()
.arg("-n1") .arg("-n1")
.arg(&format!("-i0-{upper_bound}")) .arg(&format!("-i0-{upper_bound}"))
@ -215,7 +215,7 @@ fn test_range_permute_no_overflow_0_max() {
// NOTE: This is different from GNU shuf! // NOTE: This is different from GNU shuf!
// GNU shuf accepts -i0-MAX-1 and -i1-MAX, but not -i0-MAX. // GNU shuf accepts -i0-MAX-1 and -i1-MAX, but not -i0-MAX.
// This feels like a bug in GNU shuf. // This feels like a bug in GNU shuf.
let upper_bound = std::usize::MAX; let upper_bound = usize::MAX;
let result = new_ucmd!() let result = new_ucmd!()
.arg("-n1") .arg("-n1")
.arg(&format!("-i0-{upper_bound}")) .arg(&format!("-i0-{upper_bound}"))