about summary refs log tree commit diff
path: root/src/test/ui/borrowck
diff options
context:
space:
mode:
authorWesley Wiser <wesleywiser@microsoft.com>2021-07-23 18:55:36 -0400
committerWesley Wiser <wesleywiser@microsoft.com>2021-08-25 15:17:22 -0400
commit0a42dfc2fa2b373aedf7a169da3f0ec0e996fc9f (patch)
treeb4676c6679915087e8824b3b439070dc907e3ac1 /src/test/ui/borrowck
parenta992a11913b39a258158646bb1e03528c5aa5060 (diff)
Fix debugger stepping behavior around `match` expressions
Previously, we would set up the source lines for `match` expressions so
that the code generated to perform the test of the scrutinee was matched
to the line of the arm that required the test and then jump from the arm
block to the "next" block was matched to all of the lines in the `match`
expression.

While that makes sense, it has the side effect of causing strange
stepping behavior in debuggers.

I've changed the source information so that all of the generated tests
are sourced to `match {scrutinee}` and the jumps are sourced to the last
line of the block they are inside. This resolves the weird stepping
behavior in all debuggers and resolves some instances of "ambiguous
symbol" errors in WinDbg preventing the user from setting breakpoints at
`match` expressions.
Diffstat (limited to 'src/test/ui/borrowck')
-rw-r--r--src/test/ui/borrowck/borrowck-anon-fields-variant.rs7
-rw-r--r--src/test/ui/borrowck/borrowck-anon-fields-variant.stderr14
-rw-r--r--src/test/ui/borrowck/borrowck-describe-lvalue.rs2
-rw-r--r--src/test/ui/borrowck/borrowck-describe-lvalue.stderr9
-rw-r--r--src/test/ui/borrowck/borrowck-match-already-borrowed.rs4
-rw-r--r--src/test/ui/borrowck/borrowck-match-already-borrowed.stderr5
-rw-r--r--src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs2
-rw-r--r--src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr7
8 files changed, 24 insertions, 26 deletions
diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs
index cecc278e193..6e63de9136c 100644
--- a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs
+++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs
@@ -14,8 +14,8 @@ fn distinct_variant() {
     // also used for the discriminant of `Foo`, which it would be if `a` was a
     // reference.
     let b = match y {
-      Foo::Y(_, ref mut b) => b,
       //~^ ERROR cannot use `y`
+      Foo::Y(_, ref mut b) => b,
       Foo::X => panic!()
     };
 
@@ -32,8 +32,9 @@ fn same_variant() {
     };
 
     let b = match y {
-      Foo::Y(ref mut b, _) => b, //~ ERROR cannot use `y`
-      //~| ERROR cannot borrow `y.0` as mutable
+      //~^ ERROR cannot use `y`
+      Foo::Y(ref mut b, _) => b,
+      //~^ ERROR cannot borrow `y.0` as mutable
       Foo::X => panic!()
     };
 
diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr
index 2caeed1bd44..98f6f00a7d4 100644
--- a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr
+++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr
@@ -1,29 +1,29 @@
 error[E0503]: cannot use `y` because it was mutably borrowed
-  --> $DIR/borrowck-anon-fields-variant.rs:17:7
+  --> $DIR/borrowck-anon-fields-variant.rs:16:19
    |
 LL |       Foo::Y(ref mut a, _) => a,
    |              --------- borrow of `y.0` occurs here
 ...
-LL |       Foo::Y(_, ref mut b) => b,
-   |       ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
+LL |     let b = match y {
+   |                   ^ use of borrowed `y.0`
 ...
 LL |     *a += 1;
    |     ------- borrow later used here
 
 error[E0503]: cannot use `y` because it was mutably borrowed
-  --> $DIR/borrowck-anon-fields-variant.rs:35:7
+  --> $DIR/borrowck-anon-fields-variant.rs:34:19
    |
 LL |       Foo::Y(ref mut a, _) => a,
    |              --------- borrow of `y.0` occurs here
 ...
-LL |       Foo::Y(ref mut b, _) => b,
-   |       ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
+LL |     let b = match y {
+   |                   ^ use of borrowed `y.0`
 ...
 LL |     *a += 1;
    |     ------- borrow later used here
 
 error[E0499]: cannot borrow `y.0` as mutable more than once at a time
-  --> $DIR/borrowck-anon-fields-variant.rs:35:14
+  --> $DIR/borrowck-anon-fields-variant.rs:36:14
    |
 LL |       Foo::Y(ref mut a, _) => a,
    |              --------- first mutable borrow occurs here
diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.rs b/src/test/ui/borrowck/borrowck-describe-lvalue.rs
index 0e6c0635adb..cdcff69d6e5 100644
--- a/src/test/ui/borrowck/borrowck-describe-lvalue.rs
+++ b/src/test/ui/borrowck/borrowck-describe-lvalue.rs
@@ -164,9 +164,9 @@ fn main() {
         let mut e = E::A(3);
         let x = &mut e;
         match e {
+            //~^ ERROR cannot use `e` because it was mutably borrowed
             E::A(ref ax) =>
                 //~^ ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable
-                //~| ERROR cannot use `e` because it was mutably borrowed
                 println!("e.ax: {:?}", ax),
             E::B { x: ref bx } =>
                 //~^ ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable
diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr
index 0f2ebbcbf3c..4b9c5a2a98f 100644
--- a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr
+++ b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr
@@ -238,23 +238,22 @@ LL |         drop(x);
    |              - borrow later used here
 
 error[E0503]: cannot use `e` because it was mutably borrowed
-  --> $DIR/borrowck-describe-lvalue.rs:167:13
+  --> $DIR/borrowck-describe-lvalue.rs:166:15
    |
 LL |         let x = &mut e;
    |                 ------ borrow of `e` occurs here
 LL |         match e {
-LL |             E::A(ref ax) =>
-   |             ^^^^^^^^^^^^ use of borrowed `e`
+   |               ^ use of borrowed `e`
 ...
 LL |         drop(x);
    |              - borrow later used here
 
 error[E0502]: cannot borrow `e.0` as immutable because it is also borrowed as mutable
-  --> $DIR/borrowck-describe-lvalue.rs:167:18
+  --> $DIR/borrowck-describe-lvalue.rs:168:18
    |
 LL |         let x = &mut e;
    |                 ------ mutable borrow occurs here
-LL |         match e {
+...
 LL |             E::A(ref ax) =>
    |                  ^^^^^^ immutable borrow occurs here
 ...
diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs
index c766e6c1080..a925cbbf57b 100644
--- a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs
+++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs
@@ -6,8 +6,8 @@ enum Foo {
 fn match_enum() {
     let mut foo = Foo::B;
     let p = &mut foo;
-    let _ = match foo {
-        Foo::B => 1, //~ ERROR [E0503]
+    let _ = match foo { //~ ERROR [E0503]
+        Foo::B => 1,
         _ => 2,
         Foo::A(x) => x //~ ERROR [E0503]
     };
diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr
index 286a925bb7f..39047be9de6 100644
--- a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr
+++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr
@@ -1,11 +1,10 @@
 error[E0503]: cannot use `foo` because it was mutably borrowed
-  --> $DIR/borrowck-match-already-borrowed.rs:10:9
+  --> $DIR/borrowck-match-already-borrowed.rs:9:19
    |
 LL |     let p = &mut foo;
    |             -------- borrow of `foo` occurs here
 LL |     let _ = match foo {
-LL |         Foo::B => 1,
-   |         ^^^^^^ use of borrowed `foo`
+   |                   ^^^ use of borrowed `foo`
 ...
 LL |     drop(p);
    |          - borrow later used here
diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs
index 71f1f15654b..4109c10e2e4 100644
--- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs
+++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs
@@ -10,11 +10,11 @@
 fn main() {
     let b = &mut true;
     match b {
+        //~^ ERROR use of moved value: `b` [E0382]
         &mut false => {},
         _ if { (|| { let bar = b; *bar = false; })();
                      false } => { },
         &mut true => { println!("You might think we should get here"); },
-        //~^ ERROR use of moved value: `b` [E0382]
         _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
     }
 }
diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr
index 51f9b464d76..9be1a927999 100644
--- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr
+++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr
@@ -1,16 +1,15 @@
 error[E0382]: use of moved value: `b`
-  --> $DIR/issue-27282-move-match-input-into-guard.rs:16:14
+  --> $DIR/issue-27282-move-match-input-into-guard.rs:12:5
    |
 LL |     let b = &mut true;
    |         - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait
+LL |     match b {
+   |     ^^^^^^^ value used here after move
 ...
 LL |         _ if { (|| { let bar = b; *bar = false; })();
    |                 --             - variable moved due to use in closure
    |                 |
    |                 value moved into closure here
-LL |                      false } => { },
-LL |         &mut true => { println!("You might think we should get here"); },
-   |              ^^^^ value used here after move
 
 error: aborting due to previous error