Skip to content

Commit 18d417f

Browse files
committed
add explicit revisions to polonius tests
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`
1 parent e2d1641 commit 18d417f

9 files changed

+148
-14
lines changed

tests/ui/nll/polonius/assignment-to-differing-field.stderr renamed to tests/ui/nll/polonius/assignment-to-differing-field.legacy.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0499]: cannot borrow `list.0.value` as mutable more than once at a time
2-
--> $DIR/assignment-to-differing-field.rs:20:21
2+
--> $DIR/assignment-to-differing-field.rs:23:21
33
|
44
LL | fn assignment_to_field_projection<'a, T>(
55
| -- lifetime `'a` defined here
@@ -11,7 +11,7 @@ LL | return result;
1111
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
1212

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

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

3737
error[E0499]: cannot borrow `list.0.0.0.0.0.next` as mutable more than once at a time
38-
--> $DIR/assignment-to-differing-field.rs:40:26
38+
--> $DIR/assignment-to-differing-field.rs:43:26
3939
|
4040
LL | fn assignment_through_projection_chain<'a, T>(
4141
| -- lifetime `'a` defined here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error[E0499]: cannot borrow `list.0.value` as mutable more than once at a time
2+
--> $DIR/assignment-to-differing-field.rs:23:21
3+
|
4+
LL | fn assignment_to_field_projection<'a, T>(
5+
| -- lifetime `'a` defined here
6+
...
7+
LL | result.push(&mut (list.0).value);
8+
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
9+
...
10+
LL | return result;
11+
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
12+
13+
error[E0499]: cannot borrow `list.0.next` as mutable more than once at a time
14+
--> $DIR/assignment-to-differing-field.rs:26:26
15+
|
16+
LL | fn assignment_to_field_projection<'a, T>(
17+
| -- lifetime `'a` defined here
18+
...
19+
LL | if let Some(n) = (list.0).next.as_mut() {
20+
| ^^^^^^^^^^^^^ `list.0.next` was mutably borrowed here in the previous iteration of the loop
21+
LL |
22+
LL | list.1 = n;
23+
| ---------- assignment requires that `list.0.next` is borrowed for `'a`
24+
25+
error[E0499]: cannot borrow `list.0.0.0.0.0.value` as mutable more than once at a time
26+
--> $DIR/assignment-to-differing-field.rs:40:21
27+
|
28+
LL | fn assignment_through_projection_chain<'a, T>(
29+
| -- lifetime `'a` defined here
30+
...
31+
LL | result.push(&mut ((((list.0).0).0).0).0.value);
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.value` was mutably borrowed here in the previous iteration of the loop
33+
...
34+
LL | return result;
35+
| ------ returning this value requires that `list.0.0.0.0.0.value` is borrowed for `'a`
36+
37+
error[E0499]: cannot borrow `list.0.0.0.0.0.next` as mutable more than once at a time
38+
--> $DIR/assignment-to-differing-field.rs:43:26
39+
|
40+
LL | fn assignment_through_projection_chain<'a, T>(
41+
| -- lifetime `'a` defined here
42+
...
43+
LL | if let Some(n) = ((((list.0).0).0).0).0.next.as_mut() {
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.next` was mutably borrowed here in the previous iteration of the loop
45+
LL |
46+
LL | *((((list.0).0).0).0).1 = n;
47+
| --------------------------- assignment requires that `list.0.0.0.0.0.next` is borrowed for `'a`
48+
49+
error: aborting due to 4 previous errors
50+
51+
For more information about this error, try `rustc --explain E0499`.

tests/ui/nll/polonius/assignment-to-differing-field.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// that we do not kill too many borrows. Assignments to the `.1`
55
// field projections should leave the borrows on `.0` intact.
66

7-
//@ compile-flags: -Z polonius
7+
//@ ignore-compare-mode-polonius (explicit revisions)
8+
//@ revisions: polonius legacy
9+
//@ [polonius] compile-flags: -Z polonius=next
10+
//@ [legacy] compile-flags: -Z polonius=legacy
811

912
struct List<T> {
1013
value: T,

tests/ui/nll/polonius/polonius-smoke-test.stderr renamed to tests/ui/nll/polonius/polonius-smoke-test.legacy.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0515]: cannot return reference to local variable `x`
2-
--> $DIR/polonius-smoke-test.rs:6:5
2+
--> $DIR/polonius-smoke-test.rs:10:5
33
|
44
LL | &x
55
| ^^ returns a reference to data owned by the current function
66

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

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

3737
error[E0505]: cannot move out of `s` because it is borrowed
38-
--> $DIR/polonius-smoke-test.rs:42:5
38+
--> $DIR/polonius-smoke-test.rs:46:5
3939
|
4040
LL | let s = &mut 1;
4141
| - binding `s` declared here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
error[E0515]: cannot return reference to local variable `x`
2+
--> $DIR/polonius-smoke-test.rs:10:5
3+
|
4+
LL | &x
5+
| ^^ returns a reference to data owned by the current function
6+
7+
error[E0503]: cannot use `x` because it was mutably borrowed
8+
--> $DIR/polonius-smoke-test.rs:16:13
9+
|
10+
LL | let y = &mut x;
11+
| ------ `x` is borrowed here
12+
LL | let z = x;
13+
| ^ use of borrowed `x`
14+
LL | let w = y;
15+
| - borrow later used here
16+
17+
error[E0505]: cannot move out of `x` because it is borrowed
18+
--> $DIR/polonius-smoke-test.rs:22:13
19+
|
20+
LL | pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
21+
| - - let's call the lifetime of this reference `'1`
22+
| |
23+
| binding `x` declared here
24+
LL | let y = &mut *x;
25+
| ------- borrow of `*x` occurs here
26+
LL | let z = x;
27+
| ^ move out of `x` occurs here
28+
LL | y
29+
| - returning this value requires that `*x` is borrowed for `'1`
30+
|
31+
help: consider cloning the value if the performance cost is acceptable
32+
|
33+
LL - let y = &mut *x;
34+
LL + let y = &mut x.clone();
35+
|
36+
37+
error[E0505]: cannot move out of `s` because it is borrowed
38+
--> $DIR/polonius-smoke-test.rs:46:5
39+
|
40+
LL | let s = &mut 1;
41+
| - binding `s` declared here
42+
LL | let r = &mut *s;
43+
| ------- borrow of `*s` occurs here
44+
LL | let tmp = foo(&r);
45+
LL | s;
46+
| ^ move out of `s` occurs here
47+
LL | tmp;
48+
| --- borrow later used here
49+
|
50+
help: consider cloning the value if the performance cost is acceptable
51+
|
52+
LL - let r = &mut *s;
53+
LL + let r = &mut s.clone();
54+
|
55+
56+
error: aborting due to 4 previous errors
57+
58+
Some errors have detailed explanations: E0503, E0505, E0515.
59+
For more information about an error, try `rustc --explain E0503`.

tests/ui/nll/polonius/polonius-smoke-test.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// Check that Polonius borrow check works for simple cases.
2-
//@ compile-flags: -Z polonius
1+
// Check that Polonius works for simple cases.
2+
3+
//@ ignore-compare-mode-polonius (explicit revisions)
4+
//@ revisions: polonius legacy
5+
//@ [polonius] compile-flags: -Z polonius=next
6+
//@ [legacy] compile-flags: -Z polonius=legacy
37

48
pub fn return_ref_to_local() -> &'static i32 {
59
let x = 0;

tests/ui/nll/polonius/subset-relations.stderr renamed to tests/ui/nll/polonius/subset-relations.legacy.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/subset-relations.rs:10:5
2+
--> $DIR/subset-relations.rs:13:5
33
|
44
LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
55
| -- -- lifetime `'b` defined here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/subset-relations.rs:13:5
3+
|
4+
LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
5+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | y
9+
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
10+
|
11+
= help: consider adding the following bound: `'b: 'a`
12+
13+
error: aborting due to 1 previous error
14+

tests/ui/nll/polonius/subset-relations.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// two free regions outlive each other, without any evidence that this
44
// relation holds.
55

6-
//@ compile-flags: -Z polonius
6+
//@ ignore-compare-mode-polonius (explicit revisions)
7+
//@ revisions: polonius legacy
8+
//@ [polonius] compile-flags: -Z polonius=next
9+
//@ [legacy] compile-flags: -Z polonius=legacy
710

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

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

0 commit comments

Comments
 (0)