mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2293 from miDeb/maint-minrustv
maint: adapt code to new MinRustV
This commit is contained in:
commit
a2143dcfbf
13 changed files with 46 additions and 79 deletions
|
@ -124,12 +124,7 @@ where
|
||||||
// split the file based on patterns
|
// split the file based on patterns
|
||||||
for pattern in patterns.into_iter() {
|
for pattern in patterns.into_iter() {
|
||||||
let pattern_as_str = pattern.to_string();
|
let pattern_as_str = pattern.to_string();
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
let is_skip = matches!(pattern, patterns::Pattern::SkipToMatch(_, _, _));
|
||||||
let is_skip = if let patterns::Pattern::SkipToMatch(_, _, _) = pattern {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
match pattern {
|
match pattern {
|
||||||
patterns::Pattern::UpToLine(n, ex) => {
|
patterns::Pattern::UpToLine(n, ex) => {
|
||||||
let mut up_to_line = n;
|
let mut up_to_line = n;
|
||||||
|
|
|
@ -63,12 +63,7 @@ impl Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn is_a_close_paren(&self) -> bool {
|
fn is_a_close_paren(&self) -> bool {
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
matches!(*self, Token::ParClose)
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
|
||||||
match *self {
|
|
||||||
Token::ParClose => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,12 +264,9 @@ impl<'a> ParagraphStream<'a> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
l_slice[..colon_posn]
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
.chars()
|
||||||
l_slice[..colon_posn].chars().all(|x| match x as usize {
|
.all(|x| !matches!(x as usize, y if !(33..=126).contains(&y)))
|
||||||
y if !(33..=126).contains(&y) => false,
|
|
||||||
_ => true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,12 +538,7 @@ impl<'a> WordSplit<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_punctuation(c: char) -> bool {
|
fn is_punctuation(c: char) -> bool {
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
matches!(c, '!' | '.' | '?')
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
|
||||||
match c {
|
|
||||||
'!' | '.' | '?' => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,23 @@ struct Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_custom_binary(program: &str) -> bool {
|
fn is_custom_binary(program: &str) -> bool {
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
matches!(
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
program,
|
||||||
match program {
|
"md5sum"
|
||||||
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum"
|
| "sha1sum"
|
||||||
| "sha3sum" | "sha3-224sum" | "sha3-256sum" | "sha3-384sum" | "sha3-512sum"
|
| "sha224sum"
|
||||||
| "shake128sum" | "shake256sum" | "b2sum" => true,
|
| "sha256sum"
|
||||||
_ => false,
|
| "sha384sum"
|
||||||
}
|
| "sha512sum"
|
||||||
|
| "sha3sum"
|
||||||
|
| "sha3-224sum"
|
||||||
|
| "sha3-256sum"
|
||||||
|
| "sha3-384sum"
|
||||||
|
| "sha3-512sum"
|
||||||
|
| "shake128sum"
|
||||||
|
| "shake256sum"
|
||||||
|
| "b2sum"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
|
|
|
@ -210,21 +210,14 @@ pub fn dry_exec(mut tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str) ->
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(
|
fn exec(dir: PathBuf, prefix: &str, rand: usize, suffix: &str, make_dir: bool, quiet: bool) -> i32 {
|
||||||
dir: PathBuf,
|
|
||||||
prefix: &str,
|
|
||||||
rand: usize,
|
|
||||||
suffix: &str,
|
|
||||||
make_dir: bool,
|
|
||||||
quiet: bool,
|
|
||||||
) -> i32 {
|
|
||||||
let res = if make_dir {
|
let res = if make_dir {
|
||||||
let tmpdir = Builder::new()
|
let tmpdir = Builder::new()
|
||||||
.prefix(prefix)
|
.prefix(prefix)
|
||||||
.rand_bytes(rand)
|
.rand_bytes(rand)
|
||||||
.suffix(suffix)
|
.suffix(suffix)
|
||||||
.tempdir_in(&dir);
|
.tempdir_in(&dir);
|
||||||
|
|
||||||
// `into_path` consumes the TempDir without removing it
|
// `into_path` consumes the TempDir without removing it
|
||||||
tmpdir.map(|d| d.into_path().to_string_lossy().to_string())
|
tmpdir.map(|d| d.into_path().to_string_lossy().to_string())
|
||||||
} else {
|
} else {
|
||||||
|
@ -233,7 +226,7 @@ fn exec(
|
||||||
.rand_bytes(rand)
|
.rand_bytes(rand)
|
||||||
.suffix(suffix)
|
.suffix(suffix)
|
||||||
.tempfile_in(&dir);
|
.tempfile_in(&dir);
|
||||||
|
|
||||||
match tmpfile {
|
match tmpfile {
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
// `keep` ensures that the file is not deleted
|
// `keep` ensures that the file is not deleted
|
||||||
|
@ -245,7 +238,7 @@ fn exec(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(x) => Err(x)
|
Err(x) => Err(x),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,12 +85,7 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option<FormatterItemI
|
||||||
}
|
}
|
||||||
|
|
||||||
fn od_argument_with_option(ch: char) -> bool {
|
fn od_argument_with_option(ch: char) -> bool {
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
matches!(ch, 'A' | 'j' | 'N' | 'S' | 'w')
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
|
||||||
match ch {
|
|
||||||
'A' | 'j' | 'N' | 'S' | 'w' => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses format flags from command line
|
/// Parses format flags from command line
|
||||||
|
|
|
@ -386,13 +386,8 @@ fn prompt(msg: &str) -> bool {
|
||||||
let stdin = stdin();
|
let stdin = stdin();
|
||||||
let mut stdin = stdin.lock();
|
let mut stdin = stdin.lock();
|
||||||
|
|
||||||
#[allow(clippy::match_like_matches_macro)]
|
|
||||||
// `matches!(...)` macro not stabilized until rust v1.42
|
|
||||||
match stdin.read_until(b'\n', &mut buf) {
|
match stdin.read_until(b'\n', &mut buf) {
|
||||||
Ok(x) if x > 0 => match buf[0] {
|
Ok(x) if x > 0 => matches!(buf[0], b'y' | b'Y'),
|
||||||
b'y' | b'Y' => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,12 @@ const MIN_BUFFER_SIZE: usize = 8_000;
|
||||||
|
|
||||||
/// Sort files by using auxiliary files for storing intermediate chunks (if needed), and output the result.
|
/// Sort files by using auxiliary files for storing intermediate chunks (if needed), and output the result.
|
||||||
pub fn ext_sort(files: &mut impl Iterator<Item = Box<dyn Read + Send>>, settings: &GlobalSettings) {
|
pub fn ext_sort(files: &mut impl Iterator<Item = Box<dyn Read + Send>>, settings: &GlobalSettings) {
|
||||||
let tmp_dir = crash_if_err!(1, tempfile::Builder::new().prefix("uutils_sort").tempdir_in(&settings.tmp_dir));
|
let tmp_dir = crash_if_err!(
|
||||||
|
1,
|
||||||
|
tempfile::Builder::new()
|
||||||
|
.prefix("uutils_sort")
|
||||||
|
.tempdir_in(&settings.tmp_dir)
|
||||||
|
);
|
||||||
let (sorted_sender, sorted_receiver) = std::sync::mpsc::sync_channel(1);
|
let (sorted_sender, sorted_receiver) = std::sync::mpsc::sync_channel(1);
|
||||||
let (recycled_sender, recycled_receiver) = std::sync::mpsc::sync_channel(1);
|
let (recycled_sender, recycled_receiver) = std::sync::mpsc::sync_channel(1);
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
|
|
|
@ -68,10 +68,10 @@ impl NumInfo {
|
||||||
}
|
}
|
||||||
first_char = false;
|
first_char = false;
|
||||||
|
|
||||||
if parse_settings
|
if matches!(
|
||||||
.thousands_separator
|
parse_settings.thousands_separator,
|
||||||
.map_or(false, |c| c == char)
|
Some(c) if c == char
|
||||||
{
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -583,11 +583,10 @@ impl FieldSelector {
|
||||||
is_default_selection: from.field == 1
|
is_default_selection: from.field == 1
|
||||||
&& from.char == 1
|
&& from.char == 1
|
||||||
&& to.is_none()
|
&& to.is_none()
|
||||||
// TODO: Once our MinRustV is 1.42 or higher, change this to the matches! macro
|
&& !matches!(
|
||||||
&& match settings.mode {
|
settings.mode,
|
||||||
SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric => false,
|
SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric
|
||||||
_ => true,
|
),
|
||||||
},
|
|
||||||
needs_tokens: from.field != 1 || from.char == 0 || to.is_some(),
|
needs_tokens: from.field != 1 || from.char == 0 || to.is_some(),
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
@ -650,7 +649,7 @@ impl FieldSelector {
|
||||||
tokens: Option<&[Field]>,
|
tokens: Option<&[Field]>,
|
||||||
position: &KeyPosition,
|
position: &KeyPosition,
|
||||||
) -> Resolution {
|
) -> Resolution {
|
||||||
if tokens.map_or(false, |fields| fields.len() < position.field) {
|
if matches!(tokens, Some(tokens) if tokens.len() < position.field) {
|
||||||
Resolution::TooHigh
|
Resolution::TooHigh
|
||||||
} else if position.char == 0 {
|
} else if position.char == 0 {
|
||||||
let end = tokens.unwrap()[position.field - 1].end;
|
let end = tokens.unwrap()[position.field - 1].end;
|
||||||
|
|
|
@ -25,8 +25,7 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
static ABOUT: &str =
|
static ABOUT: &str =
|
||||||
"Run COMMAND, with modified buffering operations for its standard streams.\n\n\
|
"Run COMMAND, with modified buffering operations for its standard streams.\n\n\
|
||||||
Mandatory arguments to long options are mandatory for short options too.";
|
Mandatory arguments to long options are mandatory for short options too.";
|
||||||
static LONG_HELP: &str =
|
static LONG_HELP: &str = "If MODE is 'L' the corresponding stream will be line buffered.\n\
|
||||||
"If MODE is 'L' the corresponding stream will be line buffered.\n\
|
|
||||||
This option is invalid with standard input.\n\n\
|
This option is invalid with standard input.\n\n\
|
||||||
If MODE is '0' the corresponding stream will be unbuffered.\n\n\
|
If MODE is '0' the corresponding stream will be unbuffered.\n\n\
|
||||||
Otherwise MODE is a number which may be followed by one of the following:\n\n\
|
Otherwise MODE is a number which may be followed by one of the following:\n\n\
|
||||||
|
|
|
@ -121,13 +121,7 @@ impl Parser {
|
||||||
/// Test if the next token in the stream is a BOOLOP (-a or -o), without
|
/// Test if the next token in the stream is a BOOLOP (-a or -o), without
|
||||||
/// removing the token from the stream.
|
/// removing the token from the stream.
|
||||||
fn peek_is_boolop(&mut self) -> bool {
|
fn peek_is_boolop(&mut self) -> bool {
|
||||||
// TODO: change to `matches!(self.peek(), Symbol::BoolOp(_))` once MSRV is 1.42
|
matches!(self.peek(), Symbol::BoolOp(_))
|
||||||
// #[allow(clippy::match_like_matches_macro)] // needs MSRV 1.43
|
|
||||||
if let Symbol::BoolOp(_) = self.peek() {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an expression.
|
/// Parse an expression.
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#![allow(dead_code)] // work-around for GH:rust-lang/rust#62127; maint: can be removed when MinSRV >= v1.38.0
|
|
||||||
#![allow(unused_macros)] // work-around for GH:rust-lang/rust#62127; maint: can be removed when MinSRV >= v1.38.0
|
|
||||||
|
|
||||||
// Copyright (C) ~ Roy Ivy III <rivy.dev@gmail.com>; MIT license
|
// Copyright (C) ~ Roy Ivy III <rivy.dev@gmail.com>; MIT license
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
@ -44,7 +41,6 @@ impl syn::parse::Parse for Tokens {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
#[cfg(not(test))] // work-around for GH:rust-lang/rust#62127; maint: can be removed when MinSRV >= v1.38.0
|
|
||||||
pub fn main(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn main(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
let Tokens { expr } = syn::parse_macro_input!(stream as Tokens);
|
let Tokens { expr } = syn::parse_macro_input!(stream as Tokens);
|
||||||
proc_dbg!(&expr);
|
proc_dbg!(&expr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue