Skip to content

Commit 3ebe204

Browse files
Rollup merge of #160588 - lqd:nighty-wheat-thins, r=jackh726
add a test showing polonius alpha is not a subset of datalog polonius This adds a test showing how the datalog and alpha algorithms are not subsets of one another, and are slightly distinct subsets of a platonic ideal borrowck. r? @jackh726
2 parents 481ed9d + 354cedd commit 3ebe204

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0506]: cannot assign to `z` because it is borrowed
2+
--> $DIR/nll-legacy-unnecessary-error.rs:20:5
3+
|
4+
LL | x.0 = &z;
5+
| -- `z` is borrowed here
6+
LL | z += 1;
7+
| ^^^^^^ `z` is assigned to here but it was already borrowed
8+
...
9+
LL | dbg!(y.0);
10+
| --- borrow later used here
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0506`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0506]: cannot assign to `z` because it is borrowed
2+
--> $DIR/nll-legacy-unnecessary-error.rs:20:5
3+
|
4+
LL | x.0 = &z;
5+
| -- `z` is borrowed here
6+
LL | z += 1;
7+
| ^^^^^^ `z` is assigned to here but it was already borrowed
8+
...
9+
LL | dbg!(y.0);
10+
| --- borrow later used here
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0506`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// NLLs and legacy polonius emit an unnecessary error here, unlike the alpha. It's not clear
2+
// *exactly* why the datalog implementation rejects this, but it looks like it propagates the loan
3+
// from 'x to 'y very eagerly, even though x is dead before the assignment. The loan would thus be
4+
// live and invalidated by the assignment, AKA an error.
5+
6+
//@ ignore-compare-mode-polonius (explicit revisions)
7+
//@ revisions: nll polonius legacy
8+
//@ [nll] compile-flags: -Z polonius=off
9+
//@ [polonius] check-pass
10+
//@ [polonius] compile-flags: -Z polonius=next
11+
//@ [legacy] compile-flags: -Z polonius=legacy
12+
13+
fn main() {
14+
let mut x: (&u32,) = (&1,);
15+
let mut y: (&u32,) = (&2,);
16+
let mut z = 3;
17+
18+
y.0 = x.0;
19+
x.0 = &z;
20+
z += 1;
21+
//[nll]~^ ERROR: cannot assign to `z` because it is borrowed
22+
//[legacy]~^^ ERROR: cannot assign to `z` because it is borrowed
23+
24+
dbg!(y.0);
25+
}

0 commit comments

Comments
 (0)