Skip to content

Commit 3dd3c6d

Browse files
committed
Fix ICE involving mut references
1 parent 605ea9d commit 3dd3c6d

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10701070

10711071
(Reservation(WriteKind::MutableBorrow(bk)), BorrowKind::Shallow)
10721072
| (Reservation(WriteKind::MutableBorrow(bk)), BorrowKind::Shared) if {
1073-
tcx.migrate_borrowck()
1073+
tcx.migrate_borrowck() && this.borrow_set.location_map.get(&location).is_some()
10741074
} => {
10751075
let bi = this.borrow_set.location_map[&location];
10761076
debug!(

src/test/ui/issues/issue-61623.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn f1<'a>(_: &'a mut ()) {}
2+
3+
fn f2<P>(_: P, _: ()) {}
4+
5+
fn f3<'a>(x: &'a ((), &'a mut ())) {
6+
f2(|| x.0, f1(x.1))
7+
//~^ ERROR cannot borrow `*x.1` as mutable, as it is behind a `&` reference
8+
//~| ERROR cannot borrow `*x.1` as mutable because it is also borrowed as immutable
9+
}
10+
11+
fn main() {}

src/test/ui/issues/issue-61623.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0596]: cannot borrow `*x.1` as mutable, as it is behind a `&` reference
2+
--> $DIR/issue-61623.rs:6:19
3+
|
4+
LL | fn f3<'a>(x: &'a ((), &'a mut ())) {
5+
| -------------------- help: consider changing this to be a mutable reference: `&'a mut ((), &'a mut ())`
6+
LL | f2(|| x.0, f1(x.1))
7+
| ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
8+
9+
error[E0502]: cannot borrow `*x.1` as mutable because it is also borrowed as immutable
10+
--> $DIR/issue-61623.rs:6:19
11+
|
12+
LL | f2(|| x.0, f1(x.1))
13+
| -- -- - ^^^ mutable borrow occurs here
14+
| | | |
15+
| | | first borrow occurs due to use of `x` in closure
16+
| | immutable borrow occurs here
17+
| immutable borrow later used by call
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0502, E0596.
22+
For more information about an error, try `rustc --explain E0502`.

0 commit comments

Comments
 (0)