-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Bad suggestion when implicit loop .iter()
should be made mutable
#94060
Comments
.iter()
should be made mutable
In this case the compiler suggestion would compile just fine, so I'm a bit unsure whether suggesting &mut item here is the right thing, since you may want to consume the item later in the loop body. |
@TrolledWoods Thank you for taking a look. It seems I over-reduced the testcase, since the original did not compile when following the compiler suggestion. I've updated the issue description with a less reduced testcase that still shows the issue. |
I think the right change would be for the following
to suggest iterating on |
Current output, no real change:
If we follow the suggestions:
we eventually get to code that compiles. |
Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b3ca40d8d38fae14b7bab120a85b2b8a
(From AoC, in case it wasn't obvious 😆)
The current output is:
Ideally the output should look like:
ie: To suggest changing the implicit loop iteration
for card in bingo_game.cards
to eitherfor card in &mut bingo_game.cards
or elsefor card in bingo_game.cards.iter_mut()
.CC #62387, #82081. (I've filed a new issue since the #62387 uses closures, and #82081 is about E0594 not E0596)
The text was updated successfully, but these errors were encountered: