Refer to the second borrow as the "second borrow".
This commit is contained in:
parent
3e90a12a8a
commit
1560a75f6a
@ -615,7 +615,7 @@ pub fn report_error_if_loan_conflicts_with_restriction(&self,
|
||||
let new_loan_str = &new_loan.kind.to_user_str();
|
||||
self.bccx.cannot_reborrow_already_uniquely_borrowed(
|
||||
new_loan.span, "closure", &nl, &new_loan_msg, new_loan_str,
|
||||
old_loan.span, &old_loan_msg, previous_end_span, Origin::Ast)
|
||||
old_loan.span, &old_loan_msg, previous_end_span, "", Origin::Ast)
|
||||
}
|
||||
(..) =>
|
||||
self.bccx.cannot_reborrow_already_borrowed(
|
||||
|
@ -344,6 +344,13 @@ pub(super) fn report_conflicting_borrow(
|
||||
|
||||
let first_borrow_desc;
|
||||
|
||||
let explanation = self.explain_why_borrow_contains_point(context, issued_borrow, None);
|
||||
let second_borrow_desc = if explanation.is_explained() {
|
||||
"second "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
// FIXME: supply non-"" `opt_via` when appropriate
|
||||
let mut err = match (
|
||||
gen_borrow_kind,
|
||||
@ -454,6 +461,7 @@ pub(super) fn report_conflicting_borrow(
|
||||
issued_span,
|
||||
"",
|
||||
None,
|
||||
second_borrow_desc,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
@ -469,6 +477,7 @@ pub(super) fn report_conflicting_borrow(
|
||||
issued_span,
|
||||
"",
|
||||
None,
|
||||
second_borrow_desc,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
@ -513,7 +522,7 @@ pub(super) fn report_conflicting_borrow(
|
||||
);
|
||||
}
|
||||
|
||||
self.explain_why_borrow_contains_point(context, issued_borrow, None)
|
||||
explanation
|
||||
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, first_borrow_desc);
|
||||
|
||||
err.buffer(&mut self.errors_buffer);
|
||||
|
@ -52,6 +52,12 @@ pub(in borrow_check) enum LaterUseKind {
|
||||
}
|
||||
|
||||
impl BorrowExplanation {
|
||||
pub(in borrow_check) fn is_explained(&self) -> bool {
|
||||
match self {
|
||||
BorrowExplanation::Unexplained => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx, 'tcx>(
|
||||
&self,
|
||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
|
@ -261,6 +261,7 @@ fn cannot_reborrow_already_uniquely_borrowed(
|
||||
old_loan_span: Span,
|
||||
old_opt_via: &str,
|
||||
previous_end_span: Option<Span>,
|
||||
second_borrow_desc: &str,
|
||||
o: Origin,
|
||||
) -> DiagnosticBuilder<'cx> {
|
||||
let mut err = struct_span_err!(
|
||||
@ -274,7 +275,10 @@ fn cannot_reborrow_already_uniquely_borrowed(
|
||||
kind_new,
|
||||
OGN = o
|
||||
);
|
||||
err.span_label(new_loan_span, format!("borrow occurs here{}", opt_via));
|
||||
err.span_label(
|
||||
new_loan_span,
|
||||
format!("{}borrow occurs here{}", second_borrow_desc, opt_via),
|
||||
);
|
||||
err.span_label(
|
||||
old_loan_span,
|
||||
format!("{} construction occurs here{}", container_name, old_opt_via),
|
||||
|
@ -7,7 +7,7 @@ LL | inside_closure(a)
|
||||
| - first borrow occurs due to use of `a` in closure
|
||||
LL | };
|
||||
LL | outside_closure_1(a); //[ast]~ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
|
||||
| ^ borrow occurs here
|
||||
| ^ second borrow occurs here
|
||||
...
|
||||
LL | drop(bar);
|
||||
| --- first borrow later used here
|
||||
@ -21,7 +21,7 @@ LL | inside_closure(a)
|
||||
| - first borrow occurs due to use of `a` in closure
|
||||
...
|
||||
LL | outside_closure_2(a); //[ast]~ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
|
||||
| ^ borrow occurs here
|
||||
| ^ second borrow occurs here
|
||||
...
|
||||
LL | drop(bar);
|
||||
| --- first borrow later used here
|
||||
|
@ -7,7 +7,7 @@ LL | inside_closure(a)
|
||||
| - first borrow occurs due to use of `a` in closure
|
||||
LL | };
|
||||
LL | outside_closure_1(a); //[ast]~ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
|
||||
| ^ borrow occurs here
|
||||
| ^ second borrow occurs here
|
||||
...
|
||||
LL | drop(bar);
|
||||
| --- first borrow later used here
|
||||
@ -21,7 +21,7 @@ LL | inside_closure(a)
|
||||
| - first borrow occurs due to use of `a` in closure
|
||||
...
|
||||
LL | outside_closure_2(a); //[ast]~ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
|
||||
| ^ borrow occurs here
|
||||
| ^ second borrow occurs here
|
||||
...
|
||||
LL | drop(bar);
|
||||
| --- first borrow later used here
|
||||
|
@ -10,7 +10,7 @@ LL | | |a| { //~ ERROR closure requires unique access to `f`
|
||||
LL | | f.n.insert(*a);
|
||||
| | - first borrow occurs due to use of `f` in closure
|
||||
LL | | })
|
||||
| |__________^ borrow occurs here
|
||||
| |__________^ second borrow occurs here
|
||||
|
||||
error[E0500]: closure requires unique access to `f` but it is already borrowed
|
||||
--> $DIR/borrowck-insert-during-each.rs:27:9
|
||||
|
@ -7,7 +7,7 @@ LL | let a = &mut *x;
|
||||
| - first borrow occurs due to use of `x` in generator
|
||||
...
|
||||
LL | println!("{}", x); //~ ERROR
|
||||
| ^ borrow occurs here
|
||||
| ^ second borrow occurs here
|
||||
LL | b.resume();
|
||||
| - first borrow later used here
|
||||
|
||||
|
@ -126,7 +126,7 @@ LL | let f = || *x = 0;
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | let y = &x; //~ ERROR
|
||||
| ^^ borrow occurs here
|
||||
| ^^ second borrow occurs here
|
||||
LL | f.use_ref();
|
||||
| - first borrow later used here
|
||||
|
||||
@ -138,7 +138,7 @@ LL | let f = || *x = 0;
|
||||
| |
|
||||
| closure construction occurs here
|
||||
LL | let y = &mut x; //~ ERROR
|
||||
| ^^^^^^ borrow occurs here
|
||||
| ^^^^^^ second borrow occurs here
|
||||
LL | f.use_ref();
|
||||
| - first borrow later used here
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user