diff options
| author | bors <bors@rust-lang.org> | 2017-12-09 22:32:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-09 22:32:34 +0000 |
| commit | 8db163e53dab4f188a60bf24b4d6ebeb1ea5cab1 (patch) | |
| tree | d3be9c603291bfc560d1d8caab8a8d0761c53d31 | |
| parent | 6fa53b00e7450060a3af9b1ef63169db37e589c2 (diff) | |
| parent | 90f7c31d86a82cefddc3307f5fd491dd264119c4 (diff) | |
| download | rust-8db163e53dab4f188a60bf24b4d6ebeb1ea5cab1.tar.gz rust-8db163e53dab4f188a60bf24b4d6ebeb1ea5cab1.zip | |
Auto merge of #46572 - vramana:fix-45638, r=estebank
Fix bad error message for cannot_reborrow_already_uniquely_borrowed
| -rw-r--r-- | src/librustc_mir/borrow_check/mod.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/E0501.rs | 15 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 97d8a677fe8..30838b018d3 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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, diff --git a/src/test/compile-fail/E0501.rs b/src/test/compile-fail/E0501.rs index 04678b96c8d..f7e246e8f0f 100644 --- a/src/test/compile-fail/E0501.rs +++ b/src/test/compile-fail/E0501.rs @@ -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() { |
