Skip to content

Commit 0e564ea

Browse files
authored
Merge pull request #8201 from gabelluardo/fix-clippy-rules
Prepare for clippy pedantic rules
2 parents bcb76ac + 35f3975 commit 0e564ea

File tree

34 files changed

+234
-244
lines changed

34 files changed

+234
-244
lines changed

src/uu/cp/src/cp.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,8 @@ impl Options {
11371137
CpError::Error("SELinux was not enabled during the compile time!".to_owned());
11381138
if required {
11391139
return Err(selinux_disabled_error);
1140-
} else {
1141-
show_error_if_needed(&selinux_disabled_error);
11421140
}
1141+
show_error_if_needed(&selinux_disabled_error);
11431142
}
11441143

11451144
// Extract the SELinux related flags and options
@@ -1912,10 +1911,9 @@ fn handle_existing_dest(
19121911
source.quote()
19131912
)
19141913
.into());
1915-
} else {
1916-
is_dest_removed = dest.is_symlink();
1917-
backup_dest(dest, &backup_path, is_dest_removed)?;
19181914
}
1915+
is_dest_removed = dest.is_symlink();
1916+
backup_dest(dest, &backup_path, is_dest_removed)?;
19191917
}
19201918
if !is_dest_removed {
19211919
delete_dest_if_needed_and_allowed(
@@ -2182,21 +2180,21 @@ fn handle_copy_mode(
21822180
let dest_time = dest_metadata.modified()?;
21832181
if src_time <= dest_time {
21842182
return Ok(PerformedAction::Skipped);
2185-
} else {
2186-
options.overwrite.verify(dest, options.debug)?;
2187-
2188-
copy_helper(
2189-
source,
2190-
dest,
2191-
options,
2192-
context,
2193-
source_is_symlink,
2194-
source_is_fifo,
2195-
symlinked_files,
2196-
#[cfg(unix)]
2197-
source_is_stream,
2198-
)?;
21992183
}
2184+
2185+
options.overwrite.verify(dest, options.debug)?;
2186+
2187+
copy_helper(
2188+
source,
2189+
dest,
2190+
options,
2191+
context,
2192+
source_is_symlink,
2193+
source_is_fifo,
2194+
symlinked_files,
2195+
#[cfg(unix)]
2196+
source_is_stream,
2197+
)?;
22002198
}
22012199
}
22022200
} 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 {} ({e})", format_string),
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/dd/src/dd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl Read for Input<'_> {
437437
}
438438
}
439439
Ok(len) => return Ok(len),
440-
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
440+
Err(e) if e.kind() == io::ErrorKind::Interrupted => (),
441441
Err(_) if self.settings.iconv.noerror => return Ok(base_idx),
442442
Err(e) => return Err(e),
443443
}
@@ -861,7 +861,7 @@ impl<'a> Output<'a> {
861861
return Ok(base_idx);
862862
}
863863
}
864-
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
864+
Err(e) if e.kind() == io::ErrorKind::Interrupted => (),
865865
Err(e) => return Err(e),
866866
}
867867
}

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/expand/src/expand.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ fn expand(options: &Options) -> UResult<()> {
464464
Err(e) => {
465465
show_error!("{e}");
466466
set_exit_code(1);
467-
continue;
468467
}
469468
}
470469
}

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/head/src/parse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub fn parse_obsolete(src: &str) -> Option<Result<Vec<OsString>, ParseError>> {
2626
} else if c == '+' && plus_possible {
2727
plus_possible = false;
2828
num_start += 1;
29-
continue;
3029
} else {
3130
num_end = n;
3231
last_char = c;

0 commit comments

Comments
 (0)