Skip to content

Commit 35f3975

Browse files
committed
fix(clippy): redundant_else
1 parent d64fcb1 commit 35f3975

File tree

12 files changed

+186
-189
lines changed

12 files changed

+186
-189
lines changed

src/uu/cp/src/cp.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,8 @@ impl Options {
11501150
CpError::Error("SELinux was not enabled during the compile time!".to_owned());
11511151
if required {
11521152
return Err(selinux_disabled_error);
1153-
} else {
1154-
show_error_if_needed(&selinux_disabled_error);
11551153
}
1154+
show_error_if_needed(&selinux_disabled_error);
11561155
}
11571156

11581157
// Extract the SELinux related flags and options
@@ -1925,10 +1924,9 @@ fn handle_existing_dest(
19251924
source.quote()
19261925
)
19271926
.into());
1928-
} else {
1929-
is_dest_removed = dest.is_symlink();
1930-
backup_dest(dest, &backup_path, is_dest_removed)?;
19311927
}
1928+
is_dest_removed = dest.is_symlink();
1929+
backup_dest(dest, &backup_path, is_dest_removed)?;
19321930
}
19331931
if !is_dest_removed {
19341932
delete_dest_if_needed_and_allowed(
@@ -2195,21 +2193,21 @@ fn handle_copy_mode(
21952193
let dest_time = dest_metadata.modified()?;
21962194
if src_time <= dest_time {
21972195
return Ok(PerformedAction::Skipped);
2198-
} else {
2199-
options.overwrite.verify(dest, options.debug)?;
2200-
2201-
copy_helper(
2202-
source,
2203-
dest,
2204-
options,
2205-
context,
2206-
source_is_symlink,
2207-
source_is_fifo,
2208-
symlinked_files,
2209-
#[cfg(unix)]
2210-
source_is_stream,
2211-
)?;
22122196
}
2197+
2198+
options.overwrite.verify(dest, options.debug)?;
2199+
2200+
copy_helper(
2201+
source,
2202+
dest,
2203+
options,
2204+
context,
2205+
source_is_symlink,
2206+
source_is_fifo,
2207+
symlinked_files,
2208+
#[cfg(unix)]
2209+
source_is_stream,
2210+
)?;
22132211
}
22142212
}
22152213
} else {

src/uu/cut/src/cut.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,8 @@ fn get_delimiters(matches: &ArgMatches) -> UResult<(Delimiter, Option<&[u8]>)> {
429429
1,
430430
get_message("cut-error-delimiter-must-be-single-character"),
431431
));
432-
} else {
433-
Delimiter::from(os_string)
434432
}
433+
Delimiter::from(os_string)
435434
}
436435
}
437436
None => {

src/uu/cut/src/matcher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ impl Matcher for ExactMatcher<'_> {
3434
|| haystack[match_idx + 1..].starts_with(&self.needle[1..])
3535
{
3636
return Some((match_idx, match_idx + self.needle.len()));
37-
} else {
38-
pos = match_idx + 1;
3937
}
38+
pos = match_idx + 1;
4039
}
4140
None => {
4241
return None;

src/uu/date/src/date.rs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -204,81 +204,81 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
204204
};
205205

206206
return set_system_datetime(date);
207+
}
208+
209+
// Get the current time, either in the local time zone or UTC.
210+
let now = if settings.utc {
211+
Timestamp::now().to_zoned(TimeZone::UTC)
207212
} else {
208-
// Get the current time, either in the local time zone or UTC.
209-
let now = if settings.utc {
210-
Timestamp::now().to_zoned(TimeZone::UTC)
211-
} else {
212-
Zoned::now()
213-
};
213+
Zoned::now()
214+
};
214215

