clippy: fix collapsible_match lint

https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
This commit is contained in:
xtqqczze
2026-04-16 15:26:52 +01:00
committed by Daniel Hofstetter
parent 56cf4f98e5
commit 5120da04e0
6 changed files with 65 additions and 78 deletions
+25 -29
View File
@@ -537,33 +537,29 @@ fn process_file(
let mut result = Ok(());
match entry.flags() {
fts_sys::FTS_D => {
if options.recursive_mode.is_recursive() {
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
// This happens e.g., with "chcon -R --preserve-root ... /"
// and with "chcon -RH --preserve-root ... symlink-to-root".
root_dev_ino_warn(&file_full_name);
fts_sys::FTS_D if options.recursive_mode.is_recursive() => {
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
// This happens e.g., with "chcon -R --preserve-root ... /"
// and with "chcon -RH --preserve-root ... symlink-to-root".
root_dev_ino_warn(&file_full_name);
// Tell fts not to traverse into this hierarchy.
let _ignored = fts.set(fts_sys::FTS_SKIP);
// Tell fts not to traverse into this hierarchy.
let _ignored = fts.set(fts_sys::FTS_SKIP);
// Ensure that we do not process "/" on the second visit.
let _ignored = fts.read_next_entry();
// Ensure that we do not process "/" on the second visit.
let _ignored = fts.read_next_entry();
return Err(err(
translate!("chcon-op-modifying-root-path"),
io::ErrorKind::PermissionDenied,
));
}
return Ok(());
return Err(err(
translate!("chcon-op-modifying-root-path"),
io::ErrorKind::PermissionDenied,
));
}
return Ok(());
}
fts_sys::FTS_DP => {
if !options.recursive_mode.is_recursive() {
return Ok(());
}
fts_sys::FTS_DP if !options.recursive_mode.is_recursive() => {
return Ok(());
}
fts_sys::FTS_NS => {
@@ -585,14 +581,14 @@ fn process_file(
fts_sys::FTS_DNR => result = fts_err(translate!("chcon-op-reading-directory")),
fts_sys::FTS_DC => {
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) {
emit_cycle_warning(&file_full_name);
return Err(err(
translate!("chcon-op-reading-cyclic-directory"),
io::ErrorKind::InvalidData,
));
}
fts_sys::FTS_DC
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) =>
{
emit_cycle_warning(&file_full_name);
return Err(err(
translate!("chcon-op-reading-cyclic-directory"),
io::ErrorKind::InvalidData,
));
}
_ => {}
+2 -4
View File
@@ -1134,10 +1134,8 @@ impl Options {
options::PRESERVE => {
attributes = attributes.union(&Attributes::parse_iter(val.into_iter())?);
}
options::NO_PRESERVE => {
if !val.is_empty() {
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
}
options::NO_PRESERVE if !val.is_empty() => {
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
}
_ => (),
}
+3 -5
View File
@@ -379,11 +379,9 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
uppercase = true;
swap_case = false; // ^ overrides #
}
'#' => {
if !uppercase {
// Only apply # if ^ hasn't been set
swap_case = true;
}
'#' if !uppercase => {
// Only apply # if ^ hasn't been set
swap_case = true;
}
'+' => {
force_sign = true;
+28 -31
View File
@@ -132,38 +132,35 @@ impl OdOptions {
let formats = parse_format_flags(args).map_err(|e| USimpleError::new(1, e))?;
let mut line_bytes = match matches.get_one::<String>(options::WIDTH) {
None => 16,
Some(s) => {
if matches.value_source(options::WIDTH) == Some(ValueSource::CommandLine) {
let width_display = option_display_name(args, options::WIDTH, Some('w'));
let parsed = parse_number_of_bytes(s).map_err(|e| {
USimpleError::new(1, format_error_message(&e, s, &width_display))
})?;
if parsed == 0 {
return Err(USimpleError::new(
1,
translate!(
"od-error-invalid-argument",
"option" => width_display.clone(),
"value" => s.quote()
),
));
}
usize::try_from(parsed).map_err(|_| {
USimpleError::new(
1,
translate!(
"od-error-argument-too-large",
"option" => width_display.clone(),
"value" => s.quote()
),
)
})?
} else {
16
}
let mut line_bytes = if let (Some(s), Some(ValueSource::CommandLine)) = (
matches.get_one::<String>(options::WIDTH),
matches.value_source(options::WIDTH),
) {
let width_display = option_display_name(args, options::WIDTH, Some('w'));
let parsed = parse_number_of_bytes(s)
.map_err(|e| USimpleError::new(1, format_error_message(&e, s, &width_display)))?;
if parsed == 0 {
return Err(USimpleError::new(
1,
translate!(
"od-error-invalid-argument",
"option" => width_display.clone(),
"value" => s.quote()
),
));
}
usize::try_from(parsed).map_err(|_| {
USimpleError::new(
1,
translate!(
"od-error-argument-too-large",
"option" => width_display.clone(),
"value" => s.quote()
),
)
})?
} else {
16
};
let min_bytes = formats.iter().fold(1, |max, next| {
+2 -3
View File
@@ -439,7 +439,7 @@ impl Observer {
*/
}
}
EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => {
EventKind::Modify(ModifyKind::Name(RenameMode::Both))
/*
NOTE: For `tail -f a`, keep tracking additions to b after `mv a b`
(gnu/tests/tail-2/descriptor-vs-rename.sh)
@@ -457,7 +457,7 @@ impl Observer {
TODO: [2022-05; jhscheer] add test for this bug
*/
if self.follow_descriptor() {
if self.follow_descriptor() => {
let new_path = event.paths.last().unwrap();
paths.push(new_path.clone());
@@ -472,7 +472,6 @@ impl Observer {
let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path);
self.watcher_rx.as_mut().unwrap().watch_with_parent(new_path)?;
}
}
_ => {}
}
Ok(paths)
+5 -6
View File
@@ -435,12 +435,11 @@ pub fn canonicalize<P: AsRef<Path>>(
}
result.pop();
}
Err(e) => {
if miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())
{
return Err(e);
}
Err(e)
if (miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())) =>
{
return Err(e);
}
_ => {}
}