-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add convert_for_to_iter_for_each assist #7741
Conversation
You'll have to rebase as the |
I think the best approach here is to just wrap the iterable in Edit: Actually we should be able to check if an |
* Move code to build replacement into closure * Look for iter/iter_mut methods on types behind reference
8e27a1c
to
98a6264
Compare
crates/ide_assists/src/handlers/convert_for_to_iter_for_each.rs
Outdated
Show resolved
Hide resolved
crates/ide_assists/src/handlers/convert_for_to_iter_for_each.rs
Outdated
Show resolved
Hide resolved
2 more things aside from that it looks good to me 👍 |
✌️ mattyhall can now approve this pull request. To approve and merge a pull request, simply reply with |
* Use known names for iter/iter_mut method (simplifies checking if the method exists * Extract code to check assist with fixtures to function
bors r+ |
FWIW this seems to somewhat unhelpfully trigger on I think in that case the assist either should not trigger, or it should use |
That is not intended and was an oversight, could you open an issue for that? |
Gladly, sorry I wasted such a fun issue number as #11111 for it. |
Implements one direction of #7681
I wonder if this tries to guess too much at the right thing here. A common pattern is:
I've tried to detect this case by checking if the expression after the
in
is a (mutable) reference and if not inserting iter()/iter_mut(). This is just a convention used in the stdlib however, so could sometimes be wrong. I'd be happy to make an improvement for this, but not sure what would be best. A few options spring to mind:.into_iter()
to whatever is afterin