Skip to content

Commit a616fa5

Browse files
committed
update NLL get_default test for poloniuses
- it still mentions AST borrowck - it tracks errors that shouldn't exist and are fixed by polonius
1 parent 18d417f commit a616fa5

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

Diff for: tests/ui/nll/get_default.legacy.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
2+
--> $DIR/get_default.rs:35:17
3+
|
4+
LL | fn err(map: &mut Map) -> &String {
5+
| - let's call the lifetime of this reference `'1`
6+
LL | loop {
7+
LL | match map.get() {
8+
| --- immutable borrow occurs here
9+
LL | Some(v) => {
10+
LL | map.set(String::new()); // We always expect an error here.
11+
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
12+
LL |
13+
LL | return v;
14+
| - returning this value requires that `*map` is borrowed for `'1`
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0502`.

Diff for: tests/ui/nll/get_default.stderr renamed to tests/ui/nll/get_default.nll.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
2-
--> $DIR/get_default.rs:21:17
2+
--> $DIR/get_default.rs:24:17
33
|
44
LL | fn ok(map: &mut Map) -> &String {
55
| - let's call the lifetime of this reference `'1`
@@ -14,22 +14,22 @@ LL | map.set(String::new()); // Ideally, this would not error.
1414
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
1515

1616
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
17-
--> $DIR/get_default.rs:32:17
17+
--> $DIR/get_default.rs:35:17
1818
|
1919
LL | fn err(map: &mut Map) -> &String {
2020
| - let's call the lifetime of this reference `'1`
2121
LL | loop {
2222
LL | match map.get() {
2323
| --- immutable borrow occurs here
2424
LL | Some(v) => {
25-
LL | map.set(String::new()); // Both AST and MIR error here
25+
LL | map.set(String::new()); // We always expect an error here.
2626
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
2727
LL |
2828
LL | return v;
2929
| - returning this value requires that `*map` is borrowed for `'1`
3030

3131
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
32-
--> $DIR/get_default.rs:37:17
32+
--> $DIR/get_default.rs:40:17
3333
|
3434
LL | fn err(map: &mut Map) -> &String {
3535
| - let's call the lifetime of this reference `'1`
@@ -40,7 +40,7 @@ LL | match map.get() {
4040
LL | return v;
4141
| - returning this value requires that `*map` is borrowed for `'1`
4242
...
43-
LL | map.set(String::new()); // Ideally, just AST would error here
43+
LL | map.set(String::new()); // Ideally, this would not error.
4444
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
4545

4646
error: aborting due to 3 previous errors

Diff for: tests/ui/nll/get_default.polonius.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
2+
--> $DIR/get_default.rs:35:17
3+
|
4+
LL | fn err(map: &mut Map) -> &String {
5+
| - let's call the lifetime of this reference `'1`
6+
LL | loop {
7+
LL | match map.get() {
8+
| --- immutable borrow occurs here
9+
LL | Some(v) => {
10+
LL | map.set(String::new()); // We always expect an error here.
11+
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
12+
LL |
13+
LL | return v;
14+
| - returning this value requires that `*map` is borrowed for `'1`
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0502`.

Diff for: tests/ui/nll/get_default.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Basic test for free regions in the NLL code. This test ought to
2-
// report an error due to a reborrowing constraint. Right now, we get
3-
// a variety of errors from the older, AST-based machinery (notably
4-
// borrowck), and then we get the NLL error at the end.
2+
// report an error due to a reborrowing constraint.
3+
4+
//@ ignore-compare-mode-polonius (explicit revisions)
5+
//@ revisions: nll polonius legacy
6+
//@ [polonius] compile-flags: -Z polonius=next
7+
//@ [legacy] compile-flags: -Z polonius=legacy
58

69
struct Map {
710
}
@@ -19,7 +22,7 @@ fn ok(map: &mut Map) -> &String {
1922
}
2023
None => {
2124
map.set(String::new()); // Ideally, this would not error.
22-
//~^ ERROR borrowed as immutable
25+
//[nll]~^ ERROR borrowed as immutable
2326
}
2427
}
2528
}
@@ -29,13 +32,13 @@ fn err(map: &mut Map) -> &String {
2932
loop {
3033
match map.get() {
3134
Some(v) => {
32-
map.set(String::new()); // Both AST and MIR error here
35+
map.set(String::new()); // We always expect an error here.
3336
//~^ ERROR borrowed as immutable
3437
return v;
3538
}
3639
None => {
37-
map.set(String::new()); // Ideally, just AST would error here
38-
//~^ ERROR borrowed as immutable
40+
map.set(String::new()); // Ideally, this would not error.
41+
//[nll]~^ ERROR borrowed as immutable
3942
}
4043
}
4144
}

0 commit comments

Comments
 (0)