Skip to content

Commit 97ac9dd

Browse files
authored
Rollup merge of #58008 - matthewjasper:places-conflict-args, r=oli-obk
Pass correct arguments to places_conflict The borrow place *must* be a place that we track borrows for, otherwise we will likely ICE. Closes #57989
2 parents a972c10 + 6fe370c commit 97ac9dd

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
215215
if places_conflict::places_conflict(
216216
self.tcx,
217217
self.mir,
218-
place,
219218
&borrow_data.borrowed_place,
219+
place,
220220
places_conflict::PlaceConflictBias::NoOverlap,
221221
) {
222222
debug!(

src/test/ui/nll/issue-57989.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test for ICE from issue 57989
2+
3+
#![feature(nll)]
4+
5+
fn f(x: &i32) {
6+
let g = &x;
7+
*x = 0; //~ ERROR cannot assign to `*x` which is behind a `&` reference
8+
//~| ERROR cannot assign to `*x` because it is borrowed
9+
g;
10+
}
11+
12+
fn main() {}

src/test/ui/nll/issue-57989.stderr

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0594]: cannot assign to `*x` which is behind a `&` reference
2+
--> $DIR/issue-57989.rs:7:5
3+
|
4+
LL | fn f(x: &i32) {
5+
| ---- help: consider changing this to be a mutable reference: `&mut i32`
6+
LL | let g = &x;
7+
LL | *x = 0; //~ ERROR cannot assign to `*x` which is behind a `&` reference
8+
| ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
9+
10+
error[E0506]: cannot assign to `*x` because it is borrowed
11+
--> $DIR/issue-57989.rs:7:5
12+
|
13+
LL | let g = &x;
14+
| -- borrow of `*x` occurs here
15+
LL | *x = 0; //~ ERROR cannot assign to `*x` which is behind a `&` reference
16+
| ^^^^^^ assignment to borrowed `*x` occurs here
17+
LL | //~| ERROR cannot assign to `*x` because it is borrowed
18+
LL | g;
19+
| - borrow later used here
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors occurred: E0506, E0594.
24+
For more information about an error, try `rustc --explain E0506`.

0 commit comments

Comments
 (0)