Skip to content

Commit 291473e

Browse files
authored
Merge pull request #7744 from BenWiederhake/dev-clippy-0-1-87-nightly
Apply suggestions from clippy 0.1.87+nightly
2 parents 907d3ff + 875770f commit 291473e

File tree

15 files changed

+83
-119
lines changed

15 files changed

+83
-119
lines changed

src/uu/comm/src/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result<LineReader> {
267267
Ok(LineReader::new(Input::Stdin(stdin()), line_ending))
268268
} else {
269269
if metadata(name)?.is_dir() {
270-
return Err(io::Error::new(io::ErrorKind::Other, "Is a directory"));
270+
return Err(io::Error::other("Is a directory"));
271271
}
272272
let f = File::open(name)?;
273273
Ok(LineReader::new(

src/uu/cp/src/copydir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn get_local_to_root_parent(
8282
/// Given an iterator, return all its items except the last.
8383
fn skip_last<T>(mut iter: impl Iterator<Item = T>) -> impl Iterator<Item = T> {
8484
let last = iter.next();
85-
iter.scan(last, |state, item| std::mem::replace(state, Some(item)))
85+
iter.scan(last, |state, item| state.replace(item))
8686
}
8787

8888
/// Paths that are invariant throughout the traversal when copying a directory.

src/uu/du/src/du.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,18 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
580580
// First, check if the file_name is a directory
581581
let path = PathBuf::from(file_name);
582582
if path.is_dir() {
583-
return Err(std::io::Error::new(
584-
std::io::ErrorKind::Other,
585-
format!("{file_name}: read error: Is a directory"),
586-
));
583+
return Err(std::io::Error::other(format!(
584+
"{file_name}: read error: Is a directory"
585+
)));
587586
}
588587

589588
// Attempt to open the file and handle the error if it does not exist
590589
match File::open(file_name) {
591590
Ok(file) => Box::new(BufReader::new(file)),
592591
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
593-
return Err(std::io::Error::new(
594-
std::io::ErrorKind::Other,
595-
format!("cannot open '{file_name}' for reading: No such file or directory"),
596-
));
592+
return Err(std::io::Error::other(format!(
593+
"cannot open '{file_name}' for reading: No such file or directory"
594+
)));
597595
}
598596
Err(e) => return Err(e),
599597
}
@@ -637,13 +635,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
637635

638636
let files = if let Some(file_from) = matches.get_one::<String>(options::FILES0_FROM) {
639637
if file_from == "-" && matches.get_one::<String>(options::FILE).is_some() {
640-
return Err(std::io::Error::new(
641-
std::io::ErrorKind::Other,
642-
format!(
643-
"extra operand {}\nfile operands cannot be combined with --files0-from",
644-
matches.get_one::<String>(options::FILE).unwrap().quote()
645-
),
646-
)
638+
return Err(std::io::Error::other(format!(
639+
"extra operand {}\nfile operands cannot be combined with --files0-from",
640+
matches.get_one::<String>(options::FILE).unwrap().quote()
641+
))
647642
.into());
648643
}
649644

src/uu/echo/src/echo.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,17 @@ fn execute(
168168
}
169169

170170
fn bytes_from_os_string(input: &OsStr) -> Option<&[u8]> {
171-
let option = {
172-
#[cfg(target_family = "unix")]
173-
{
174-
use std::os::unix::ffi::OsStrExt;
171+
#[cfg(target_family = "unix")]
172+
{
173+
use std::os::unix::ffi::OsStrExt;
175174

176-
Some(input.as_bytes())
177-
}
178-
179-
#[cfg(not(target_family = "unix"))]
180-
{
181-
// TODO
182-
// Verify that this works correctly on these platforms
183-
input.to_str().map(|st| st.as_bytes())
184-
}
185-
};
175+
Some(input.as_bytes())
176+
}
186177

187-
option
178+
#[cfg(not(target_family = "unix"))]
179+
{
180+
// TODO
181+
// Verify that this works correctly on these platforms
182+
input.to_str().map(|st| st.as_bytes())
183+
}
188184
}

src/uu/env/src/native_int_str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ impl<'a> NativeStr<'a> {
283283
match &self.native {
284284
Cow::Borrowed(b) => {
285285
let slice = f_borrow(b);
286-
let os_str = slice.map(|x| from_native_int_representation(Cow::Borrowed(x)));
287-
os_str
286+
slice.map(|x| from_native_int_representation(Cow::Borrowed(x)))
288287
}
289288
Cow::Owned(o) => {
290289
let slice = f_owned(o);

src/uu/fmt/src/linebreak.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ fn break_knuth_plass<'a, T: Clone + Iterator<Item = &'a WordInfo<'a>>>(
164164

165165
// We find identical breakpoints here by comparing addresses of the references.
166166
// This is OK because the backing vector is not mutating once we are linebreaking.
167-
let winfo_ptr = winfo as *const _;
168-
let next_break_ptr = next_break as *const _;
169-
if winfo_ptr == next_break_ptr {
167+
if std::ptr::eq(winfo, next_break) {
170168
// OK, we found the matching word
171169
if break_before {
172170
write_newline(args.indent_str, args.ostream)?;

src/uu/mv/src/mv.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
370370
OverwriteMode::NoClobber => return Ok(()),
371371
OverwriteMode::Interactive => {
372372
if !prompt_yes!("overwrite {}? ", target.quote()) {
373-
return Err(io::Error::new(io::ErrorKind::Other, "").into());
373+
return Err(io::Error::other("").into());
374374
}
375375
}
376376
OverwriteMode::Force => {}
@@ -609,7 +609,7 @@ fn rename(
609609

610610
if opts.update == UpdateMode::ReplaceNoneFail {
611611
let err_msg = format!("not replacing {}", to.quote());
612-
return Err(io::Error::new(io::ErrorKind::Other, err_msg));
612+
return Err(io::Error::other(err_msg));
613613
}
614614

615615
match opts.overwrite {
@@ -621,7 +621,7 @@ fn rename(
621621
}
622622
OverwriteMode::Interactive => {
623623
if !prompt_yes!("overwrite {}?", to.quote()) {
624-
return Err(io::Error::new(io::ErrorKind::Other, ""));
624+
return Err(io::Error::other(""));
625625
}
626626
}
627627
OverwriteMode::Force => {}
@@ -640,7 +640,7 @@ fn rename(
640640
if is_empty_dir(to) {
641641
fs::remove_dir(to)?;
642642
} else {
643-
return Err(io::Error::new(io::ErrorKind::Other, "Directory not empty"));
643+
return Err(io::Error::other("Directory not empty"));
644644
}
645645
}
646646
}
@@ -756,7 +756,7 @@ fn rename_with_fallback(
756756
io::ErrorKind::PermissionDenied,
757757
"Permission denied",
758758
)),
759-
_ => Err(io::Error::new(io::ErrorKind::Other, format!("{err:?}"))),
759+
_ => Err(io::Error::other(format!("{err:?}"))),
760760
};
761761
}
762762
} else {
@@ -811,8 +811,7 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
811811
}
812812
#[cfg(not(any(windows, unix)))]
813813
{
814-
return Err(io::Error::new(
815-
io::ErrorKind::Other,
814+
return Err(io::Error::other(
816815
"your operating system does not support symlinks",
817816
));
818817
}

src/uu/split/src/platform/unix.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
use std::env;
66
use std::io::Write;
7-
use std::io::{BufWriter, Error, ErrorKind, Result};
7+
use std::io::{BufWriter, Error, Result};
88
use std::path::Path;
99
use std::process::{Child, Command, Stdio};
1010
use uucore::error::USimpleError;
@@ -134,22 +134,14 @@ pub fn instantiate_current_writer(
134134
.create(true)
135135
.truncate(true)
136136
.open(Path::new(&filename))
137-
.map_err(|_| {
138-
Error::new(
139-
ErrorKind::Other,
140-
format!("unable to open '{filename}'; aborting"),
141-
)
142-
})?
137+
.map_err(|_| Error::other(format!("unable to open '{filename}'; aborting")))?
143138
} else {
144139
// re-open file that we previously created to append to it
145140
std::fs::OpenOptions::new()
146141
.append(true)
147142
.open(Path::new(&filename))
148143
.map_err(|_| {
149-
Error::new(
150-
ErrorKind::Other,
151-
format!("unable to re-open '{filename}'; aborting"),
152-
)
144+
Error::other(format!("unable to re-open '{filename}'; aborting"))
153145
})?
154146
};
155147
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))

src/uu/split/src/platform/windows.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
use std::io::Write;
6-
use std::io::{BufWriter, Error, ErrorKind, Result};
6+
use std::io::{BufWriter, Error, Result};
77
use std::path::Path;
88
use uucore::fs;
99

@@ -23,23 +23,13 @@ pub fn instantiate_current_writer(
2323
.create(true)
2424
.truncate(true)
2525
.open(Path::new(&filename))
26-
.map_err(|_| {
27-
Error::new(
28-
ErrorKind::Other,
29-
format!("unable to open '{filename}'; aborting"),
30-
)
31-
})?
26+
.map_err(|_| Error::other(format!("unable to open '{filename}'; aborting")))?
3227
} else {
3328
// re-open file that we previously created to append to it
3429
std::fs::OpenOptions::new()
3530
.append(true)
3631
.open(Path::new(&filename))
37-
.map_err(|_| {
38-
Error::new(
39-
ErrorKind::Other,
40-
format!("unable to re-open '{filename}'; aborting"),
41-
)
42-
})?
32+
.map_err(|_| Error::other(format!("unable to re-open '{filename}'; aborting")))?
4333
};
4434
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))
4535
}

src/uu/split/src/split.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,9 @@ impl Settings {
535535
is_new: bool,
536536
) -> io::Result<BufWriter<Box<dyn Write>>> {
537537
if platform::paths_refer_to_same_file(&self.input, filename) {
538-
return Err(io::Error::new(
539-
ErrorKind::Other,
540-
format!("'{filename}' would overwrite input; aborting"),
541-
));
538+
return Err(io::Error::other(format!(
539+
"'{filename}' would overwrite input; aborting"
540+
)));
542541
}
543542

544543
platform::instantiate_current_writer(self.filter.as_deref(), filename, is_new)
@@ -638,10 +637,9 @@ where
638637
} else if input == "-" {
639638
// STDIN stream that did not fit all content into a buffer
640639
// Most likely continuous/infinite input stream
641-
return Err(io::Error::new(
642-
ErrorKind::Other,
643-
format!("{input}: cannot determine input size"),
644-
));
640+
return Err(io::Error::other(format!(
641+
"{input}: cannot determine input size"
642+
)));
645643
} else {
646644
// Could be that file size is larger than set read limit
647645
// Get the file size from filesystem metadata
@@ -664,10 +662,9 @@ where
664662
// Give up and return an error
665663
// TODO It might be possible to do more here
666664
// to address all possible file types and edge cases
667-
return Err(io::Error::new(
668-
ErrorKind::Other,
669-
format!("{input}: cannot determine file size"),
670-
));
665+
return Err(io::Error::other(format!(
666+
"{input}: cannot determine file size"
667+
)));
671668
}
672669
}
673670
}
@@ -750,9 +747,10 @@ impl Write for ByteChunkWriter<'_> {
750747
self.num_bytes_remaining_in_current_chunk = self.chunk_size;
751748

752749
// Allocate the new file, since at this point we know there are bytes to be written to it.
753-
let filename = self.filename_iterator.next().ok_or_else(|| {
754-
io::Error::new(ErrorKind::Other, "output file suffixes exhausted")
755-
})?;
750+
let filename = self
751+
.filename_iterator
752+
.next()
753+
.ok_or_else(|| io::Error::other("output file suffixes exhausted"))?;
756754
if self.settings.verbose {
757755
println!("creating file {}", filename.quote());
758756
}
@@ -871,9 +869,10 @@ impl Write for LineChunkWriter<'_> {
871869
// corresponding writer.
872870
if self.num_lines_remaining_in_current_chunk == 0 {
873871
self.num_chunks_written += 1;
874-
let filename = self.filename_iterator.next().ok_or_else(|| {
875-
io::Error::new(ErrorKind::Other, "output file suffixes exhausted")
876-
})?;
872+
let filename = self
873+
.filename_iterator
874+
.next()
875+
.ok_or_else(|| io::Error::other("output file suffixes exhausted"))?;
877876
if self.settings.verbose {
878877
println!("creating file {}", filename.quote());
879878
}
@@ -948,7 +947,7 @@ impl ManageOutFiles for OutFiles {
948947
// This object is responsible for creating the filename for each chunk
949948
let mut filename_iterator: FilenameIterator<'_> =
950949
FilenameIterator::new(&settings.prefix, &settings.suffix)
951-
.map_err(|e| io::Error::new(ErrorKind::Other, format!("{e}")))?;
950+
.map_err(|e| io::Error::other(format!("{e}")))?;
952951
let mut out_files: Self = Self::new();
953952
for _ in 0..num_files {
954953
let filename = filename_iterator

0 commit comments

Comments
 (0)