Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match_bool: fix suggestion if guard is present #14039

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

samueltardieu
Copy link
Contributor

Without this check, the lint would suggest that

    match test {
        true if option == 5 => 10,
        _ => 1,
    };

is replaced by if test { 10 } else { 1 }.

changelog: [match_bool]: omit suggestion when guards are present in match expression

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 20, 2025
@llogiq
Copy link
Contributor

llogiq commented Jan 20, 2025

Wouldn't it be better to && the guard onto the scrutinee? E.g. in your example, suggest if test && option == 5 { 10 } else { 1 }?

@samueltardieu
Copy link
Contributor Author

Wouldn't it be better to && the guard onto the scrutinee? E.g. in your example, suggest if test && option == 5 { 10 } else { 1 }?

Indeed, done.

I also enabled rustfix on the ui test.

Without this check, the lint would suggest that

```rust
    match test {
        true if option == 5 => 10,
        _ => 1,
    };
```

is replaced by `if test { 10 } else { 1 }`.
@llogiq llogiq changed the title match_bool: omit suggestion if guard is present match_bool: fix suggestion if guard is present Jan 22, 2025
@llogiq
Copy link
Contributor

llogiq commented Jan 22, 2025

Thanks!

@llogiq llogiq added this pull request to the merge queue Jan 22, 2025
Merged via the queue into rust-lang:master with commit 106db26 Jan 22, 2025
13 checks passed
@samueltardieu samueltardieu deleted the push-suqovkvqlzuz branch January 22, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants