Skip to content

Commit

Permalink
Merge pull request #6184 from sylvestre/match_bool
Browse files Browse the repository at this point in the history
Fix clippy warning match_bool
  • Loading branch information
cakebaker authored Apr 3, 2024
2 parents d7434d4 + 0a0a7b9 commit 874c4f2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
command: |
## `cargo clippy` lint testing
unset fault
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone"
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone -W clippy::match_bool"
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
Expand Down
25 changes: 15 additions & 10 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,13 @@ impl Options {
#[cfg(unix)]
fn preserve_mode(&self) -> (bool, bool) {
match self.attributes.mode {
Preserve::No { explicit } => match explicit {
true => (false, true),
false => (false, false),
},
Preserve::No { explicit } => {
if explicit {
(false, true)
} else {
(false, false)
}
}
Preserve::Yes { .. } => (true, false),
}
}
Expand Down Expand Up @@ -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 S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO;
match is_explicit_no_preserve_mode {
true => return MODE_RW_UGO,
false => return org_mode & S_IRWXUGO,
if is_explicit_no_preserve_mode {
return MODE_RW_UGO;
} else {
return org_mode & S_IRWXUGO;
};
}

Expand All @@ -2051,9 +2055,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) as u32;
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
match is_explicit_no_preserve_mode {
true => return MODE_RW_UGO,
false => return org_mode & S_IRWXUGO,
if is_explicit_no_preserve_mode {
return MODE_RW_UGO;
} else {
return org_mode & S_IRWXUGO;
};
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,13 @@ fn get_delimiters(
}
}
}
None => match whitespace_delimited {
true => Delimiter::Whitespace,
false => Delimiter::default(),
},
None => {
if whitespace_delimited {
Delimiter::Whitespace
} else {
Delimiter::default()
}
}
};
let out_delim = matches
.get_one::<OsString>(options::OUTPUT_DELIMITER)
Expand Down
7 changes: 4 additions & 3 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,10 @@ fn extract_indicator_style(options: &clap::ArgMatches) -> IndicatorStyle {
}

fn parse_width(s: &str) -> Result<u16, LsError> {
let radix = match s.starts_with('0') && s.len() > 1 {
true => 8,
false => 10,
let radix = if s.starts_with('0') && s.len() > 1 {
8
} else {
10
};
match u16::from_str_radix(s, radix) {
Ok(x) => Ok(x),
Expand Down
17 changes: 8 additions & 9 deletions src/uu/timeout/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
// NOTE: GNU timeout doesn't check for errors of signal.
// 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.
match foreground {
true => _ = process.send_signal(signal),
false => {
_ = process.send_signal_group(signal);
let kill_signal = signal_by_name_or_value("KILL").unwrap();
let continued_signal = signal_by_name_or_value("CONT").unwrap();
if signal != kill_signal && signal != continued_signal {
_ = process.send_signal_group(continued_signal);
}
if foreground {
let _ = process.send_signal(signal);
} else {
let _ = process.send_signal_group(signal);
let kill_signal = signal_by_name_or_value("KILL").unwrap();
let continued_signal = signal_by_name_or_value("CONT").unwrap();
if signal != kill_signal && signal != continued_signal {
_ = process.send_signal_group(continued_signal);
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/uucore/src/lib/features/format/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ impl Spec {
if *c == b'u' && flags.hash {
return Err(&start[..index]);
}
let prefix = match flags.hash {
false => Prefix::No,
true => Prefix::Yes,
};
let prefix = if flags.hash { Prefix::Yes } else { Prefix::No };
let variant = match c {
b'u' => UnsignedIntVariant::Decimal,
b'o' => UnsignedIntVariant::Octal(prefix),
Expand All @@ -245,13 +242,15 @@ impl Spec {
b'a' | b'A' => FloatVariant::Hexadecimal,
_ => unreachable!(),
},
force_decimal: match flags.hash {
false => ForceDecimal::No,
true => ForceDecimal::Yes,
force_decimal: if flags.hash {
ForceDecimal::Yes
} else {
ForceDecimal::No
},
case: match c.is_ascii_uppercase() {
false => Case::Lowercase,
true => Case::Uppercase,
case: if c.is_ascii_uppercase() {
Case::Uppercase
} else {
Case::Lowercase
},
alignment,
positive_sign,
Expand Down

0 comments on commit 874c4f2

Please sign in to comment.