Skip to content

Commit 089b628

Browse files
authored
Parser clean up. (nushell#16668)
- Rewrite `if matches!(val, pat) { .. }` expressions as `if let pat = val { .. }` - Replace `if matches!(..) {..}` with `match` expressions where it makes code easier to understand - Use combinator methods instead of imperative code in a few places. - Slay the [beast](nushell/nushell@69857c1...c430bcd) ## Release notes summary - What our users need to know N/A ## Tasks after submitting N/A
1 parent 3c83ea7 commit 089b628

File tree

63 files changed

+164
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+164
-198
lines changed

crates/nu-cli/src/completions/completer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,14 @@ impl NuCompleter {
394394
// - "--foo ..a" => ["--foo", "..a"] => "..a"
395395
// - "--foo=..a" => ["--foo", "..a"] => "..a"
396396
// - strip placeholder (`a`) if present
397-
let (new_span, prefix) = if matches!(arg, Argument::Named(_)) {
398-
strip_placeholder_with_rsplit(
397+
let (new_span, prefix) = match arg {
398+
Argument::Named(_) => strip_placeholder_with_rsplit(
399399
working_set,
400400
&span,
401401
|b| *b == b'=' || *b == b' ',
402402
strip,
403-
)
404-
} else {
405-
strip_placeholder_if_any(working_set, &span, strip)
403+
),
404+
_ => strip_placeholder_if_any(working_set, &span, strip),
406405
};
407406
let ctx = Context::new(working_set, new_span, prefix, offset);
408407

crates/nu-cli/src/completions/operator_completions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Completer for OperatorCompletion<'_> {
229229
Type::Any => match &self.left_hand_side.expr {
230230
Expr::FullCellPath(path) => {
231231
// for `$ <tab>`
232-
if matches!(path.head.expr, Expr::Garbage) {
232+
if let Expr::Garbage = path.head.expr {
233233
return vec![];
234234
}
235235
let value =

crates/nu-cmd-extra/src/extra/bits/and.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Command for BitsAnd {
7373
};
7474

7575
// This doesn't match explicit nulls
76-
if matches!(input, PipelineData::Empty) {
76+
if let PipelineData::Empty = input {
7777
return Err(ShellError::PipelineEmpty { dst_span: head });
7878
}
7979

crates/nu-cmd-extra/src/extra/bits/not.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Command for BitsNot {
7373
let number_size = get_number_bytes(number_bytes, head)?;
7474

7575
// This doesn't match explicit nulls
76-
if matches!(input, PipelineData::Empty) {
76+
if let PipelineData::Empty = input {
7777
return Err(ShellError::PipelineEmpty { dst_span: head });
7878
}
7979

crates/nu-cmd-extra/src/extra/bits/or.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Command for BitsOr {
7474
};
7575

7676
// This doesn't match explicit nulls
77-
if matches!(input, PipelineData::Empty) {
77+
if let PipelineData::Empty = input {
7878
return Err(ShellError::PipelineEmpty { dst_span: head });
7979
}
8080

crates/nu-cmd-extra/src/extra/bits/rotate_left.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Command for BitsRol {
7575
let number_size = get_number_bytes(number_bytes, head)?;
7676

7777
// This doesn't match explicit nulls
78-
if matches!(input, PipelineData::Empty) {
78+
if let PipelineData::Empty = input {
7979
return Err(ShellError::PipelineEmpty { dst_span: head });
8080
}
8181

crates/nu-cmd-extra/src/extra/bits/rotate_right.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Command for BitsRor {
7575
let number_size = get_number_bytes(number_bytes, head)?;
7676

7777
// This doesn't match explicit nulls
78-
if matches!(input, PipelineData::Empty) {
78+
if let PipelineData::Empty = input {
7979
return Err(ShellError::PipelineEmpty { dst_span: head });
8080
}
8181

crates/nu-cmd-extra/src/extra/bits/shift_left.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Command for BitsShl {
8080
let number_size = get_number_bytes(number_bytes, head)?;
8181

8282
// This doesn't match explicit nulls
83-
if matches!(input, PipelineData::Empty) {
83+
if let PipelineData::Empty = input {
8484
return Err(ShellError::PipelineEmpty { dst_span: head });
8585
}
8686

crates/nu-cmd-extra/src/extra/bits/shift_right.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Command for BitsShr {
7777
let number_size = get_number_bytes(number_bytes, head)?;
7878

7979
// This doesn't match explicit nulls
80-
if matches!(input, PipelineData::Empty) {
80+
if let PipelineData::Empty = input {
8181
return Err(ShellError::PipelineEmpty { dst_span: head });
8282
}
8383

crates/nu-cmd-extra/src/extra/bits/xor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Command for BitsXor {
7474
};
7575

7676
// This doesn't match explicit nulls
77-
if matches!(input, PipelineData::Empty) {
77+
if let PipelineData::Empty = input {
7878
return Err(ShellError::PipelineEmpty { dst_span: head });
7979
}
8080

0 commit comments

Comments
 (0)