-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Extended error message for mut borrow conflicts in loops #43479
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
Conversation
Error message now makes clear that mutable borrow conflicts on a single value in a loop body is caused by the borrow outlasting a single pass of the loop. Loop conflicts are detected by seeing when two borrow locations are the same - which indicates the same code being run more than once.
@ivanbakel This is great! Could you add a |
Sure. What are the two cases? All the current message tests still pass. Or should I write tests for the different kind of loops? |
There should be at least two test cases, one that expects "first mutable borrow occurs here"/"second mutable borrow occurs here" to be displayed, and another that expects "mutable borrow starts here in previous iteration of loop". If in the test you can add you also add one case for each possible loop type ( |
One set of tests is to ensure the current message is correct. The other set is to check the messages are generated correctly for every type of loop.
Alright, the tests are added. Do I have to do something else as well as just writing the files? They run on my machine using `./x.py test'. |
Now we just wait for travis to finish so we can make sure there're no regressions in other platforms. When testing locally you can also do |
@bors r+ |
📌 Commit 6888520 has been approved by |
@bors rollup |
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.
☀️ Test successful - status-appveyor, status-travis |
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.