Closed
Description
The 2018 edition adds an incorrect "in later iteration of loop" qualifier to the borrow checker error message if an issues occurs within a loop.
Repro code:
fn main() {
for _ in 0..1 {
let mut x = 1;
let xm = &mut x;
&x;
*xm = 2;
}
}
Actual Output:
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
--> src/main.rs:5:9
|
4 | let xm = &mut x;
| ------ mutable borrow occurs here
5 | &x;
| ^^ immutable borrow occurs here
6 | *xm = 2;
| ------- mutable borrow used here, in later iteration of loop
error: aborting due to previous error
For more information about this error, try `rustc --explain E0502`.
error: Could not compile `playground`.
Expected Output:
The error message should not say in later iteration of loop since the use occurs in the same iteration of the loop as both borrows. The value and the reference do not survive between loop iterations.
Rust version: stable (1.31.0)