Skip to content

Fix bad error message for cannot_reborrow_already_uniquely_borrowed #46572

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

Merged
merged 1 commit into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/test/compile-fail/E0501.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down