Skip to content

Commit

Permalink
update NLL get_default test for poloniuses
Browse files Browse the repository at this point in the history
- it still mentions AST borrowck
- it tracks errors that shouldn't exist and are fixed by polonius
  • Loading branch information
lqd committed Jan 31, 2025
1 parent 9259823 commit c19a34e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
18 changes: 18 additions & 0 deletions tests/ui/nll/get_default.legacy.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
--> $DIR/get_default.rs:35:17
|
LL | fn err(map: &mut Map) -> &String {
| - let's call the lifetime of this reference `'1`
LL | loop {
LL | match map.get() {
| --- immutable borrow occurs here
LL | Some(v) => {
LL | map.set(String::new()); // We always expect an error here.
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL |
LL | return v;
| - returning this value requires that `*map` is borrowed for `'1`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0502`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
--> $DIR/get_default.rs:21:17
--> $DIR/get_default.rs:24:17
|
LL | fn ok(map: &mut Map) -> &String {
| - let's call the lifetime of this reference `'1`
Expand All @@ -14,22 +14,22 @@ LL | map.set(String::new()); // Ideally, this would not error.
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here

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

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

error: aborting due to 3 previous errors
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/nll/get_default.polonius.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable
--> $DIR/get_default.rs:35:17
|
LL | fn err(map: &mut Map) -> &String {
| - let's call the lifetime of this reference `'1`
LL | loop {
LL | match map.get() {
| --- immutable borrow occurs here
LL | Some(v) => {
LL | map.set(String::new()); // We always expect an error here.
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL |
LL | return v;
| - returning this value requires that `*map` is borrowed for `'1`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0502`.
17 changes: 10 additions & 7 deletions tests/ui/nll/get_default.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Basic test for free regions in the NLL code. This test ought to
// report an error due to a reborrowing constraint. Right now, we get
// a variety of errors from the older, AST-based machinery (notably
// borrowck), and then we get the NLL error at the end.
// report an error due to a reborrowing constraint.

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

struct Map {
}
Expand All @@ -19,7 +22,7 @@ fn ok(map: &mut Map) -> &String {
}
None => {
map.set(String::new()); // Ideally, this would not error.
//~^ ERROR borrowed as immutable
//[nll]~^ ERROR borrowed as immutable
}
}
}
Expand All @@ -29,13 +32,13 @@ fn err(map: &mut Map) -> &String {
loop {
match map.get() {
Some(v) => {
map.set(String::new()); // Both AST and MIR error here
map.set(String::new()); // We always expect an error here.
//~^ ERROR borrowed as immutable
return v;
}
None => {
map.set(String::new()); // Ideally, just AST would error here
//~^ ERROR borrowed as immutable
map.set(String::new()); // Ideally, this would not error.
//[nll]~^ ERROR borrowed as immutable
}
}
}
Expand Down

0 comments on commit c19a34e

Please sign in to comment.