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.
This commit is contained in:
commit
4aa7879b55
170 changed files with 453 additions and 583 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
||||
|
|
|
|||
|
|
@ -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>>`
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ...
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue