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

feat: add bool_to_enum assist for parameters #17467

Merged
merged 2 commits into from
Jun 30, 2024
Merged

feat: add bool_to_enum assist for parameters #17467

merged 2 commits into from
Jun 30, 2024

Conversation

winstxnhdw
Copy link
Contributor

@winstxnhdw winstxnhdw commented Jun 20, 2024

Summary

This PR adds parameter support for bool_to_enum assists. Essentially, the assist can now transform this:

fn function($0foo: bool) {
    if foo {
        println!("foo");
    }
}

To this,

#[derive(PartialEq, Eq)]
enum Bool { True, False }

fn function(foo: Bool) {
    if foo == Bool::True {
        println!("foo");
    }
}

Thanks to @/davidbarsky for the test skeleton (:

Closes #17400

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2024
@winstxnhdw winstxnhdw marked this pull request as ready for review June 20, 2024 21:19
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay one more simplification, I didn't realize the code generally assumes a top level ident pattern only, so using ancestor is wrong. We want to check if the ident pattern is the top most patterns in the statement/param.

Also could you squash the commits? There is a lot of very small commits that I don't think add any value here

crates/ide-assists/src/handlers/bool_to_enum.rs Outdated Show resolved Hide resolved
crates/ide-assists/src/handlers/bool_to_enum.rs Outdated Show resolved Hide resolved
crates/ide-assists/src/handlers/bool_to_enum.rs Outdated Show resolved Hide resolved
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2024
@@ -784,7 +880,6 @@ fn main() {

#[test]
fn local_variable_non_ident_pat() {
cov_mark::check!(not_applicable_in_non_ident_pat);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure, but I don't think this should ever hit anymore.

@Veykril
Copy link
Member

Veykril commented Jun 30, 2024

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Jun 30, 2024

📌 Commit d468746 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jun 30, 2024

⌛ Testing commit d468746 with merge 7e8f9c8...

@bors
Copy link
Contributor

bors commented Jun 30, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 7e8f9c8 to master...

@bors bors merged commit 7e8f9c8 into rust-lang:master Jun 30, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bool_to_enum assist should work on parameters
5 participants