about summary refs log tree commit diff
path: root/src/test/ui/issues
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-30 01:40:30 +0000
committerbors <bors@rust-lang.org>2021-09-30 01:40:30 +0000
commit4aa7879b559ccf7f82bcce2a8e532ea307697ea9 (patch)
tree393753bcad9b7b9d238c34eed23e40e8e6d54581 /src/test/ui/issues
parent24a789b666f2c36d443cde48b5baef04e5b3c76d (diff)
parent4d66986e090abed11c1aae9602f23385f94154fa (diff)
Auto merge of #89110 - Aaron1011:adjustment-span, r=estebank
Use larger span for adjustment THIR expressions

Currently, we use a relatively 'small' span for THIR
expressions generated by an 'adjustment' (e.g. an autoderef,
autoborrow, unsizing). As a result, if a borrow generated
by an adustment ends up causing a borrowcheck error, for example:

```rust
let mut my_var = String::new();
let my_ref = &my_var
my_var.push('a');
my_ref;
```

then the span for the mutable borrow may end up referring
to only the base expression (e.g. `my_var`), rather than
the method call which triggered the mutable borrow
(e.g. `my_var.push('a')`)

Due to a quirk of the MIR borrowck implementation,
this doesn't always get exposed in migration mode,
but it does in many cases.

This commit makes THIR building consistently use 'larger'
spans for adjustment expressions. These spans are recoded
when we first create the adjustment during typecheck. For
example, an autoref adjustment triggered by a method call
will record the span of the entire method call.

The intent of this change it make it clearer to users
when it's the specific way in which a variable is
used (for example, in a method call) that produdes
a borrowcheck error. For example, an error message
claiming that a 'mutable borrow occurs here' might
be confusing if it just points at a usage of a variable
(e.g. `my_var`), when no `&mut` is in sight. Pointing
at the entire expression should help to emphasize
that the method call itself is responsible for
the mutable borrow.

In several cases, this makes the `#![feature(nll)]` diagnostic
output match up exactly with the default (migration mode) output.
As a result, several `.nll.stderr` files end up getting removed
entirely.
Diffstat (limited to 'src/test/ui/issues')
-rw-r--r--src/test/ui/issues/issue-13497-2.stderr15
-rw-r--r--src/test/ui/issues/issue-19163.stderr6
-rw-r--r--src/test/ui/issues/issue-21600.stderr2
-rw-r--r--src/test/ui/issues/issue-41726.stderr2
-rw-r--r--src/test/ui/issues/issue-42106.stderr4
-rw-r--r--src/test/ui/issues/issue-44405.stderr2
-rw-r--r--src/test/ui/issues/issue-47646.stderr2
-rw-r--r--src/test/ui/issues/issue-52126-assign-op-invariance.stderr2
-rw-r--r--src/test/ui/issues/issue-61108.stderr2
-rw-r--r--src/test/ui/issues/issue-81584.stderr2
10 files changed, 21 insertions, 18 deletions
diff --git a/src/test/ui/issues/issue-13497-2.stderr b/src/test/ui/issues/issue-13497-2.stderr
index 8ad921027e2..6f72b79f2a5 100644
--- a/src/test/ui/issues/issue-13497-2.stderr
+++ b/src/test/ui/issues/issue-13497-2.stderr
@@ -1,13 +1,14 @@
 error[E0515]: cannot return value referencing local variable `rawLines`
   --> $DIR/issue-13497-2.rs:3:5
    |
-LL |       rawLines
-   |       ^-------
-   |       |
-   |  _____`rawLines` is borrowed here
-   | |
-LL | |         .iter().map(|l| l.trim()).collect()
-   | |___________________________________________^ returns a value referencing data owned by the current function
+LL |        rawLines
+   |   _____^
+   |  |_____|
+   | ||
+LL | ||         .iter().map(|l| l.trim()).collect()
+   | ||_______________-___________________________^ returns a value referencing data owned by the current function
+   | |________________|
+   |                  `rawLines` is borrowed here
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-19163.stderr b/src/test/ui/issues/issue-19163.stderr
index af509aa59d4..def032ba1bb 100644
--- a/src/test/ui/issues/issue-19163.stderr
+++ b/src/test/ui/issues/issue-19163.stderr
@@ -1,8 +1,10 @@
 error[E0596]: cannot borrow data in a `&` reference as mutable
-  --> $DIR/issue-19163.rs:9:14
+  --> $DIR/issue-19163.rs:9:5
    |
 LL |     mywrite!(&v, "Hello world");
-   |              ^^ cannot borrow as mutable
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
+   |
+   = note: this error originates in the macro `mywrite` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-21600.stderr b/src/test/ui/issues/issue-21600.stderr
index 84c7106e890..dab3c3d1797 100644
--- a/src/test/ui/issues/issue-21600.stderr
+++ b/src/test/ui/issues/issue-21600.stderr
@@ -5,7 +5,7 @@ LL | fn call_it<F>(f: F) where F: Fn() { f(); }
    |                  - change this to accept `FnMut` instead of `Fn`
 ...
 LL |         call_it(|| x.gen_mut());
