Fix bad error message for cannot_reborrow_already_uniquely_borrowed

Fixes #45638
This commit is contained in:
Ramana Venkata 2017-12-08 02:45:11 +05:30
parent a8437a0acc
commit 90f7c31d86
2 changed files with 27 additions and 4 deletions

View file

@ -2334,12 +2334,24 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Origin::Mir,
),
(_, _, _, BorrowKind::Unique, _, _) => self.tcx
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => self.tcx
.cannot_reborrow_already_uniquely_borrowed(
span,
&desc_place,
"it",
"",
lft,
issued_span,
"",
end_issued_loan_span,
Origin::Mir,
),
(BorrowKind::Mut, _, lft, BorrowKind::Unique, _, _) => self.tcx
.cannot_reborrow_already_uniquely_borrowed(
span,
&desc_place,
"",
lft,
issued_span,
"",
end_issued_loan_span,

View file

@ -8,17 +8,28 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
fn inside_closure(x: &mut i32) {
}
fn outside_closure(x: &mut i32) {
fn outside_closure_1(x: &mut i32) {
}
fn outside_closure_2(x: &i32) {
}
fn foo(a: &mut i32) {
let bar = || {
inside_closure(a)
};
outside_closure(a); //~ ERROR E0501
outside_closure_1(a); //[ast]~ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
//[mir]~^ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
outside_closure_2(a); //[ast]~ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
//[mir]~^ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
}
fn main() {