-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Better messages for next
inside for
loops
#102972
Comments
@rustbot claim |
It's hard to get 'c' in line 3 during the context where the compiler errors out the second mutable borrow message, because the mutable borrow happens between |
I don't think it's critical to mention @rustbot label +D-newcomer-roadblock |
I'd love to try to fix this, but sadly I'm not familiar with the internals of rustc. If someone could point me towards the section where this error is, I could give it a try. |
Hi @lylythechosenone ! Whenever I try to dive into fixing a problem with rustc, I usually start with a search through the codebase. In this case, I'd search for strings that come from the error message: And that leads me to here: rust/compiler/rustc_borrowck/src/borrowck_errors.rs Lines 36 to 84 in 7d85104
So then I'd use rust-analyzer to try to find all the usages of that method. In this case, turns out there's only one: rust/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Lines 814 to 830 in 7d85104
And there we see that there is already some conditional suggestion being made; it calls You'll need to figure out how to sort of "back track" from the MIR back to the HIR or the AST so you can figure out whether you're inside a And don't forget to write a handful of regression tests in It might also be possible to perform this check at a higher level, say, in |
…next, r=compiler-errors Better messages for next on a iterator inside for loops Fixes rust-lang#102972
…next, r=compiler-errors Better messages for next on a iterator inside for loops Fixes rust-lang#102972
Given the following code:
playground
The current output is:
Ideally the output should look like:
or similar. The note and/or help are both subject to changes, this is just a basic idea.
We could also conceivably rewrite the error message to expand on what the note says, like so:
The text was updated successfully, but these errors were encountered: