提交 c802fc71 编写于 作者: I Isaac van Bakel

Modified error for loop mut borrow conflicts

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.
上级 5c126bde
......@@ -466,19 +466,33 @@ pub fn report_error_if_loan_conflicts_with_restriction(&self,
let mut err = match (new_loan.kind, old_loan.kind) {
(ty::MutBorrow, ty::MutBorrow) => {
let mut err = struct_span_err!(self.bccx, new_loan.span, E0499,
"cannot borrow `{}`{} as mutable \
more than once at a time",
nl, new_loan_msg);
err.span_label(
old_loan.span,
format!("first mutable borrow occurs here{}", old_loan_msg));
err.span_label(
new_loan.span,
format!("second mutable borrow occurs here{}", new_loan_msg));
err.span_label(
previous_end_span,
"first borrow ends here");
err
"cannot borrow `{}`{} as mutable \
more than once at a time",
nl, new_loan_msg);
if new_loan.span == old_loan.span {
// Both borrows are happening in the same place
// Meaning the borrow is occuring in a loop
err.span_label(
new_loan.span,
format!("mutable borrow starts here in previous \
iteration of loop{}", new_loan_msg));
err.span_label(
previous_end_span,
"mutable borrow ends here");
err
} else {
err.span_label(
old_loan.span,
format!("first mutable borrow occurs here{}", old_loan_msg));
err.span_label(
new_loan.span,
format!("second mutable borrow occurs here{}", new_loan_msg));
err.span_label(
previous_end_span,
"first borrow ends here");
err
}
}
(ty::UniqueImmBorrow, ty::UniqueImmBorrow) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册