about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2025-01-31 09:10:15 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2025-01-31 11:04:50 +0000
commita616fa565745e2b8e8e245826f9452eb4c6d1191 (patch)
tree9d0738f211a3059a28e76cc0af7979bd2ec276c9
parent18d417fdcfc372dc81244169be19c581499091ec (diff)
downloadrust-a616fa565745e2b8e8e245826f9452eb4c6d1191.tar.gz
rust-a616fa565745e2b8e8e245826f9452eb4c6d1191.zip
update NLL `get_default` test for poloniuses
- it still mentions AST borrowck
- it tracks errors that shouldn't exist and are fixed by polonius
-rw-r--r--tests/ui/nll/get_default.legacy.stderr18
-rw-r--r--tests/ui/nll/get_default.nll.stderr (renamed from tests/ui/nll/get_default.stderr)10
-rw-r--r--tests/ui/nll/get_default.polonius.stderr18
-rw-r--r--tests/ui/nll/get_default.rs17
4 files changed, 51 insertions, 12 deletions
diff --git a/tests/ui/nll/get_default.legacy.stderr b/tests/ui/nll/get_default.legacy.stderr
new file mode 100644
index 00000000000..699250312dc
--- /dev/null
+++ b/tests/ui/nll/get_default.legacy.stderr
@@ -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`.
diff --git a/tests/ui/nll/get_default.stderr b/tests/ui/nll/get_default.nll.stderr
index af79771e7e1..9b5976ca717 100644
--- a/tests/ui/nll/get_default.stderr
+++ b/tests/ui/nll/get_default.nll.stderr
@@ -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`
@@ -14,7 +14,7 @@ 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`
@@ -22,14 +22,14 @@ 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`
@@ -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
diff --git a/tests/ui/nll/get_default.polonius.stderr b/tests/ui/nll/get_default.polonius.stderr
new file mode 100644
index 00000000000..699250312dc
--- /dev/null
+++ b/tests/ui/nll/get_default.polonius.stderr
@@ -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`.
diff --git a/tests/ui/nll/get_default.rs b/tests/ui/nll/get_default.rs
index ffac8a33da1..c3c09e9c2c5 100644
--- a/tests/ui/nll/get_default.rs
+++ b/tests/ui/nll/get_default.rs
@@ -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 {
 }
@@ -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
             }
         }
     }
@@ -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
             }
         }
     }