Skip to content

Commit 8db163e

Browse files
committed
Auto merge of #46572 - vramana:fix-45638, r=estebank
Fix bad error message for cannot_reborrow_already_uniquely_borrowed
2 parents 6fa53b0 + 90f7c31 commit 8db163e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/librustc_mir/borrow_check/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -2334,12 +2334,24 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
23342334
Origin::Mir,
23352335
),
23362336

2337-
(_, _, _, BorrowKind::Unique, _, _) => self.tcx
2337+
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => self.tcx
23382338
.cannot_reborrow_already_uniquely_borrowed(
23392339
span,
23402340
&desc_place,
2341-
"it",
23422341
"",
2342+
lft,
2343+
issued_span,
2344+
"",
2345+
end_issued_loan_span,
2346+
Origin::Mir,
2347+
),
2348+
2349+
(BorrowKind::Mut, _, lft, BorrowKind::Unique, _, _) => self.tcx
2350+
.cannot_reborrow_already_uniquely_borrowed(
2351+
span,
2352+
&desc_place,
2353+
"",
2354+
lft,
23432355
issued_span,
23442356
"",
23452357
end_issued_loan_span,

src/test/compile-fail/E0501.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
// revisions: ast mir
13+
//[mir]compile-flags: -Z borrowck=mir
14+
1115
fn inside_closure(x: &mut i32) {
1216
}
1317

14-
fn outside_closure(x: &mut i32) {
18+
fn outside_closure_1(x: &mut i32) {
19+
}
20+
21+
fn outside_closure_2(x: &i32) {
1522
}
1623

1724
fn foo(a: &mut i32) {
1825
let bar = || {
1926
inside_closure(a)
2027
};
21-
outside_closure(a); //~ ERROR E0501
28+
outside_closure_1(a); //[ast]~ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
29+
//[mir]~^ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
30+
31+
outside_closure_2(a); //[ast]~ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
32+
//[mir]~^ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
2233
}
2334

2435
fn main() {

0 commit comments

Comments
 (0)