Skip to content

Commit

Permalink
add explicit revisions to polonius tests
Browse files Browse the repository at this point in the history
The blessed expectations were recently removed because they were only
checked via the compare-mode. This switches to explicit revisions to
ensure it doesn't happen again.

- `assignment-to-differing-field`
- `polonius-smoke-test`
- `subset-relations`
  • Loading branch information
lqd committed Jan 31, 2025
1 parent e2d1641 commit 18d417f
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `list.0.value` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:20:21
--> $DIR/assignment-to-differing-field.rs:23:21
|
LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
Expand All @@ -11,7 +11,7 @@ LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.next` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:23:26
--> $DIR/assignment-to-differing-field.rs:26:26
|
LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
Expand All @@ -23,7 +23,7 @@ LL | list.1 = n;
| ---------- assignment requires that `list.0.next` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.0.0.0.0.value` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:37:21
--> $DIR/assignment-to-differing-field.rs:40:21
|
LL | fn assignment_through_projection_chain<'a, T>(
| -- lifetime `'a` defined here
Expand All @@ -35,7 +35,7 @@ LL | return result;
| ------ returning this value requires that `list.0.0.0.0.0.value` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.0.0.0.0.next` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:40:26
--> $DIR/assignment-to-differing-field.rs:43:26
|
LL | fn assignment_through_projection_chain<'a, T>(
| -- lifetime `'a` defined here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error[E0499]: cannot borrow `list.0.value` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:23:21
|
LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
...
LL | result.push(&mut (list.0).value);
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
...
LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.next` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:26:26
|
LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
...
LL | if let Some(n) = (list.0).next.as_mut() {
| ^^^^^^^^^^^^^ `list.0.next` was mutably borrowed here in the previous iteration of the loop
LL |
LL | list.1 = n;
| ---------- assignment requires that `list.0.next` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.0.0.0.0.value` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:40:21
|
LL | fn assignment_through_projection_chain<'a, T>(
| -- lifetime `'a` defined here
...
LL | result.push(&mut ((((list.0).0).0).0).0.value);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.value` was mutably borrowed here in the previous iteration of the loop
...
LL | return result;
| ------ returning this value requires that `list.0.0.0.0.0.value` is borrowed for `'a`

error[E0499]: cannot borrow `list.0.0.0.0.0.next` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:43:26
|
LL | fn assignment_through_projection_chain<'a, T>(
| -- lifetime `'a` defined here
...
LL | if let Some(n) = ((((list.0).0).0).0).0.next.as_mut() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.next` was mutably borrowed here in the previous iteration of the loop
LL |
LL | *((((list.0).0).0).0).1 = n;
| --------------------------- assignment requires that `list.0.0.0.0.0.next` is borrowed for `'a`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0499`.
5 changes: 4 additions & 1 deletion tests/ui/nll/polonius/assignment-to-differing-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
// that we do not kill too many borrows. Assignments to the `.1`
// field projections should leave the borrows on `.0` intact.

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

struct List<T> {
value: T,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0515]: cannot return reference to local variable `x`
--> $DIR/polonius-smoke-test.rs:6:5
--> $DIR/polonius-smoke-test.rs:10:5
|
LL | &x
| ^^ returns a reference to data owned by the current function

error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/polonius-smoke-test.rs:12:13
--> $DIR/polonius-smoke-test.rs:16:13
|
LL | let y = &mut x;
| ------ `x` is borrowed here
Expand All @@ -15,7 +15,7 @@ LL | let w = y;
| - borrow later used here

error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/polonius-smoke-test.rs:18:13
--> $DIR/polonius-smoke-test.rs:22:13
|
LL | pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
| - - let's call the lifetime of this reference `'1`
Expand All @@ -35,7 +35,7 @@ LL + let y = &mut x.clone();
|

error[E0505]: cannot move out of `s` because it is borrowed
--> $DIR/polonius-smoke-test.rs:42:5
--> $DIR/polonius-smoke-test.rs:46:5
|
LL | let s = &mut 1;
| - binding `s` declared here
Expand Down
59 changes: 59 additions & 0 deletions tests/ui/nll/polonius/polonius-smoke-test.polonius.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
error[E0515]: cannot return reference to local variable `x`
--> $DIR/polonius-smoke-test.rs:10:5
|
LL | &x
| ^^ returns a reference to data owned by the current function

error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/polonius-smoke-test.rs:16:13
|
LL | let y = &mut x;
| ------ `x` is borrowed here
LL | let z = x;
| ^ use of borrowed `x`
LL | let w = y;
| - borrow later used here

error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/polonius-smoke-test.rs:22:13
|
LL | pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
| - - let's call the lifetime of this reference `'1`
| |
| binding `x` declared here
LL | let y = &mut *x;
| ------- borrow of `*x` occurs here
LL | let z = x;
| ^ move out of `x` occurs here
LL | y
| - returning this value requires that `*x` is borrowed for `'1`
|
help: consider cloning the value if the performance cost is acceptable
|
LL - let y = &mut *x;
LL + let y = &mut x.clone();
|

error[E0505]: cannot move out of `s` because it is borrowed
--> $DIR/polonius-smoke-test.rs:46:5
|
LL | let s = &mut 1;
| - binding `s` declared here
LL | let r = &mut *s;
| ------- borrow of `*s` occurs here
LL | let tmp = foo(&r);
LL | s;
| ^ move out of `s` occurs here
LL | tmp;
| --- borrow later used here
|
help: consider cloning the value if the performance cost is acceptable
|
LL - let r = &mut *s;
LL + let r = &mut s.clone();
|

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0503, E0505, E0515.
For more information about an error, try `rustc --explain E0503`.
8 changes: 6 additions & 2 deletions tests/ui/nll/polonius/polonius-smoke-test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Check that Polonius borrow check works for simple cases.
//@ compile-flags: -Z polonius
// Check that Polonius works for simple cases.

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

pub fn return_ref_to_local() -> &'static i32 {
let x = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/subset-relations.rs:10:5
--> $DIR/subset-relations.rs:13:5
|
LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
| -- -- lifetime `'b` defined here
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/nll/polonius/subset-relations.polonius.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: lifetime may not live long enough
--> $DIR/subset-relations.rs:13:5
|
LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | y
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
|
= help: consider adding the following bound: `'b: 'a`

error: aborting due to 1 previous error

7 changes: 5 additions & 2 deletions tests/ui/nll/polonius/subset-relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// two free regions outlive each other, without any evidence that this
// relation holds.

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

// returning `y` requires that `'b: 'a`, but it's not known to be true
fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
Expand All @@ -22,7 +25,7 @@ fn implied_bounds_subset<'a, 'b>(x: &'a &'b mut u32) -> &'a u32 {

// `'b: 'a` is declared, and `'a: 'c` is known via implied bounds:
// `'b: 'c` is therefore known to hold transitively
fn transitively_valid_subset<'a, 'b: 'a, 'c>(x: &'c &'a u32, y: &'b u32) -> &'c u32 {
fn transitively_valid_subset<'a, 'b: 'a, 'c>(x: &'c &'a u32, y: &'b u32) -> &'c u32 {
y
}

Expand Down

0 comments on commit 18d417f

Please sign in to comment.