clippy: fix collapsible_match lint

https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
This commit is contained in:
xtqqczze
2026-04-18 22:54:07 +01:00
committed by danielrainer
parent b21a4a7197
commit a4b6348315
5 changed files with 45 additions and 75 deletions

View File

@@ -534,8 +534,8 @@ enum Mode {
let mut to_append_or_none = Some(c);
if mode == Mode::Unquoted {
match c {
'\\' => {
if !ignore_backslashes {
'\\'
if !ignore_backslashes => {
// Backslashes (escapes) are complicated and may result in errors, or
// appending INTERNAL_SEPARATORs, so we have to handle them specially.
if let Some(escape_chars) = read_unquoted_escape(
@@ -555,28 +555,25 @@ enum Mode {
// We've already appended, don't append anything else.
to_append_or_none = None;
}
}
'~' => {
'~'
if unescape_special
&& (input_position == 0 || Some(input_position) == potential_word_start)
{
=> {
to_append_or_none = Some(HOME_DIRECTORY);
}
}
'%' => {
'%'
// Note that this only recognizes %self if the string is literally %self.
// %self/foo will NOT match this.
if allow_percent_self
&& unescape_special
&& input_position == 0
&& input == PROCESS_EXPAND_SELF_STR
{
=> {
to_append_or_none = Some(PROCESS_EXPAND_SELF);
input_position += PROCESS_EXPAND_SELF_STR.len() - 1; // skip over 'self's
}
}
'*' => {
if unescape_special {
'*'
if unescape_special => {
// In general, this is ANY_STRING. But as a hack, if the last appended char
// is ANY_STRING, delete the last char and store ANY_STRING_RECURSIVE to
// reflect the fact that ** is the recursive wildcard.
@@ -588,14 +585,12 @@ enum Mode {
to_append_or_none = Some(ANY_STRING);
}
}
}
'?' => {
if unescape_special && !feature_test(FeatureFlag::QuestionMarkNoGlob) {
'?'
if unescape_special && !feature_test(FeatureFlag::QuestionMarkNoGlob) => {
to_append_or_none = Some(ANY_CHAR);
}
}
'$' => {
if unescape_special {
'$'
if unescape_special => {
let is_cmdsub = input_position + 1 < input.len()
&& input.char_at(input_position + 1) == '(';
if !is_cmdsub {
@@ -603,18 +598,16 @@ enum Mode {
vars_or_seps.push(input_position);
}
}
}
'{' => {
if unescape_special {
'{'
if unescape_special => {
brace_count += 1;
to_append_or_none = Some(BRACE_BEGIN);
// We need to store where the brace *ends up* in the output.
braces.push(result.len());
potential_word_start = Some(input_position + 1);
}
}
'}' => {
if unescape_special {
'}'
if unescape_special => {
// HACK: The completion machinery sometimes hands us partial tokens.
// We can't parse them properly, but it shouldn't hurt,
// so we don't assert here.
@@ -646,19 +639,16 @@ enum Mode {
}
}
}
}
',' => {
if unescape_special && brace_count > 0 {
','
if unescape_special && brace_count > 0 => {
to_append_or_none = Some(BRACE_SEP);
vars_or_seps.push(input_position);
potential_word_start = Some(input_position + 1);
}
}
' ' => {
if unescape_special && brace_count > 0 {
' '
if unescape_special && brace_count > 0 => {
to_append_or_none = Some(BRACE_SPACE);
}
}
'\'' => {
mode = Mode::SingleQuotes;
to_append_or_none = if unescape_special {
@@ -743,11 +733,9 @@ enum Mode {
}
}
}
'$' => {
if unescape_special {
to_append_or_none = Some(VARIABLE_EXPAND_SINGLE);
vars_or_seps.push(input_position);
}
'$' if unescape_special => {
to_append_or_none = Some(VARIABLE_EXPAND_SINGLE);
vars_or_seps.push(input_position);
}
_ => (),
}

View File

@@ -1735,10 +1735,8 @@ enum Mode {
match c {
'\\' => skip_next = true,
'$' => {
if mode == Unquoted || mode == DoubleQuoted {
variable_start = Some(in_pos);
}
'$' if (mode == Unquoted || mode == DoubleQuoted) => {
variable_start = Some(in_pos);
}
'\'' => {
if mode == SingleQuoted {

View File

@@ -800,10 +800,8 @@ fn expand_braces(
brace_end = Some(pos);
}
}
BRACE_SEP => {
if brace_count == 1 {
last_sep = Some(pos);
}
BRACE_SEP if brace_count == 1 => {
last_sep = Some(pos);
}
_ => {
// we ignore all other characters here

View File

@@ -586,10 +586,8 @@ enum Mode {
} else {
// Not a backslash.
match c {
'~' => {
if in_pos == 0 {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
'~' if in_pos == 0 => {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
'$' => {
assert!(in_pos < buff_len);
@@ -597,10 +595,8 @@ enum Mode {
// Subtract one to account for the upcoming loop increment.
in_pos -= 1;
}
'?' => {
if !feature_test(FeatureFlag::QuestionMarkNoGlob) {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
'?' if !feature_test(FeatureFlag::QuestionMarkNoGlob) => {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
'*' | '(' | ')' => {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
@@ -613,10 +609,8 @@ enum Mode {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
bracket_count -= 1;
}
',' => {
if bracket_count > 0 {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
',' if bracket_count > 0 => {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
}
'\'' => {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::quote);
@@ -660,9 +654,9 @@ enum Mode {
'"' => {
mode = Mode::unquoted;
}
'\\' => {
'\\'
// Backslash
if in_pos + 1 < buff_len {
if in_pos + 1 < buff_len => {
let escaped_char = buffstr.as_char_slice()[in_pos + 1];
if matches!(escaped_char, '\\' | '"' | '\n' | '$') {
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::escape); // backslash
@@ -670,7 +664,6 @@ enum Mode {
in_pos += 1; // skip over backslash
}
}
}
'$' => {
in_pos += color_variable(&buffstr[in_pos..], &mut colors[in_pos..]);
// Subtract one to account for the upcoming increment in the loop.

View File

@@ -968,17 +968,13 @@ fn visit(&mut self, node: &'a dyn Node) {
// ....cmd3
// end
// See #7252.
Kind::JobContinuation(node) => {
if self.has_newline(&node.newlines) {
inc_dec = (1, 1);
}
Kind::JobContinuation(node) if self.has_newline(&node.newlines) => {
inc_dec = (1, 1);
}
// Likewise for && and ||.
Kind::JobConjunctionContinuation(node) => {
if self.has_newline(&node.newlines) {
inc_dec = (1, 1);
}
Kind::JobConjunctionContinuation(node) if self.has_newline(&node.newlines) => {
inc_dec = (1, 1);
}
Kind::CaseItemList(_) => {
@@ -1150,23 +1146,21 @@ pub fn detect_parse_errors_in_ast(
let mut traversal = ast::Traversal::new(ast.top());
while let Some(node) = traversal.next() {
match node.kind() {
Kind::JobContinuation(jc) => {
Kind::JobContinuation(jc)
// Somewhat clumsy way of checking for a statement without source in a pipeline.
// See if our pipe has source but our statement does not.
if jc.pipe.has_source() && jc.statement.try_source_range().is_none() {
if jc.pipe.has_source() && jc.statement.try_source_range().is_none() => {
has_unclosed_pipe = true;
}
}
Kind::JobConjunction(job_conjunction) => {
issue.error |= detect_errors_in_job_conjunction(job_conjunction, &mut out_errors);
}
Kind::JobConjunctionContinuation(jcc) => {
Kind::JobConjunctionContinuation(jcc)
// Somewhat clumsy way of checking for a job without source in a conjunction.
// See if our conjunction operator (&& or ||) has source but our job does not.
if jcc.conjunction.has_source() && jcc.job.try_source_range().is_none() {
if jcc.conjunction.has_source() && jcc.job.try_source_range().is_none() => {
has_unclosed_conjunction = true;
}
}
Kind::Argument(arg) => {
let arg_src = arg.source(buff_src);
if let Err(e) = detect_errors_in_argument(arg, arg_src, &mut out_errors) {
@@ -1174,7 +1168,7 @@ pub fn detect_parse_errors_in_ast(
issue.incomplete |= e.incomplete;
}
}
Kind::JobPipeline(job) => {
Kind::JobPipeline(job)
// Disallow background in the following cases:
//
// foo & ; and bar
@@ -1182,11 +1176,10 @@ pub fn detect_parse_errors_in_ast(
// if foo & ; end
// while foo & ; end
// If it's not a background job, nothing to do.
if job.bg.is_some() {
if job.bg.is_some() => {
issue.error |=
detect_errors_in_backgrounded_job(&traversal, job, &mut out_errors);
}
}
Kind::DecoratedStatement(stmt) => {
issue.error |= detect_errors_in_decorated_statement(
buff_src,