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

Add suggestion to reborrow mutable references when they're moved in a for loop #83945

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

SkiFire13
Copy link
Contributor

@SkiFire13 SkiFire13 commented Apr 6, 2021

Address #83924

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2021
@eggyal
Copy link
Contributor

eggyal commented Apr 6, 2021

This is definitely a better diagnostic, but (as mentioned in the underlying issue) I wonder if it's not possible to fix the desugaring so that &&Vec etc are actually iterable.

@SkiFire13
Copy link
Contributor Author

Even if &&mut Vec was iterable I don't think that would be what the user actually wants. Chances are that the code inside the loop expects the item to be some sort of mutable reference, so iterating over a &&mut Vec would still not work. If &mut &mut Vec was iterable then adding a &mut would also be another valid suggestion, but that's no different than suggesting to reborrow.

@eggyal
Copy link
Contributor

eggyal commented Apr 6, 2021

If &mut &mut Vec was iterable

To be completely clear, I did indeed mean to fix desugaring so that &mut &mut Vec (and indeed anything that can be deref-coerced to an iterable) is also iterable.

then adding a &mut would also be another valid suggestion, but that's no different than suggesting to reborrow.

Aye that's fair, although obviously it would also catch other scenarios too.

@estebank
Copy link
Contributor

estebank commented Apr 6, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 6, 2021

📌 Commit a775984 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2021
@estebank
Copy link
Contributor

estebank commented Apr 6, 2021

Let's not close the reporting ticket on merge so that an alternative desugaring can be explored to make this code Just Work™️.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 7, 2021
Add suggestion to reborrow mutable references when they're moved in a for loop

Address rust-lang#83924
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#83476 (Add strong_count mutation methods to Rc)
 - rust-lang#83634 (Do not emit the advanced diagnostics on macros)
 - rust-lang#83816 (Trigger `unused_doc_comments` on macros at once)
 - rust-lang#83916 (Use AnonConst for asm! constants)
 - rust-lang#83935 (forbid `impl Trait` in generic param defaults)
 - rust-lang#83936 (Disable using non-ascii identifiers in extern blocks.)
 - rust-lang#83945 (Add suggestion to reborrow mutable references when they're moved in a for loop)
 - rust-lang#83954 (Do not ICE when closure is involved in Trait Alias Impl Trait)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d7d42cc into rust-lang:master Apr 7, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 7, 2021
@SkiFire13 SkiFire13 deleted the fix-83924 branch April 7, 2021 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants