mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 22:21:15 -03:00
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:
@@ -534,8 +534,8 @@ enum Mode {
|
|||||||
let mut to_append_or_none = Some(c);
|
let mut to_append_or_none = Some(c);
|
||||||
if mode == Mode::Unquoted {
|
if mode == Mode::Unquoted {
|
||||||
match c {
|
match c {
|
||||||
'\\' => {
|
'\\'
|
||||||
if !ignore_backslashes {
|
if !ignore_backslashes => {
|
||||||
// Backslashes (escapes) are complicated and may result in errors, or
|
// Backslashes (escapes) are complicated and may result in errors, or
|
||||||
// appending INTERNAL_SEPARATORs, so we have to handle them specially.
|
// appending INTERNAL_SEPARATORs, so we have to handle them specially.
|
||||||
if let Some(escape_chars) = read_unquoted_escape(
|
if let Some(escape_chars) = read_unquoted_escape(
|
||||||
@@ -555,28 +555,25 @@ enum Mode {
|
|||||||
// We've already appended, don't append anything else.
|
// We've already appended, don't append anything else.
|
||||||
to_append_or_none = None;
|
to_append_or_none = None;
|
||||||
}
|
}
|
||||||
}
|
'~'
|
||||||
'~' => {
|
|
||||||
if unescape_special
|
if unescape_special
|
||||||
&& (input_position == 0 || Some(input_position) == potential_word_start)
|
&& (input_position == 0 || Some(input_position) == potential_word_start)
|
||||||
{
|
=> {
|
||||||
to_append_or_none = Some(HOME_DIRECTORY);
|
to_append_or_none = Some(HOME_DIRECTORY);
|
||||||
}
|
}
|
||||||
}
|
'%'
|
||||||
'%' => {
|
|
||||||
// Note that this only recognizes %self if the string is literally %self.
|
// Note that this only recognizes %self if the string is literally %self.
|
||||||
// %self/foo will NOT match this.
|
// %self/foo will NOT match this.
|
||||||
if allow_percent_self
|
if allow_percent_self
|
||||||
&& unescape_special
|
&& unescape_special
|
||||||
&& input_position == 0
|
&& input_position == 0
|
||||||
&& input == PROCESS_EXPAND_SELF_STR
|
&& input == PROCESS_EXPAND_SELF_STR
|
||||||
{
|
=> {
|
||||||
to_append_or_none = Some(PROCESS_EXPAND_SELF);
|
to_append_or_none = Some(PROCESS_EXPAND_SELF);
|
||||||
input_position += PROCESS_EXPAND_SELF_STR.len() - 1; // skip over 'self's
|
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
|
// 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
|
// is ANY_STRING, delete the last char and store ANY_STRING_RECURSIVE to
|
||||||
// reflect the fact that ** is the recursive wildcard.
|
// reflect the fact that ** is the recursive wildcard.
|
||||||
@@ -588,14 +585,12 @@ enum Mode {
|
|||||||
to_append_or_none = Some(ANY_STRING);
|
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);
|
to_append_or_none = Some(ANY_CHAR);
|
||||||
}
|
}
|
||||||
}
|
'$'
|
||||||
'$' => {
|
if unescape_special => {
|
||||||
if unescape_special {
|
|
||||||
let is_cmdsub = input_position + 1 < input.len()
|
let is_cmdsub = input_position + 1 < input.len()
|
||||||
&& input.char_at(input_position + 1) == '(';
|
&& input.char_at(input_position + 1) == '(';
|
||||||
if !is_cmdsub {
|
if !is_cmdsub {
|
||||||
@@ -603,18 +598,16 @@ enum Mode {
|
|||||||
vars_or_seps.push(input_position);
|
vars_or_seps.push(input_position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
'{'
|
||||||
'{' => {
|
if unescape_special => {
|
||||||
if unescape_special {
|
|
||||||
brace_count += 1;
|
brace_count += 1;
|
||||||
to_append_or_none = Some(BRACE_BEGIN);
|
to_append_or_none = Some(BRACE_BEGIN);
|
||||||
// We need to store where the brace *ends up* in the output.
|
// We need to store where the brace *ends up* in the output.
|
||||||
braces.push(result.len());
|
braces.push(result.len());
|
||||||
potential_word_start = Some(input_position + 1);
|
potential_word_start = Some(input_position + 1);
|
||||||
}
|
}
|
||||||
}
|
'}'
|
||||||
'}' => {
|
if unescape_special => {
|
||||||
if unescape_special {
|
|
||||||
// HACK: The completion machinery sometimes hands us partial tokens.
|
// HACK: The completion machinery sometimes hands us partial tokens.
|
||||||
// We can't parse them properly, but it shouldn't hurt,
|
// We can't parse them properly, but it shouldn't hurt,
|
||||||
// so we don't assert here.
|
// 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);
|
to_append_or_none = Some(BRACE_SEP);
|
||||||
vars_or_seps.push(input_position);
|
vars_or_seps.push(input_position);
|
||||||
potential_word_start = Some(input_position + 1);
|
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);
|
to_append_or_none = Some(BRACE_SPACE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
'\'' => {
|
'\'' => {
|
||||||
mode = Mode::SingleQuotes;
|
mode = Mode::SingleQuotes;
|
||||||
to_append_or_none = if unescape_special {
|
to_append_or_none = if unescape_special {
|
||||||
@@ -743,11 +733,9 @@ enum Mode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'$' => {
|
'$' if unescape_special => {
|
||||||
if unescape_special {
|
to_append_or_none = Some(VARIABLE_EXPAND_SINGLE);
|
||||||
to_append_or_none = Some(VARIABLE_EXPAND_SINGLE);
|
vars_or_seps.push(input_position);
|
||||||
vars_or_seps.push(input_position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1735,10 +1735,8 @@ enum Mode {
|
|||||||
|
|
||||||
match c {
|
match c {
|
||||||
'\\' => skip_next = true,
|
'\\' => skip_next = true,
|
||||||
'$' => {
|
'$' if (mode == Unquoted || mode == DoubleQuoted) => {
|
||||||
if mode == Unquoted || mode == DoubleQuoted {
|
variable_start = Some(in_pos);
|
||||||
variable_start = Some(in_pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'\'' => {
|
'\'' => {
|
||||||
if mode == SingleQuoted {
|
if mode == SingleQuoted {
|
||||||
|
|||||||
@@ -800,10 +800,8 @@ fn expand_braces(
|
|||||||
brace_end = Some(pos);
|
brace_end = Some(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BRACE_SEP => {
|
BRACE_SEP if brace_count == 1 => {
|
||||||
if brace_count == 1 {
|
last_sep = Some(pos);
|
||||||
last_sep = Some(pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// we ignore all other characters here
|
// we ignore all other characters here
|
||||||
|
|||||||
@@ -586,10 +586,8 @@ enum Mode {
|
|||||||
} else {
|
} else {
|
||||||
// Not a backslash.
|
// Not a backslash.
|
||||||
match c {
|
match c {
|
||||||
'~' => {
|
'~' if in_pos == 0 => {
|
||||||
if in_pos == 0 {
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||||
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'$' => {
|
'$' => {
|
||||||
assert!(in_pos < buff_len);
|
assert!(in_pos < buff_len);
|
||||||
@@ -597,10 +595,8 @@ enum Mode {
|
|||||||
// Subtract one to account for the upcoming loop increment.
|
// Subtract one to account for the upcoming loop increment.
|
||||||
in_pos -= 1;
|
in_pos -= 1;
|
||||||
}
|
}
|
||||||
'?' => {
|
'?' if !feature_test(FeatureFlag::QuestionMarkNoGlob) => {
|
||||||
if !feature_test(FeatureFlag::QuestionMarkNoGlob) {
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||||
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'*' | '(' | ')' => {
|
'*' | '(' | ')' => {
|
||||||
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);
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||||
bracket_count -= 1;
|
bracket_count -= 1;
|
||||||
}
|
}
|
||||||
',' => {
|
',' if bracket_count > 0 => {
|
||||||
if bracket_count > 0 {
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||||
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::operat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'\'' => {
|
'\'' => {
|
||||||
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::quote);
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::quote);
|
||||||
@@ -660,9 +654,9 @@ enum Mode {
|
|||||||
'"' => {
|
'"' => {
|
||||||
mode = Mode::unquoted;
|
mode = Mode::unquoted;
|
||||||
}
|
}
|
||||||
'\\' => {
|
'\\'
|
||||||
// Backslash
|
// Backslash
|
||||||
if in_pos + 1 < buff_len {
|
if in_pos + 1 < buff_len => {
|
||||||
let escaped_char = buffstr.as_char_slice()[in_pos + 1];
|
let escaped_char = buffstr.as_char_slice()[in_pos + 1];
|
||||||
if matches!(escaped_char, '\\' | '"' | '\n' | '$') {
|
if matches!(escaped_char, '\\' | '"' | '\n' | '$') {
|
||||||
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::escape); // backslash
|
colors[in_pos] = HighlightSpec::with_fg(HighlightRole::escape); // backslash
|
||||||
@@ -670,7 +664,6 @@ enum Mode {
|
|||||||
in_pos += 1; // skip over backslash
|
in_pos += 1; // skip over backslash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
'$' => {
|
'$' => {
|
||||||
in_pos += color_variable(&buffstr[in_pos..], &mut colors[in_pos..]);
|
in_pos += color_variable(&buffstr[in_pos..], &mut colors[in_pos..]);
|
||||||
// Subtract one to account for the upcoming increment in the loop.
|
// Subtract one to account for the upcoming increment in the loop.
|
||||||
|
|||||||
@@ -968,17 +968,13 @@ fn visit(&mut self, node: &'a dyn Node) {
|
|||||||
// ....cmd3
|
// ....cmd3
|
||||||
// end
|
// end
|
||||||
// See #7252.
|
// See #7252.
|
||||||
Kind::JobContinuation(node) => {
|
Kind::JobContinuation(node) if self.has_newline(&node.newlines) => {
|
||||||
if self.has_newline(&node.newlines) {
|
inc_dec = (1, 1);
|
||||||
inc_dec = (1, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Likewise for && and ||.
|
// Likewise for && and ||.
|
||||||
Kind::JobConjunctionContinuation(node) => {
|
Kind::JobConjunctionContinuation(node) if self.has_newline(&node.newlines) => {
|
||||||
if self.has_newline(&node.newlines) {
|
inc_dec = (1, 1);
|
||||||
inc_dec = (1, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Kind::CaseItemList(_) => {
|
Kind::CaseItemList(_) => {
|
||||||
@@ -1150,23 +1146,21 @@ pub fn detect_parse_errors_in_ast(
|
|||||||
let mut traversal = ast::Traversal::new(ast.top());
|
let mut traversal = ast::Traversal::new(ast.top());
|
||||||
while let Some(node) = traversal.next() {
|
while let Some(node) = traversal.next() {
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
Kind::JobContinuation(jc) => {
|
Kind::JobContinuation(jc)
|
||||||
// Somewhat clumsy way of checking for a statement without source in a pipeline.
|
// Somewhat clumsy way of checking for a statement without source in a pipeline.
|
||||||
// See if our pipe has source but our statement does not.
|
// 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;
|
has_unclosed_pipe = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Kind::JobConjunction(job_conjunction) => {
|
Kind::JobConjunction(job_conjunction) => {
|
||||||
issue.error |= detect_errors_in_job_conjunction(job_conjunction, &mut out_errors);
|
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.
|
// 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.
|
// 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;
|
has_unclosed_conjunction = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Kind::Argument(arg) => {
|
Kind::Argument(arg) => {
|
||||||
let arg_src = arg.source(buff_src);
|
let arg_src = arg.source(buff_src);
|
||||||
if let Err(e) = detect_errors_in_argument(arg, arg_src, &mut out_errors) {
|
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;
|
issue.incomplete |= e.incomplete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Kind::JobPipeline(job) => {
|
Kind::JobPipeline(job)
|
||||||
// Disallow background in the following cases:
|
// Disallow background in the following cases:
|
||||||
//
|
//
|
||||||
// foo & ; and bar
|
// foo & ; and bar
|
||||||
@@ -1182,11 +1176,10 @@ pub fn detect_parse_errors_in_ast(
|
|||||||
// if foo & ; end
|
// if foo & ; end
|
||||||
// while foo & ; end
|
// while foo & ; end
|
||||||
// If it's not a background job, nothing to do.
|
// If it's not a background job, nothing to do.
|
||||||
if job.bg.is_some() {
|
if job.bg.is_some() => {
|
||||||
issue.error |=
|
issue.error |=
|
||||||
detect_errors_in_backgrounded_job(&traversal, job, &mut out_errors);
|
detect_errors_in_backgrounded_job(&traversal, job, &mut out_errors);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Kind::DecoratedStatement(stmt) => {
|
Kind::DecoratedStatement(stmt) => {
|
||||||
issue.error |= detect_errors_in_decorated_statement(
|
issue.error |= detect_errors_in_decorated_statement(
|
||||||
buff_src,
|
buff_src,
|
||||||
|
|||||||
Reference in New Issue
Block a user