about summary refs log tree commit diff
path: root/src/test/ui/span
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-09-16 15:01:22 -0500
committerAaron Hill <aa1ronham@gmail.com>2021-09-25 10:00:41 -0500
commit4d66986e090abed11c1aae9602f23385f94154fa (patch)
tree54c358a978a7d94139a2091caa71c325edfc209b /src/test/ui/span
parent73422130ee96c09e7214c876a3600ac1f32aa8c8 (diff)
downloadrust-4d66986e090abed11c1aae9602f23385f94154fa.tar.gz
rust-4d66986e090abed11c1aae9602f23385f94154fa.zip
Use larger span for adjustments on method calls
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

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/span')
-rw-r--r--src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr8
-rw-r--r--src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr2
-rw-r--r--src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr2
-rw-r--r--src/test/ui/span/borrowck-fn-in-const-b.stderr2
-rw-r--r--src/test/ui/span/borrowck-let-suggestion-suffixes.stderr2
-rw-r--r--src/test/ui/span/borrowck-object-mutability.stderr4
-rw-r--r--src/test/ui/span/destructor-restrictions.stderr2
-rw-r--r--src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr4
-rw-r--r--src/test/ui/span/issue-36537.stderr2
-rw-r--r--src/test/ui/span/issue-40157.stderr2
-rw-r--r--src/test/ui/span/mut-arg-hint.stderr6
-rw-r--r--src/test/ui/span/mut-ptr-cant-outlive-ref.stderr2
-rw-r--r--src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr2
-rw-r--r--src/test/ui/span/regions-escape-loop-via-vec.stderr11
-rw-r--r--src/test/ui/span/send-is-not-static-std-sync.stderr10
-rw-r--r--src/test/ui/span/slice-borrow.stderr2
16 files changed, 32 insertions, 31 deletions
diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr
index 8fceef64c8c..e4ec9f87576 100644
--- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr
+++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr
@@ -56,7 +56,7 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
 LL | fn deref_mut_method1(x: Own<Point>) {
    |                      - help: consider changing this to be mutable: `mut x`
 LL |     x.set(0, 0);
-   |     ^ cannot borrow as mutable
+   |     ^^^^^^^^^^^ cannot borrow as mutable
 
 error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
   --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:121:5
@@ -64,7 +64,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
 LL | fn deref_extend_mut_method1(x: &Own<Point>) -> &mut isize {
    |                                ----------- help: consider changing this to be a mutable reference: `&mut Own<Point>`
 LL |     x.y_mut()
-   |     ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |     ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:129:6
@@ -72,7 +72,7 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
 LL | fn assign_method1<'a>(x: Own<Point>) {
    |                       - help: consider changing this to be mutable: `mut x`
 LL |     *x.y_mut() = 3;
-   |      ^ cannot borrow as mutable
+   |      ^^^^^^^^^ cannot borrow as mutable
 
 error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
   --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:133:6
@@ -80,7 +80,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
 LL | fn assign_method2<'a>(x: &'a Own<Point>) {
    |                          -------------- help: consider changing this to be a mutable reference: `&'a mut Own<Point>`
 LL |     *x.y_mut() = 3;
-   |      ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |      ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error: aborting due to 10 previous errors
 
diff --git a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
index 0f630abd148..b4693b7242a 100644
--- a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
+++ b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
@@ -24,7 +24,7 @@ error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference
 LL | fn test4(f: &Test) {
    |             ----- help: consider changing this to be a mutable reference: `&mut Test<'_>`
 LL |     f.f.call_mut(())
-   |     ^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |     ^^^^^^^^^^^^^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error[E0507]: cannot move out of `f`, a captured variable in an `FnMut` closure
   --> $DIR/borrowck-call-is-borrow-issue-12224.rs:57:13
diff --git a/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr b/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr
index 6b5e0779e5f..1864f5de108 100644
--- a/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr
+++ b/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr
@@ -5,7 +5,7 @@ LL | fn b(x: &Foo) {
    |         ---- help: consider changing this to be a mutable reference: `&mut Foo`
 LL |     x.f();
 LL |     x.h();
-   |     ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |     ^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/borrowck-fn-in-const-b.stderr b/src/test/ui/span/borrowck-fn-in-const-b.stderr
index 8949a10481a..1f5d8bd32bb 100644
--- a/src/test/ui/span/borrowck-fn-in-const-b.stderr
+++ b/src/test/ui/span/borrowck-fn-in-const-b.stderr
@@ -4,7 +4,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
 LL |     fn broken(x: &Vec<String>) {
    |                  ------------ help: consider changing this to be a mutable reference: `&mut Vec<String>`
 LL |         x.push(format!("this is broken"));
-   |         ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
index 7ba909d208a..7c5caba6eae 100644
--- a/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
+++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr
@@ -32,7 +32,7 @@ LL |         v4.push(&id('y'));
    |                  creates a temporary which is freed while still in use
 ...
 LL |         v4.use_ref();
-   |         -- borrow later used here
+   |         ------------ borrow later used here
    |
    = note: consider using a `let` binding to create a longer lived value
 
diff --git a/src/test/ui/span/borrowck-object-mutability.stderr b/src/test/ui/span/borrowck-object-mutability.stderr
index fe6d05c588f..cc43f6d0928 100644
--- a/src/test/ui/span/borrowck-object-mutability.stderr
+++ b/src/test/ui/span/borrowck-object-mutability.stderr
@@ -5,7 +5,7 @@ LL | fn borrowed_receiver(x: &dyn Foo) {
    |                         -------- help: consider changing this to be a mutable reference: `&mut dyn Foo`
 LL |     x.borrowed();
 LL |     x.borrowed_mut();
-   |     ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |     ^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error[E0596]: cannot borrow `*x` as mutable, as `x` is not declared as mutable
   --> $DIR/borrowck-object-mutability.rs:18:5
@@ -14,7 +14,7 @@ LL | fn owned_receiver(x: Box<dyn Foo>) {
    |                   - help: consider changing this to be mutable: `mut x`
 LL |     x.borrowed();
 LL |     x.borrowed_mut();
-   |     ^ cannot borrow as mutable
+   |     ^^^^^^^^^^^^^^^^ cannot borrow as mutable
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/span/destructor-restrictions.stderr b/src/test/ui/span/destructor-restrictions.stderr
index 8f75c388f65..53c9404620f 100644
--- a/src/test/ui/span/destructor-restrictions.stderr
+++ b/src/test/ui/span/destructor-restrictions.stderr
@@ -2,7 +2,7 @@ error[E0597]: `*a` does not live long enough
   --> $DIR/destructor-restrictions.rs:8:10
    |
 LL |         *a.borrow() + 1
-   |          ^---------
+   |          ^^^^^^^^^^
    |          |
    |          borrowed value does not live long enough
    |          a temporary with access to the borrow is created here ...
diff --git a/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr
index 8d4709d660f..3c2022748f0 100644
--- a/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr
+++ b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr
@@ -2,7 +2,7 @@ error[E0597]: `y` does not live long enough
   --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:10:5
    |
 LL |     y.borrow().clone()
-   |     ^---------
+   |     ^^^^^^^^^^
    |     |
    |     borrowed value does not live long enough
    |     a temporary with access to the borrow is created here ...
@@ -23,7 +23,7 @@ error[E0597]: `y` does not live long enough
   --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:17:9
    |
 LL |         y.borrow().clone()
-   |         ^---------
+   |         ^^^^^^^^^^
    |         |
    |         borrowed value does not live long enough
    |         a temporary with access to the borrow is created here ...
diff --git a/src/test/ui/span/issue-36537.stderr b/src/test/ui/span/issue-36537.stderr
index 0939584380a..79a0ebaeb8d 100644
--- a/src/test/ui/span/issue-36537.stderr
+++ b/src/test/ui/span/issue-36537.stderr
@@ -7,7 +7,7 @@ LL |         p = &a;
 LL |     }
    |     - `a` dropped here while still borrowed
 LL |     p.use_ref();
-   |     - borrow later used here
+   |     ----------- borrow later used here
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/issue-40157.stderr b/src/test/ui/span/issue-40157.stderr
index 0b365c3f7b6..57f80214a4f 100644
--- a/src/test/ui/span/issue-40157.stderr
+++ b/src/test/ui/span/issue-40157.stderr
@@ -2,7 +2,7 @@ error[E0597]: `foo` does not live long enough
   --> $DIR/issue-40157.rs:2:53
    |
 LL |     {println!("{:?}", match { let foo = vec![1, 2]; foo.get(1) } { x => x });}
-   |                             ------------------------^^^---------
+   |                             ------------------------^^^^^^^^^^--
    |                             |                       |          |
    |                             |                       |          `foo` dropped here while still borrowed
    |                             |                       borrowed value does not live long enough
diff --git a/src/test/ui/span/mut-arg-hint.stderr b/src/test/ui/span/mut-arg-hint.stderr
index e04e4cbdabb..8a7c504f005 100644
--- a/src/test/ui/span/mut-arg-hint.stderr
+++ b/src/test/ui/span/mut-arg-hint.stderr
@@ -4,7 +4,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
 LL |     fn foo(mut a: &String) {
    |                   ------- help: consider changing this to be a mutable reference: `&mut String`
 LL |         a.push_str("bar");
-   |         ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |         ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
   --> $DIR/mut-arg-hint.rs:8:5
@@ -12,7 +12,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
 LL | pub fn foo<'a>(mut a: &'a String) {
    |                       ---------- help: consider changing this to be a mutable reference: `&'a mut String`
 LL |     a.push_str("foo");
-   |     ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |     ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
   --> $DIR/mut-arg-hint.rs:15:9
@@ -20,7 +20,7 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
 LL |     pub fn foo(mut a: &String) {
    |                       ------- help: consider changing this to be a mutable reference: `&mut String`
 LL |         a.push_str("foo");
-   |         ^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+   |         ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr b/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr
index 21b29464df5..4d976a7bbfa 100644
--- a/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr
+++ b/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr
@@ -7,7 +7,7 @@ LL |     }
    |     - `b` dropped here while still borrowed
 LL |
 LL |     p.use_ref();
-   |     - borrow later used here
+   |     ----------- borrow later used here
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr b/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr
index 8e9cd595154..0b985de609c 100644
--- a/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr
+++ b/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr
@@ -7,7 +7,7 @@ LL |         let c_ref = &c;
 LL |     }
    |     - `c` dropped here while still borrowed
 LL |     f.use_mut();
-   |     - borrow later used here
+   |     ----------- borrow later used here
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/span/regions-escape-loop-via-vec.stderr b/src/test/ui/span/regions-escape-loop-via-vec.stderr
index b47250db723..2b649307739 100644
--- a/src/test/ui/span/regions-escape-loop-via-vec.stderr
+++ b/src/test/ui/span/regions-escape-loop-via-vec.stderr
@@ -7,7 +7,7 @@ LL |     while x < 10 {
    |           ^ use of borrowed `x`
 LL |         let mut z = x;
 LL |         _y.push(&mut z);
-   |         -- borrow later used here
+   |         --------------- borrow later used here
 
 error[E0503]: cannot use `x` because it was mutably borrowed
   --> $DIR/regions-escape-loop-via-vec.rs:6:21
@@ -18,14 +18,15 @@ LL |     while x < 10 {
 LL |         let mut z = x;
    |                     ^ use of borrowed `x`
 LL |         _y.push(&mut z);
-   |         -- borrow later used here
+   |         --------------- borrow later used here
 
 error[E0597]: `z` does not live long enough
   --> $DIR/regions-escape-loop-via-vec.rs:7:17
    |
 LL |         _y.push(&mut z);
-   |         --      ^^^^^^ borrowed value does not live long enough
-   |         |
+   |         --------^^^^^^-
+   |         |       |
+   |         |       borrowed value does not live long enough
    |         borrow later used here
 ...
 LL |     }
@@ -38,7 +39,7 @@ LL |     let mut _y = vec![&mut x];
    |                       ------ borrow of `x` occurs here
 ...
 LL |         _y.push(&mut z);
-   |         -- borrow later used here
+   |         --------------- borrow later used here
 LL |
 LL |         x += 1;
    |         ^^^^^^ use of borrowed `x`
diff --git a/src/test/ui/span/send-is-not-static-std-sync.stderr b/src/test/ui/span/send-is-not-static-std-sync.stderr
index 81de8c29906..5d493a3e4ee 100644
--- a/src/test/ui/span/send-is-not-static-std-sync.stderr
+++ b/src/test/ui/span/send-is-not-static-std-sync.stderr
@@ -7,7 +7,7 @@ LL |     drop(y);
    |          ^ move out of `y` occurs here
 ...
 LL |         *lock.lock().unwrap() = &z;
-   |          ---- borrow later used here
+   |          ----------- borrow later used here
 
 error[E0597]: `z` does not live long enough
   --> $DIR/send-is-not-static-std-sync.rs:16:33
@@ -18,7 +18,7 @@ LL |     }
    |     - `z` dropped here while still borrowed
 LL |
 LL |     lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z` => needs explicit use)
-   |     ---- borrow later used here
+   |     -------------- borrow later used here
 
 error[E0505]: cannot move out of `y` because it is borrowed
   --> $DIR/send-is-not-static-std-sync.rs:27:10
@@ -29,7 +29,7 @@ LL |     drop(y);
    |          ^ move out of `y` occurs here
 ...
 LL |         *lock.write().unwrap() = &z;
-   |          ---- borrow later used here
+   |          ------------ borrow later used here
 
 error[E0597]: `z` does not live long enough
   --> $DIR/send-is-not-static-std-sync.rs:30:34
@@ -40,7 +40,7 @@ LL |     }
    |     - `z` dropped here while still borrowed
 LL |
 LL |     lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z` => needs explicit use)
-   |     ---- borrow later used here
+   |     -------------- borrow later used here
 
 error[E0505]: cannot move out of `y` because it is borrowed
   --> $DIR/send-is-not-static-std-sync.rs:43:10
@@ -51,7 +51,7 @@ LL |     drop(y);
    |          ^ move out of `y` occurs here
 ...
 LL |         tx.send(&z).unwrap();
-   |         -- borrow later used here
+   |         ----------- borrow later used here
 
 error[E0597]: `z` does not live long enough
   --> $DIR/send-is-not-static-std-sync.rs:46:17
diff --git a/src/test/ui/span/slice-borrow.stderr b/src/test/ui/span/slice-borrow.stderr
index 62a4a6009d4..27df25be3fa 100644
--- a/src/test/ui/span/slice-borrow.stderr
+++ b/src/test/ui/span/slice-borrow.stderr
@@ -7,7 +7,7 @@ LL |         let x: &[isize] = &vec![1, 2, 3, 4, 5];
 LL |     }
    |     - temporary value is freed at the end of this statement
 LL |     y.use_ref();
-   |     - borrow later used here
+   |     ----------- borrow later used here
    |
    = note: consider using a `let` binding to create a longer lived value
    = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)