-   |         -------    ^ cannot borrow as mutable
+   |         -------    ^^^^^^^^^^^ cannot borrow as mutable
    |         |
    |         expects `Fn` instead of `FnMut`
 
diff --git a/src/test/ui/issues/issue-41726.stderr b/src/test/ui/issues/issue-41726.stderr
index b00a420bc37..22631e7c2a3 100644
--- a/src/test/ui/issues/issue-41726.stderr
+++ b/src/test/ui/issues/issue-41726.stderr
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow data in an index of `HashMap<String, Vec<String>>` a
   --> $DIR/issue-41726.rs:5:9
    |
 LL |         things[src.as_str()].sort();
-   |         ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
    |
    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<String, Vec<String>>`
 
diff --git a/src/test/ui/issues/issue-42106.stderr b/src/test/ui/issues/issue-42106.stderr
index d5a9d233bc9..73cf8652f6d 100644
--- a/src/test/ui/issues/issue-42106.stderr
+++ b/src/test/ui/issues/issue-42106.stderr
@@ -4,9 +4,9 @@ error[E0502]: cannot borrow `*collection` as mutable because it is also borrowed
 LL |     let _a = &collection;
    |              ----------- immutable borrow occurs here
 LL |     collection.swap(1, 2);
-   |     ^^^^^^^^^^ mutable borrow occurs here
+   |     ^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
 LL |     _a.use_ref();
-   |     -- immutable borrow later used here
+   |     ------------ immutable borrow later used here
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-44405.stderr b/src/test/ui/issues/issue-44405.stderr
index 1fd69f6e777..626cb2999e1 100644
--- a/src/test/ui/issues/issue-44405.stderr
+++ b/src/test/ui/issues/issue-44405.stderr
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow data in an index of `Container` as mutable
   --> $DIR/issue-44405.rs:21:5
    |
 LL |     container[&mut val].test();
-   |     ^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
    |
    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `Container`
 
diff --git a/src/test/ui/issues/issue-47646.stderr b/src/test/ui/issues/issue-47646.stderr
index b46c277d045..eff1de3e017 100644
--- a/src/test/ui/issues/issue-47646.stderr
+++ b/src/test/ui/issues/issue-47646.stderr
@@ -2,7 +2,7 @@ error[E0502]: cannot borrow `heap` as immutable because it is also borrowed as m
   --> $DIR/issue-47646.rs:9:30
    |
 LL |     let borrow = heap.peek_mut();
-   |                  ---- mutable borrow occurs here
+   |                  --------------- mutable borrow occurs here
 LL | 
 LL |     match (borrow, ()) {
    |           ------------ a temporary with access to the mutable borrow is created here ...
diff --git a/src/test/ui/issues/issue-52126-assign-op-invariance.stderr b/src/test/ui/issues/issue-52126-assign-op-invariance.stderr
index d231f621e59..d4506757762 100644
--- a/src/test/ui/issues/issue-52126-assign-op-invariance.stderr
+++ b/src/test/ui/issues/issue-52126-assign-op-invariance.stderr
@@ -2,7 +2,7 @@ error[E0597]: `line` does not live long enough
   --> $DIR/issue-52126-assign-op-invariance.rs:34:28
    |
 LL |         let v: Vec<&str> = line.split_whitespace().collect();
-   |                            ^^^^ borrowed value does not live long enough
+   |                            ^^^^^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
 ...
 LL |         acc += cnt2;
    |         --- borrow later used here
diff --git a/src/test/ui/issues/issue-61108.stderr b/src/test/ui/issues/issue-61108.stderr
index fb242f738c8..6f345f56d1a 100644
--- a/src/test/ui/issues/issue-61108.stderr
+++ b/src/test/ui/issues/issue-61108.stderr
@@ -10,7 +10,7 @@ LL |     for l in bad_letters {
    |              help: consider borrowing to avoid moving into the for loop: `&bad_letters`
 ...
 LL |     bad_letters.push('s');
-   |     ^^^^^^^^^^^ value borrowed here after move
+   |     ^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move
    |
 note: this function takes ownership of the receiver `self`, which moves `bad_letters`
   --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
diff --git a/src/test/ui/issues/issue-81584.stderr b/src/test/ui/issues/issue-81584.stderr
index d57f1b778df..54973cfa34e 100644
--- a/src/test/ui/issues/issue-81584.stderr
+++ b/src/test/ui/issues/issue-81584.stderr
@@ -2,7 +2,7 @@ error[E0515]: cannot return value referencing function parameter `y`
   --> $DIR/issue-81584.rs:5:22
    |
 LL |             .map(|y| y.iter().map(|x| x + 1))
-   |                      -^^^^^^^^^^^^^^^^^^^^^^
+   |                      --------^^^^^^^^^^^^^^^
    |                      |
    |                      returns a value referencing data owned by the current function
    |                      `y` is borrowed here