summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2023-07-14 11:47:34 +0200
committerGitHub <noreply@github.com>2023-07-14 11:47:34 +0200
commitec1d2fba33624fe78db0d64d31f70e4b8fefc950 (patch)
tree53182273e633a310db199069bdc09cc6a2eac41a
parent0ee92981c4d541d2cab730566803cdac96f8d0c9 (diff)
parent5d03d2d9d41dcd8292ba0a0a658656bf5032835e (diff)
Merge pull request #5079 from cakebaker/clippy_fix_warnings_rust_1_71_0
clippy: fix warnings introduced by Rust 1.71.0
-rw-r--r--src/uu/csplit/src/csplit.rs206
-rw-r--r--src/uu/fmt/src/parasplit.rs2
-rw-r--r--src/uu/stdbuf/build.rs2
-rw-r--r--src/uucore/src/lib/features/fsext.rs15
-rw-r--r--src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs2
-rw-r--r--src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs2
-rw-r--r--tests/by-util/test_cp.rs4
-rw-r--r--tests/by-util/test_stat.rs6
-rw-r--r--tests/by-util/test_tail.rs2
9 files changed, 118 insertions, 123 deletions
diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs
index 1a94b41565..a5b6c06b04 100644
--- a/src/uu/csplit/src/csplit.rs
+++ b/src/uu/csplit/src/csplit.rs
@@ -552,6 +552,109 @@ where
}
}
+#[uucore::main]
+pub fn uumain(args: impl uucore::Args) -> UResult<()> {
+ let args = args.collect_ignore();
+
+ let matches = uu_app().try_get_matches_from(args)?;
+
+ // get the file to split
+ let file_name = matches.get_one::<String>(options::FILE).unwrap();
+
+ // get the patterns to split on
+ let patterns: Vec<String> = matches
+ .get_many::<String>(options::PATTERN)
+ .unwrap()
+ .map(|s| s.to_string())
+ .collect();
+ let patterns = patterns::get_patterns(&patterns[..])?;
+ let options = CsplitOptions::new(&matches);
+ if file_name == "-" {
+ let stdin = io::stdin();
+ Ok(csplit(&options, patterns, stdin.lock())?)
+ } else {
+ let file = File::open(file_name)
+ .map_err_context(|| format!("cannot access {}", file_name.quote()))?;
+ let file_metadata = file
+ .metadata()
+ .map_err_context(|| format!("cannot access {}", file_name.quote()))?;
+ if !file_metadata.is_file() {
+ return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
+ }
+ Ok(csplit(&options, patterns, BufReader::new(file))?)
+ }
+}
+
+pub fn uu_app() -> Command {
+ Command::new(uucore::util_name())
+ .version(crate_version!())
+ .about(ABOUT)
+ .override_usage(format_usage(USAGE))
+ .infer_long_args(true)
+ .arg(
+ Arg::new(options::SUFFIX_FORMAT)
+ .short('b')
+ .long(options::SUFFIX_FORMAT)
+ .value_name("FORMAT")
+ .help("use sprintf FORMAT instead of %02d"),
+ )
+ .arg(
+ Arg::new(options::PREFIX)
+ .short('f')
+ .long(options::PREFIX)
+ .value_name("PREFIX")
+ .help("use PREFIX instead of 'xx'"),
+ )
+ .arg(
+ Arg::new(options::KEEP_FILES)
+ .short('k')
+ .long(options::KEEP_FILES)
+ .help("do not remove output files on errors")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new(options::SUPPRESS_MATCHED)
+ .long(options::SUPPRESS_MATCHED)
+ .help("suppress the lines matching PATTERN")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new(options::DIGITS)
+ .short('n')
+ .long(options::DIGITS)
+ .value_name("DIGITS")
+ .help("use specified number of digits instead of 2"),
+ )
+ .arg(
+ Arg::new(options::QUIET)
+ .short('s')
+ .long(options::QUIET)
+ .visible_alias("silent")
+ .help("do not print counts of output file sizes")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new(options::ELIDE_EMPTY_FILES)
+ .short('z')
+ .long(options::ELIDE_EMPTY_FILES)
+ .help("remove empty output files")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new(options::FILE)
+ .hide(true)
+ .required(true)
+ .value_hint(clap::ValueHint::FilePath),
+ )
+ .arg(
+ Arg::new(options::PATTERN)
+ .hide(true)
+ .action(clap::ArgAction::Append)
+ .required(true),
+ )
+ .after_help(AFTER_HELP)
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -714,106 +817,3 @@ mod tests {
assert!(input_splitter.next().is_none());
}
}
-
-#[uucore::main]
-pub fn uumain(args: impl uucore::Args) -> UResult<()> {
- let args = args.collect_ignore();
-
- let matches = uu_app().try_get_matches_from(args)?;
-
- // get the file to split
- let file_name = matches.get_one::<String>(options::FILE).unwrap();
-
- // get the patterns to split on
- let patterns: Vec<String> = matches
- .get_many::<String>(options::PATTERN)
- .unwrap()
- .map(|s| s.to_string())
- .collect();
- let patterns = patterns::get_patterns(&patterns[..])?;
- let options = CsplitOptions::new(&matches);
- if file_name == "-" {
- let stdin = io::stdin();
- Ok(csplit(&options, patterns, stdin.lock())?)
- } else {
- let file = File::open(file_name)
- .map_err_context(|| format!("cannot access {}", file_name.quote()))?;
- let file_metadata = file
- .metadata()
- .map_err_context(|| format!("cannot access {}", file_name.quote()))?;
- if !file_metadata.is_file() {
- return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
- }
- Ok(csplit(&options, patterns, BufReader::new(file))?)
- }
-}
-
-pub fn uu_app() -> Command {
- Command::new(uucore::util_name())
- .version(crate_version!())
- .about(ABOUT)
- .override_usage(format_usage(USAGE))
- .infer_long_args(true)
- .arg(
- Arg::new(options::SUFFIX_FORMAT)
- .short('b')
- .long(options::SUFFIX_FORMAT)
- .value_name("FORMAT")
- .help("use sprintf FORMAT instead of %02d"),
- )
- .arg(
- Arg::new(options::PREFIX)
- .short('f')
- .long(options::PREFIX)
- .value_name("PREFIX")
- .help("use PREFIX instead of 'xx'"),
- )
- .arg(
- Arg::new(options::KEEP_FILES)
- .short('k')
- .long(options::KEEP_FILES)
- .help("do not remove output files on errors")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new(options::SUPPRESS_MATCHED)
- .long(options::SUPPRESS_MATCHED)
- .help("suppress the lines matching PATTERN")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new(options::DIGITS)
- .short('n')
- .long(options::DIGITS)
- .value_name("DIGITS")
- .help("use specified number of digits instead of 2"),
- )
- .arg(
- Arg::new(options::QUIET)
- .short('s')
- .long(options::QUIET)
- .visible_alias("silent")
- .help("do not print counts of output file sizes")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new(options::ELIDE_EMPTY_FILES)
- .short('z')
- .long(options::ELIDE_EMPTY_FILES)
- .help("remove empty output files")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new(options::FILE)
- .hide(true)
- .required(true)
- .value_hint(clap::ValueHint::FilePath),
- )
- .arg(
- Arg::new(options::PATTERN)
- .hide(true)
- .action(clap::ArgAction::Append)
- .required(true),
- )
- .after_help(AFTER_HELP)
-}
diff --git a/src/uu/fmt/src/parasplit.rs b/src/uu/fmt/src/parasplit.rs
index a2d70b088e..c94c819740 100644
--- a/src/uu/fmt/src/parasplit.rs
+++ b/src/uu/fmt/src/parasplit.rs
@@ -598,7 +598,7 @@ impl<'a> Iterator for WordSplit<'a> {
self.prev_punct && (before_tab.is_some() || word_start_relative > 1);
// now record whether this word ends in punctuation
- self.prev_punct = match self.string[..self.position].chars().rev().next() {
+ self.prev_punct = match self.string[..self.position].chars().next_back() {
Some(ch) => WordSplit::is_punctuation(ch),
_ => panic!("fatal: expected word not to be empty"),
};
diff --git a/src/uu/stdbuf/build.rs b/src/uu/stdbuf/build.rs
index 9ed9a62072..a8472243a0 100644
--- a/src/uu/stdbuf/build.rs
+++ b/src/uu/stdbuf/build.rs
@@ -9,7 +9,7 @@ mod platform {
pub const DYLIB_EXT: &str = ".so";
}
-#[cfg(any(target_vendor = "apple"))]
+#[cfg(target_vendor = "apple")]
mod platform {
pub const DYLIB_EXT: &str = ".dylib";
}
diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs
index 89f1d6e716..6f831fb922 100644
--- a/src/uucore/src/lib/features/fsext.rs
+++ b/src/uucore/src/lib/features/fsext.rs
@@ -194,15 +194,10 @@ impl MountInfo {
}
#[cfg(unix)]
{
- if self.dev_name.find(':').is_some()
+ self.remote = self.dev_name.find(':').is_some()
|| (self.dev_name.starts_with("//") && self.fs_type == "smbfs"
|| self.fs_type == "cifs")
- || self.dev_name == "-hosts"
- {
- self.remote = true;
- } else {
- self.remote = false;
- }
+ || self.dev_name == "-hosts";
}
}
@@ -371,9 +366,9 @@ extern "C" {
fn get_mount_info(mount_buffer_p: *mut *mut StatFs, flags: c_int) -> c_int;
#[cfg(any(
- all(target_os = "freebsd"),
- all(target_os = "netbsd"),
- all(target_os = "openbsd"),
+ target_os = "freebsd",
+ target_os = "netbsd",
+ target_os = "openbsd",
all(target_vendor = "apple", target_arch = "aarch64")
))]
#[link_name = "getmntinfo"] // spell-checker:disable-line
diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs
index e13629af50..cca2750dc5 100644
--- a/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs
+++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs
@@ -10,7 +10,7 @@ use super::float_common::{get_primitive_dec, primitive_to_str_common, FloatAnaly
pub struct Floatf;
impl Floatf {
pub fn new() -> Self {
- Self::default()
+ Self
}
}
impl Formatter for Floatf {
diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs
index c5b88b5a7f..c871dc4e55 100644
--- a/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs
+++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs
@@ -10,7 +10,7 @@ pub struct Scif;
impl Scif {
pub fn new() -> Self {
- Self::default()
+ Self
}
}
impl Formatter for Scif {
diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs
index 52f7e44301..18f3829a2b 100644
--- a/tests/by-util/test_cp.rs
+++ b/tests/by-util/test_cp.rs
@@ -1337,7 +1337,7 @@ fn test_cp_preserve_all_context_fails_on_non_selinux() {
}
#[test]
-#[cfg(any(target_os = "android"))]
+#[cfg(target_os = "android")]
fn test_cp_preserve_xattr_fails_on_android() {
// Because of the SELinux extended attributes used on Android, trying to copy extended
// attributes has to fail in this case, since we specify `--preserve=xattr` and this puts it
@@ -2768,7 +2768,7 @@ fn test_same_file_force() {
}
/// Test that copying file to itself with forced backup succeeds.
-#[cfg(all(not(windows)))]
+#[cfg(not(windows))]
#[test]
fn test_same_file_force_backup() {
let (at, mut ucmd) = at_and_ucmd!();
diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs
index 2527dc7cdd..92a8bcd988 100644
--- a/tests/by-util/test_stat.rs
+++ b/tests/by-util/test_stat.rs
@@ -178,7 +178,7 @@ fn test_char() {
DEV_FORMAT_STR,
#[cfg(target_os = "linux")]
"/dev/pts/ptmx",
- #[cfg(any(target_vendor = "apple"))]
+ #[cfg(target_vendor = "apple")]
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (/%T) %u %U %W %X %y %Y %z %Z",
#[cfg(any(target_os = "android", target_vendor = "apple"))]
"/dev/ptmx",
@@ -198,7 +198,7 @@ fn test_date() {
"%z",
#[cfg(target_os = "linux")]
"/bin/sh",
- #[cfg(any(target_vendor = "apple"))]
+ #[cfg(target_vendor = "apple")]
"%z",
#[cfg(any(target_os = "android", target_vendor = "apple"))]
"/bin/sh",
@@ -213,7 +213,7 @@ fn test_date() {
"%z",
#[cfg(target_os = "linux")]
"/dev/ptmx",
- #[cfg(any(target_vendor = "apple"))]
+ #[cfg(target_vendor = "apple")]
"%z",
#[cfg(any(target_os = "android", target_vendor = "apple"))]
"/dev/ptmx",
diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs
index dba1df269b..75abb8eb6f 100644
--- a/tests/by-util/test_tail.rs
+++ b/tests/by-util/test_tail.rs
@@ -145,7 +145,7 @@ fn test_stdin_redirect_offset() {
}
#[test]
-#[cfg(all(not(target_vendor = "apple")))] // FIXME: for currently not working platforms
+#[cfg(not(target_vendor = "apple"))] // FIXME: for currently not working platforms
fn test_stdin_redirect_offset2() {
// like test_stdin_redirect_offset but with multiple files