Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/ui/nll/polonius/nll-legacy-unnecessary-error.legacy.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0506]: cannot assign to `z` because it is borrowed
--> $DIR/nll-legacy-unnecessary-error.rs:20:5
|
LL | x.0 = &z;
| -- `z` is borrowed here
LL | z += 1;
| ^^^^^^ `z` is assigned to here but it was already borrowed
...
LL | dbg!(y.0);
| --- borrow later used here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0506`.
14 changes: 14 additions & 0 deletions tests/ui/nll/polonius/nll-legacy-unnecessary-error.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0506]: cannot assign to `z` because it is borrowed
--> $DIR/nll-legacy-unnecessary-error.rs:20:5
|
LL | x.0 = &z;
| -- `z` is borrowed here
LL | z += 1;
| ^^^^^^ `z` is assigned to here but it was already borrowed
...
LL | dbg!(y.0);
| --- borrow later used here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0506`.
25 changes: 25 additions & 0 deletions tests/ui/nll/polonius/nll-legacy-unnecessary-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// NLLs and legacy polonius emit an unnecessary error here, unlike the alpha. It's not clear
// *exactly* why the datalog implementation rejects this, but it looks like it propagates the loan
// from 'x to 'y very eagerly, even though x is dead before the assignment. The loan would thus be
// live and invalidated by the assignment, AKA an error.

//@ ignore-compare-mode-polonius (explicit revisions)
//@ revisions: nll polonius legacy
//@ [nll] compile-flags: -Z polonius=off
//@ [polonius] check-pass
//@ [polonius] compile-flags: -Z polonius=next
//@ [legacy] compile-flags: -Z polonius=legacy

fn main() {
let mut x: (&u32,) = (&1,);
let mut y: (&u32,) = (&2,);
let mut z = 3;

y.0 = x.0;
x.0 = &z;
z += 1;
//[nll]~^ ERROR: cannot assign to `z` because it is borrowed
//[legacy]~^^ ERROR: cannot assign to `z` because it is borrowed

dbg!(y.0);
}
Loading