-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Changing mutable borrow check error when it occurs in a loop #2080
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
Labels
T-lang
Relevant to the language team, which will review and decide on the RFC.
Comments
I think that a PR would be sufficient for this. In general, if we can detect a particular case accurately (and with little overhead for the non-erroring path) more specific error messages are greatly preferable. |
What do you mean by a PR - a RFC PR, or a PR directly to the rust-lang/rust repo? |
Sorry, a PR directly to rust-lang/rust. |
bors
added a commit
to rust-lang/rust
that referenced
this issue
Jul 27, 2017
Extended error message for mut borrow conflicts in loops RFC issue: rust-lang/rfcs#2080 The error message for multiple mutable borrows on the same value over loop iterations now makes it clear that the conflict comes from the borrow outlasting the loop. The wording of the error is based on the special case of the moved-value error for a value moved in a loop. Following the example of that error, the code remains the same for the special case. This is mainly because I felt the current message is confusing in the loop case : #43437. It's not clear that the two conflicting borrows are in different iterations of the loop, and instead it just looks like the compiler has an issue with a single line.
My PR was merged, so I'm closing this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm happy to write up a full RFC for this, but I'd prefer to float the idea and understand if more contextual messages are a good thing. Inspired by my own experience in rust-lang/rust#43437, the message for two mutable borrows doesn't account for the case of loops - producing an error message that looks strange and doesn't really communicate what the borrow checker is having a problem with.
I'd like to change it so that the formatted message is changed based on it occuring inside a loop, similar to the
use of moved value
error message, which specifies when the move occurs in a loop iteration.The code is already written, in ivanbakel/rust@53fb2a5 .
The text was updated successfully, but these errors were encountered: