Skip to content

Commit ec1d2fb

Browse files
authored
Merge pull request #5079 from cakebaker/clippy_fix_warnings_rust_1_71_0
clippy: fix warnings introduced by Rust 1.71.0
2 parents 0ee9298 + 5d03d2d commit ec1d2fb

File tree

9 files changed

+118
-123
lines changed

9 files changed

+118
-123
lines changed

src/uu/csplit/src/csplit.rs

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,109 @@ where
552552
}
553553
}
554554

555+
#[uucore::main]
556+
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
557+
let args = args.collect_ignore();
558+
559+
let matches = uu_app().try_get_matches_from(args)?;
560+
561+
// get the file to split
562+
let file_name = matches.get_one::<String>(options::FILE).unwrap();
563+
564+
// get the patterns to split on
565+
let patterns: Vec<String> = matches
566+
.get_many::<String>(options::PATTERN)
567+
.unwrap()
568+
.map(|s| s.to_string())
569+
.collect();
570+
let patterns = patterns::get_patterns(&patterns[..])?;
571+
let options = CsplitOptions::new(&matches);
572+
if file_name == "-" {
573+
let stdin = io::stdin();
574+
Ok(csplit(&options, patterns, stdin.lock())?)
575+
} else {
576+
let file = File::open(file_name)
577+
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
578+
let file_metadata = file
579+
.metadata()
580+
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
581+
if !file_metadata.is_file() {
582+
return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
583+
}
584+
Ok(csplit(&options, patterns, BufReader::new(file))?)
585+
}
586+
}
587+
588+
pub fn uu_app() -> Command {
589+
Command::new(uucore::util_name())
590+
.version(crate_version!())
591+
.about(ABOUT)
592+
.override_usage(format_usage(USAGE))
593+
.infer_long_args(true)
594+
.arg(
595+
Arg::new(options::SUFFIX_FORMAT)
596+
.short('b')
597+
.long(options::SUFFIX_FORMAT)
598+
.value_name("FORMAT")
599+
.help("use sprintf FORMAT instead of %02d"),
600+
)
601+
.arg(
602+
Arg::new(options::PREFIX)
603+
.short('f')
604+
.long(options::PREFIX)
605+
.value_name("PREFIX")
606+
.help("use PREFIX instead of 'xx'"),
607+
)
608+
.arg(
609+
Arg::new(options::KEEP_FILES)
610+
.short('k')
611+
.long(options::KEEP_FILES)
612+
.help("do not remove output files on errors")
613+
.action(ArgAction::SetTrue),
614+
)
615+
.arg(
616+
Arg::new(options::SUPPRESS_MATCHED)
617+
.long(options::SUPPRESS_MATCHED)
618+
.help("suppress the lines matching PATTERN")
619+
.action(ArgAction::SetTrue),
620+
)
621+
.arg(
622+
Arg::new(options::DIGITS)
623+
.short('n')
624+
.long(options::DIGITS)
625+
.value_name("DIGITS")
626+
.help("use specified number of digits instead of 2"),
627+
)
628+
.arg(
629+
Arg::new(options::QUIET)
630+
.short('s')
631+
.long(options::QUIET)
632+
.visible_alias("silent")
633+
.help("do not print counts of output file sizes")
634+
.action(ArgAction::SetTrue),
635+
)
636+
.arg(
637+
Arg::new(options::ELIDE_EMPTY_FILES)
638+
.short('z')
639+
.long(options::ELIDE_EMPTY_FILES)
640+
.help("remove empty output files")
641+
.action(ArgAction::SetTrue),
642+
)
643+
.arg(
644+
Arg::new(options::FILE)
645+
.hide(true)
646+
.required(true)
647+
.value_hint(clap::ValueHint::FilePath),
648+
)
649+
.arg(
650+
Arg::new(options::PATTERN)
651+
.hide(true)
652+
.action(clap::ArgAction::Append)
653+
.required(true),
654+
)
655+
.after_help(AFTER_HELP)
656+
}
657+
555658
#[cfg(test)]
556659
mod tests {
557660
use super::*;
@@ -714,106 +817,3 @@ mod tests {
714817
assert!(input_splitter.next().is_none());
715818
}
716819
}
717-
718-
#[uucore::main]
719-
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
720-
let args = args.collect_ignore();
721-
722-
let matches = uu_app().try_get_matches_from(args)?;
723-
724-
// get the file to split
725-
let file_name = matches.get_one::<String>(options::FILE).unwrap();
726-
727-
// get the patterns to split on
728-
let patterns: Vec<String> = matches
729-
.get_many::<String>(options::PATTERN)
730-
.unwrap()
731-
.map(|s| s.to_string())
732-
.collect();
733-
let patterns = patterns::get_patterns(&patterns[..])?;
734-
let options = CsplitOptions::new(&matches);
735-
if file_name == "-" {
736-
let stdin = io::stdin();
737-
Ok(csplit(&options, patterns, stdin.lock())?)
738-
} else {
739-
let file = File::open(file_name)
740-
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
741-
let file_metadata = file
742-
.metadata()
743-
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
744-
if !file_metadata.is_file() {
745-
return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
746-
}
747-
Ok(csplit(&options, patterns, BufReader::new(file))?)
748-
}
749-
}
750-
751-
pub fn uu_app() -> Command {
752-
Command::new(uucore::util_name())
753-
.version(crate_version!())
754-
.about(ABOUT)
755-
.override_usage(format_usage(USAGE))
756-
.infer_long_args(true)
757-
.arg(
758-
Arg::new(options::SUFFIX_FORMAT)
759-
.short('b')
760-
.long(options::SUFFIX_FORMAT)
761-
.value_name("FORMAT")
762-
.help("use sprintf FORMAT instead of %02d"),
763-
)
764-
.arg(
765-
Arg::new(options::PREFIX)
766-
.short('f')
767-
.long(options::PREFIX)
768-
.value_name("PREFIX")
769-
.help("use PREFIX instead of 'xx'"),
770-
)
771-
.arg(
772-
Arg::new(options::KEEP_FILES)
773-
.short('k')
774-
.long(options::KEEP_FILES)
775-
.help("do not remove output files on errors")
776-
.action(ArgAction::SetTrue),
777-
)
778-
.arg(
779-
Arg::new(options::SUPPRESS_MATCHED)
780-
.long(options::SUPPRESS_MATCHED)
781-
.help("suppress the lines matching PATTERN")
782-
.action(ArgAction::SetTrue),
783-
)
784-
.arg(
785-
Arg::new(options::DIGITS)
786-
.short('n')
787-
.long(options::DIGITS)
788-
.value_name("DIGITS")
789-
.help("use specified number of digits instead of 2"),
790-
)
791-
.arg(
792-
Arg::new(options::QUIET)
793-
.short('s')
794-
.long(options::QUIET)
795-
.visible_alias("silent")
796-
.help("do not print counts of output file sizes")
797-
.action(ArgAction::SetTrue),
798-
)
799-
.arg(
800-
Arg::new(options::ELIDE_EMPTY_FILES)
801-
.short('z')
802-
.long(options::ELIDE_EMPTY_FILES)
803-
.help("remove empty output files")
804-
.action(ArgAction::SetTrue),
805-
)
806-
.arg(
807-
Arg::new(options::FILE)
808-
.hide(true)
809-
.required(true)
810-
.value_hint(clap::ValueHint::FilePath),
811-
)
812-
.arg(
813-
Arg::new(options::PATTERN)
814-
.hide(true)
815-
.action(clap::ArgAction::Append)
816-
.required(true),
817-
)
818-
.after_help(AFTER_HELP)
819-
}

src/uu/fmt/src/parasplit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl<'a> Iterator for WordSplit<'a> {
598598
self.prev_punct && (before_tab.is_some() || word_start_relative > 1);
599599

600600
// now record whether this word ends in punctuation
601-
self.prev_punct = match self.string[..self.position].chars().rev().next() {
601+
self.prev_punct = match self.string[..self.position].chars().next_back() {
602602
Some(ch) => WordSplit::is_punctuation(ch),
603603
_ => panic!("fatal: expected word not to be empty"),
604604
};

src/uu/stdbuf/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod platform {
99
pub const DYLIB_EXT: &str = ".so";
1010
}
1111

12-
#[cfg(any(target_vendor = "apple"))]
12+
#[cfg(target_vendor = "apple")]
1313
mod platform {
1414
pub const DYLIB_EXT: &str = ".dylib";
1515
}

src/uucore/src/lib/features/fsext.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,10 @@ impl MountInfo {
194194
}
195195
#[cfg(unix)]
196196
{
197-
if self.dev_name.find(':').is_some()
197+
self.remote = self.dev_name.find(':').is_some()
198198
|| (self.dev_name.starts_with("//") && self.fs_type == "smbfs"
199199
|| self.fs_type == "cifs")
200-
|| self.dev_name == "-hosts"
201-
{
202-
self.remote = true;
203-
} else {
204-
self.remote = false;
205-
}
200+
|| self.dev_name == "-hosts";
206201
}
207202
}
208203

@@ -371,9 +366,9 @@ extern "C" {
371366
fn get_mount_info(mount_buffer_p: *mut *mut StatFs, flags: c_int) -> c_int;
372367

373368
#[cfg(any(
374-
all(target_os = "freebsd"),
375-
all(target_os = "netbsd"),
376-
all(target_os = "openbsd"),
369+
target_os = "freebsd",
370+
target_os = "netbsd",
371+
target_os = "openbsd",
377372
all(target_vendor = "apple", target_arch = "aarch64")
378373
))]
379374
#[link_name = "getmntinfo"] // spell-checker:disable-line

src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::float_common::{get_primitive_dec, primitive_to_str_common, FloatAnaly
1010
pub struct Floatf;
1111
impl Floatf {
1212
pub fn new() -> Self {
13-
Self::default()
13+
Self
1414
}
1515
}
1616
impl Formatter for Floatf {

src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Scif;
1010

1111
impl Scif {
1212
pub fn new() -> Self {
13-
Self::default()
13+
Self
1414
}
1515
}
1616
impl Formatter for Scif {

tests/by-util/test_cp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ fn test_cp_preserve_all_context_fails_on_non_selinux() {
13371337
}
13381338

13391339
#[test]
1340-
#[cfg(any(target_os = "android"))]
1340+
#[cfg(target_os = "android")]
13411341
fn test_cp_preserve_xattr_fails_on_android() {
13421342
// Because of the SELinux extended attributes used on Android, trying to copy extended
13431343
// 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() {
27682768
}
27692769

27702770
/// Test that copying file to itself with forced backup succeeds.
2771-
#[cfg(all(not(windows)))]
2771+
#[cfg(not(windows))]
27722772
#[test]
27732773
fn test_same_file_force_backup() {
27742774
let (at, mut ucmd) = at_and_ucmd!();

tests/by-util/test_stat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn test_char() {
178178
DEV_FORMAT_STR,
179179
#[cfg(target_os = "linux")]
180180
"/dev/pts/ptmx",
181-
#[cfg(any(target_vendor = "apple"))]
181+
#[cfg(target_vendor = "apple")]
182182
"%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",
183183
#[cfg(any(target_os = "android", target_vendor = "apple"))]
184184
"/dev/ptmx",
@@ -198,7 +198,7 @@ fn test_date() {
198198
"%z",
199199
#[cfg(target_os = "linux")]
200200
"/bin/sh",
201-
#[cfg(any(target_vendor = "apple"))]
201+
#[cfg(target_vendor = "apple")]
202202
"%z",
203203
#[cfg(any(target_os = "android", target_vendor = "apple"))]
204204
"/bin/sh",
@@ -213,7 +213,7 @@ fn test_date() {
213213
"%z",
214214
#[cfg(target_os = "linux")]
215215
"/dev/ptmx",
216-
#[cfg(any(target_vendor = "apple"))]
216+
#[cfg(target_vendor = "apple")]
217217
"%z",
218218
#[cfg(any(target_os = "android", target_vendor = "apple"))]
219219
"/dev/ptmx",

tests/by-util/test_tail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn test_stdin_redirect_offset() {
145145
}
146146

147147
#[test]
148-
#[cfg(all(not(target_vendor = "apple")))] // FIXME: for currently not working platforms
148+
#[cfg(not(target_vendor = "apple"))] // FIXME: for currently not working platforms
149149
fn test_stdin_redirect_offset2() {
150150
// like test_stdin_redirect_offset but with multiple files
151151

0 commit comments

Comments
 (0)