215-
// Iterate over all dates - whether it's a single date or a file.
216-
let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
217-
DateSource::Custom(ref input) => {
218-
let date = parse_date(input);
219-
let iter = std::iter::once(date);
220-
Box::new(iter)
221-
}
222-
DateSource::Human(relative_time) => {
223-
// Double check the result is overflow or not of the current_time + relative_time
224-
// it may cause a panic of chrono::datetime::DateTime add
225-
match now.checked_add(relative_time) {
226-
Ok(date) => {
227-
let iter = std::iter::once(Ok(date));
228-
Box::new(iter)
229-
}
230-
Err(_) => {
231-
return Err(USimpleError::new(
232-
1,
233-
format!("invalid date {relative_time}"),
234-
));
235-
}
216+
// Iterate over all dates - whether it's a single date or a file.
217+
let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
218+
DateSource::Custom(ref input) => {
219+
let date = parse_date(input);
220+
let iter = std::iter::once(date);
221+
Box::new(iter)
222+
}
223+
DateSource::Human(relative_time) => {
224+
// Double check the result is overflow or not of the current_time + relative_time
225+
// it may cause a panic of chrono::datetime::DateTime add
226+
match now.checked_add(relative_time) {
227+
Ok(date) => {
228+
let iter = std::iter::once(Ok(date));
229+
Box::new(iter)
236230
}
237-
}
238-
DateSource::Stdin => {
239-
let lines = BufReader::new(std::io::stdin()).lines();
240-
let iter = lines.map_while(Result::ok).map(parse_date);
241-
Box::new(iter)
242-
}
243-
DateSource::File(ref path) => {
244-
if path.is_dir() {
231+
Err(_) => {
245232
return Err(USimpleError::new(
246-
2,
247-
format!("expected file, got directory {}", path.quote()),
233+
1,
234+
format!("invalid date {relative_time}"),
248235
));
249236
}
250-
let file = File::open(path)
251-
.map_err_context(|| path.as_os_str().to_string_lossy().to_string())?;
252-
let lines = BufReader::new(file).lines();
253-
let iter = lines.map_while(Result::ok).map(parse_date);
254-
Box::new(iter)
255237
}
256-
DateSource::Now => {
257-
let iter = std::iter::once(Ok(now));
258-
Box::new(iter)
238+
}
239+
DateSource::Stdin => {
240+
let lines = BufReader::new(std::io::stdin()).lines();
241+
let iter = lines.map_while(Result::ok).map(parse_date);
242+
Box::new(iter)
243+
}
244+
DateSource::File(ref path) => {
245+
if path.is_dir() {
246+
return Err(USimpleError::new(
247+
2,
248+
format!("expected file, got directory {}", path.quote()),
249+
));
259250
}
260-
};
251+
let file = File::open(path)
252+
.map_err_context(|| path.as_os_str().to_string_lossy().to_string())?;
253+
let lines = BufReader::new(file).lines();
254+
let iter = lines.map_while(Result::ok).map(parse_date);
255+
Box::new(iter)
256+
}
257+
DateSource::Now => {
258+
let iter = std::iter::once(Ok(now));
259+
Box::new(iter)
260+
}
261+
};
261262

262-
let format_string = make_format_string(&settings);
263-
264-
// Format all the dates
265-
for date in dates {
266-
match date {
267-
// TODO: Switch to lenient formatting.
268-
Ok(date) => match strtime::format(format_string, &date) {
269-
Ok(s) => println!("{s}"),
270-
Err(e) => {
271-
return Err(USimpleError::new(
272-
1,
273-
format!("invalid format {format_string} ({e})"),
274-
));
275-
}
276-
},
277-
Err((input, _err)) => show!(USimpleError::new(
278-
1,
279-
format!("invalid date {}", input.quote())
280-
)),
281-
}
263+
let format_string = make_format_string(&settings);
264+
265+
// Format all the dates
266+
for date in dates {
267+
match date {
268+
// TODO: Switch to lenient formatting.
269+
Ok(date) => match strtime::format(format_string, &date) {
270+
Ok(s) => println!("{s}"),
271+
Err(e) => {
272+
return Err(USimpleError::new(
273+
1,
274+
format!("invalid format {format_string} ({e})"),
275+
));
276+
}
277+
},
278+
Err((input, _err)) => show!(USimpleError::new(
279+
1,
280+
format!("invalid date {}", input.quote())
281+
)),
282282
}
283283
}
284284

src/uu/dirname/src/dirname.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3333

3434
if dirnames.is_empty() {
3535
return Err(UUsageError::new(1, get_message("dirname-missing-operand")));
36-
} else {
37-
for path in &dirnames {
38-
let p = Path::new(path);
39-
match p.parent() {
40-
Some(d) => {
41-
if d.components().next().is_none() {
42-
print!(".");
43-
} else {
44-
print_verbatim(d).unwrap();
45-
}
36+
}
37+
38+
for path in &dirnames {
39+
let p = Path::new(path);
40+
match p.parent() {
41+
Some(d) => {
42+
if d.components().next().is_none() {
43+
print!(".");
44+
} else {
45+
print_verbatim(d).unwrap();
4646
}
47-
None => {
48-
if p.is_absolute() || path == "/" {
49-
print!("/");
50-
} else {
51-
print!(".");
52-
}
47+
}
48+
None => {
49+
if p.is_absolute() || path == "/" {
50+
print!("/");
51+
} else {
52+
print!(".");
5353
}
5454
}
55-
print!("{line_ending}");
5655
}
56+
print!("{line_ending}");
5757
}
5858

5959
Ok(())

src/uu/env/src/env.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,11 @@ impl EnvAppData {
594594
match cmd.status() {
595595
Ok(exit) if !exit.success() => {
596596
#[cfg(unix)]
597-
if let Some(exit_code) = exit.code() {
598-
return Err(exit_code.into());
599-
} else {
597+
{
598+
if let Some(exit_code) = exit.code() {
599+
return Err(exit_code.into());
600+
}
601+
600602
// `exit.code()` returns `None` on Unix when the process is terminated by a signal.
601603
// See std::os::unix::process::ExitStatusExt for more information. This prints out
602604
// the interrupted process and the signal it received.

src/uu/fmt/src/linebreak.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ fn break_knuth_plass<'a, T: Clone + Iterator<Item = &'a WordInfo<'a>>>(
175175
fresh = true;
176176
}
177177
break;
178-
} else {
179-
write_with_spaces(word, slen, args.ostream)?;
180178
}
179+
write_with_spaces(word, slen, args.ostream)?;
181180
}
182181
Ok((prev_punct, fresh))
183182
},

src/uu/pr/src/pr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,8 @@ fn write_columns(
10861086
}
10871087
if not_found_break && feed_line_present {
10881088
break;
1089-
} else {
1090-
out.write_all(line_separator)?;
10911089
}
1090+
out.write_all(line_separator)?;
10921091
}
10931092

10941093
Ok(lines_printed)

src/uu/sort/src/chunks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ fn read_to_buffer<T: Read>(
287287
let end = last_line_end.unwrap();
288288
// We want to include the separator here, because it shouldn't be carried over.
289289
return Ok((end + 1, true));
290-
} else {
291-
// We need to read more lines
292-
let len = buffer.len();
293-
// resize the vector to 10 KB more
294-
buffer.resize(len + 1024 * 10, 0);
295-
read_target = &mut buffer[len..];
296290
}
291+
292+
// We need to read more lines
293+
let len = buffer.len();
294+
// resize the vector to 10 KB more
295+
buffer.resize(len + 1024 * 10, 0);
296+
read_target = &mut buffer[len..];
297297
} else {
298298
// This file has been fully read.
299299
let mut leftover_len = read_target.len();

src/uu/split/src/split.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -763,28 +763,28 @@ impl Write for ByteChunkWriter<'_> {
763763
let num_bytes_written = custom_write(buf, &mut self.inner, self.settings)?;
764764
self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64;
765765
return Ok(carryover_bytes_written + num_bytes_written);
766-
} else {
767-
// Write enough bytes to fill the current chunk.
768-
//
769-
// Conversion to usize is safe because we checked that
770-
// self.num_bytes_remaining_in_current_chunk is lower than
771-
// n, which is already usize.
772-
let i = self.num_bytes_remaining_in_current_chunk as usize;
773-
let num_bytes_written = custom_write(&buf[..i], &mut self.inner, self.settings)?;
774-
self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64;
775-
776-
// It's possible that the underlying writer did not
777-
// write all the bytes.
778-
if num_bytes_written < i {
779-
return Ok(carryover_bytes_written + num_bytes_written);
780-
} else {
781-
// Move the window to look at only the remaining bytes.
782-
buf = &buf[i..];
766+
}
783767

784-
// Remember for the next iteration that we wrote these bytes.
785-
carryover_bytes_written += num_bytes_written;
786-
}
768+
// Write enough bytes to fill the current chunk.
769+
//
770+
// Conversion to usize is safe because we checked that
771+
// self.num_bytes_remaining_in_current_chunk is lower than
772+
// n, which is already usize.
773+
let i = self.num_bytes_remaining_in_current_chunk as usize;
774+
let num_bytes_written = custom_write(&buf[..i], &mut self.inner, self.settings)?;
775+
self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64;
776+
777+
// It's possible that the underlying writer did not
778+
// write all the bytes.
779+
if num_bytes_written < i {
780+
return Ok(carryover_bytes_written + num_bytes_written);
787781
}
782+
783+
// Move the window to look at only the remaining bytes.
784+
buf = &buf[i..];
785+
786+
// Remember for the next iteration that we wrote these bytes.
787+
carryover_bytes_written += num_bytes_written;
788788
}
789789
}
790790
fn flush(&mut self) -> io::Result<()> {

0 commit comments

Comments
 (0)