Skip to content

Commit 874c4f2

Browse files
authored
Merge pull request #6184 from sylvestre/match_bool
Fix clippy warning match_bool
2 parents d7434d4 + 0a0a7b9 commit 874c4f2

File tree

6 files changed

+44
-37
lines changed

6 files changed

+44
-37
lines changed

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
command: |
127127
## `cargo clippy` lint testing
128128
unset fault
129-
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"
129+
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"
130130
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
131131
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
132132
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>

src/uu/cp/src/cp.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,13 @@ impl Options {
10651065
#[cfg(unix)]
10661066
fn preserve_mode(&self) -> (bool, bool) {
10671067
match self.attributes.mode {
1068-
Preserve::No { explicit } => match explicit {
1069-
true => (false, true),
1070-
false => (false, false),
1071-
},
1068+
Preserve::No { explicit } => {
1069+
if explicit {
1070+
(false, true)
1071+
} else {
1072+
(false, false)
1073+
}
1074+
}
10721075
Preserve::Yes { .. } => (true, false),
10731076
}
10741077
}
@@ -2034,9 +2037,10 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
20342037
{
20352038
const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
20362039
const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO;
2037-
match is_explicit_no_preserve_mode {
2038-
true => return MODE_RW_UGO,
2039-
false => return org_mode & S_IRWXUGO,
2040+
if is_explicit_no_preserve_mode {
2041+
return MODE_RW_UGO;
2042+
} else {
2043+
return org_mode & S_IRWXUGO;
20402044
};
20412045
}
20422046

@@ -2051,9 +2055,10 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 {
20512055
const MODE_RW_UGO: u32 =
20522056
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32;
20532057
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
2054-
match is_explicit_no_preserve_mode {
2055-
true => return MODE_RW_UGO,
2056-
false => return org_mode & S_IRWXUGO,
2058+
if is_explicit_no_preserve_mode {
2059+
return MODE_RW_UGO;
2060+
} else {
2061+
return org_mode & S_IRWXUGO;
20572062
};
20582063
}
20592064
}

src/uu/cut/src/cut.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,13 @@ fn get_delimiters(
408408
}
409409
}
410410
}
411-
None => match whitespace_delimited {
412-
true => Delimiter::Whitespace,
413-
false => Delimiter::default(),
414-
},
411+
None => {
412+
if whitespace_delimited {
413+
Delimiter::Whitespace
414+
} else {
415+
Delimiter::default()
416+
}
417+
}
415418
};
416419
let out_delim = matches
417420
.get_one::<OsString>(options::OUTPUT_DELIMITER)

src/uu/ls/src/ls.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,10 @@ fn extract_indicator_style(options: &clap::ArgMatches) -> IndicatorStyle {
763763
}
764764

765765
fn parse_width(s: &str) -> Result<u16, LsError> {
766-
let radix = match s.starts_with('0') && s.len() > 1 {
767-
true => 8,
768-
false => 10,
766+
let radix = if s.starts_with('0') && s.len() > 1 {
767+
8
768+
} else {
769+
10
769770
};
770771
match u16::from_str_radix(s, radix) {
771772
Ok(x) => Ok(x),

src/uu/timeout/src/timeout.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
202202
// NOTE: GNU timeout doesn't check for errors of signal.
203203
// The subprocess might have exited just after the timeout.
204204
// Sending a signal now would return "No such process", but we should still try to kill the children.
205-
match foreground {
206-
true => _ = process.send_signal(signal),
207-
false => {
208-
_ = process.send_signal_group(signal);
209-
let kill_signal = signal_by_name_or_value("KILL").unwrap();
210-
let continued_signal = signal_by_name_or_value("CONT").unwrap();
211-
if signal != kill_signal && signal != continued_signal {
212-
_ = process.send_signal_group(continued_signal);
213-
}
205+
if foreground {
206+
let _ = process.send_signal(signal);
207+
} else {
208+
let _ = process.send_signal_group(signal);
209+
let kill_signal = signal_by_name_or_value("KILL").unwrap();
210+
let continued_signal = signal_by_name_or_value("CONT").unwrap();
211+
if signal != kill_signal && signal != continued_signal {
212+
_ = process.send_signal_group(continued_signal);
214213
}
215214
}
216215
}

src/uucore/src/lib/features/format/spec.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@ impl Spec {
217217
if *c == b'u' && flags.hash {
218218
return Err(&start[..index]);
219219
}
220-
let prefix = match flags.hash {
221-
false => Prefix::No,
222-
true => Prefix::Yes,
223-
};
220+
let prefix = if flags.hash { Prefix::Yes } else { Prefix::No };
224221
let variant = match c {
225222
b'u' => UnsignedIntVariant::Decimal,
226223
b'o' => UnsignedIntVariant::Octal(prefix),
@@ -245,13 +242,15 @@ impl Spec {
245242
b'a' | b'A' => FloatVariant::Hexadecimal,
246243
_ => unreachable!(),
247244
},
248-
force_decimal: match flags.hash {
249-
false => ForceDecimal::No,
250-
true => ForceDecimal::Yes,
245+
force_decimal: if flags.hash {
246+
ForceDecimal::Yes
247+
} else {
248+
ForceDecimal::No
251249
},
252-
case: match c.is_ascii_uppercase() {
253-
false => Case::Lowercase,
254-
true => Case::Uppercase,
250+
case: if c.is_ascii_uppercase() {
251+
Case::Uppercase
252+
} else {
253+
Case::Lowercase
255254
},
256255
alignment,
257256
positive_sign,

0 commit comments

Comments
 (0)