Fix clippy warning match_bool

This commit is contained in:
Sylvestre Ledru 2024-04-02 23:29:37 +02:00
parent d7434d4198
commit 2fe5dc874e
5 changed files with 43 additions and 36 deletions

View file

@ -1065,10 +1065,13 @@ impl Options {
#[cfg(unix)] #[cfg(unix)]
fn preserve_mode(&self) -> (bool, bool) { fn preserve_mode(&self) -> (bool, bool) {
match self.attributes.mode { match self.attributes.mode {
Preserve::No { explicit } => match explicit { Preserve::No { explicit } => {
true => (false, true), if explicit {
false => (false, false), (false, true)
}, } else {
(false, false)
}
}
Preserve::Yes { .. } => (true, false), Preserve::Yes { .. } => (true, false),
} }
} }
@ -2034,9 +2037,10 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
{ {
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO;
match is_explicit_no_preserve_mode { if is_explicit_no_preserve_mode {
true => return MODE_RW_UGO, return MODE_RW_UGO;
false => return org_mode & S_IRWXUGO, } else {
return org_mode & S_IRWXUGO;
}; };
} }
@ -2051,9 +2055,10 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
const MODE_RW_UGO: u32 = const MODE_RW_UGO: u32 =
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32;
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
match is_explicit_no_preserve_mode { if is_explicit_no_preserve_mode {
true => return MODE_RW_UGO, return MODE_RW_UGO;
false => return org_mode & S_IRWXUGO, } else {
return org_mode & S_IRWXUGO;
}; };
} }
} }

View file

@ -408,10 +408,13 @@ fn get_delimiters(
} }
} }
} }
None => match whitespace_delimited { None => {
true => Delimiter::Whitespace, if whitespace_delimited {
false => Delimiter::default(), Delimiter::Whitespace
}, } else {
Delimiter::default()
}
}
}; };
let out_delim = matches let out_delim = matches
.get_one::<OsString>(options::OUTPUT_DELIMITER) .get_one::<OsString>(options::OUTPUT_DELIMITER)

View file

@ -763,9 +763,10 @@ fn extract_indicator_style(options: &clap::ArgMatches) -> IndicatorStyle {
} }
fn parse_width(s: &str) -> Result<u16, LsError> { fn parse_width(s: &str) -> Result<u16, LsError> {
let radix = match s.starts_with('0') && s.len() > 1 { let radix = if s.starts_with('0') && s.len() > 1 {
true => 8, 8
false => 10, } else {
10
}; };
match u16::from_str_radix(s, radix) { match u16::from_str_radix(s, radix) {
Ok(x) => Ok(x), Ok(x) => Ok(x),

View file

@ -202,10 +202,10 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
// NOTE: GNU timeout doesn't check for errors of signal. // NOTE: GNU timeout doesn't check for errors of signal.
// The subprocess might have exited just after the timeout. // The subprocess might have exited just after the timeout.
// Sending a signal now would return "No such process", but we should still try to kill the children. // Sending a signal now would return "No such process", but we should still try to kill the children.
match foreground { if foreground {
true => _ = process.send_signal(signal), let _ = process.send_signal(signal);
false => { } else {
_ = process.send_signal_group(signal); let _ = process.send_signal_group(signal);
let kill_signal = signal_by_name_or_value("KILL").unwrap(); let kill_signal = signal_by_name_or_value("KILL").unwrap();
let continued_signal = signal_by_name_or_value("CONT").unwrap(); let continued_signal = signal_by_name_or_value("CONT").unwrap();
if signal != kill_signal && signal != continued_signal { if signal != kill_signal && signal != continued_signal {
@ -213,7 +213,6 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
} }
} }
} }
}
/// Wait for a child process and send a kill signal if it does not terminate. /// Wait for a child process and send a kill signal if it does not terminate.
/// ///

View file

@ -217,10 +217,7 @@ impl Spec {
if *c == b'u' && flags.hash { if *c == b'u' && flags.hash {
return Err(&start[..index]); return Err(&start[..index]);
} }
let prefix = match flags.hash { let prefix = if flags.hash { Prefix::Yes } else { Prefix::No };
false => Prefix::No,
true => Prefix::Yes,
};
let variant = match c { let variant = match c {
b'u' => UnsignedIntVariant::Decimal, b'u' => UnsignedIntVariant::Decimal,
b'o' => UnsignedIntVariant::Octal(prefix), b'o' => UnsignedIntVariant::Octal(prefix),
@ -245,13 +242,15 @@ impl Spec {
b'a' | b'A' => FloatVariant::Hexadecimal, b'a' | b'A' => FloatVariant::Hexadecimal,
_ => unreachable!(), _ => unreachable!(),
}, },
force_decimal: match flags.hash { force_decimal: if flags.hash {
false => ForceDecimal::No, ForceDecimal::Yes
true => ForceDecimal::Yes, } else {
ForceDecimal::No
}, },
case: match c.is_ascii_uppercase() { case: if c.is_ascii_uppercase() {
false => Case::Lowercase, Case::Uppercase
true => Case::Uppercase, } else {
Case::Lowercase
}, },
alignment, alignment,
positive_sign, positive_sign,