feat: handle if matches!() for replace_if_let_with_match#22079
Merged
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom Apr 26, 2026
Merged
feat: handle if matches!() for replace_if_let_with_match#22079ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
Conversation
46ab9fe to
d187af3
Compare
Example
---
```rust
fn foo(x: Result<i32, ()>) {
$0if matches!(x, Ok(a @ 1..2)) {
}
}
```
**Before this PR**
```rust
fn foo(x: Result<i32, ()>) {
match matches!(x, Ok(a @ 1..2)) {
true => {}
false => (),
}
}
```
**After this PR**
```rust
fn foo(x: Result<i32, ()>) {
match x {
Ok(a@1..2) => {}
_ => (),
}
}
```
d187af3 to
9e61113
Compare
ChayimFriedman2
approved these changes
Apr 26, 2026
| let input = tt.syntax().children_with_tokens().skip(1).take_while(|it| *it != r_delim); | ||
| // Only supports single top-level comma case | ||
| let [comma] = input.clone().filter(|it| it.kind() == T![,]).collect_array()?; | ||
| let input_rest = input.clone().skip_while(|it| *it != comma).skip(1); |
Contributor
There was a problem hiding this comment.
Why skip(1)? Is it to skip the whitespace? Better to skip only whitespace.
Member
Author
There was a problem hiding this comment.
input.clone().skip_while(|it| *it != comma)outputs", ..."input.clone().skip_while(|it| *it != comma).skip(1)outputs" ..."
| let input_expr = input.clone().take_while(|it| *it != comma).join(""); | ||
| let input_pat = input_rest.clone().take_while(|it| Some(it) != if_kwd.as_ref()); | ||
| let input_guard = | ||
| if_kwd.as_ref().map(|if_kwd| { input_rest }.skip_while(|it| it != if_kwd).skip(1).join("")); |
Contributor
There was a problem hiding this comment.
Here again no skip(1).
ChayimFriedman2
approved these changes
Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #20013
Example
Before this PR
After this PR