Clearer later use messages for calls

Give a special message when the later use is from a call. Use the span
of the callee instead of the whole expression. For conflicting borrow
messages say that the later use is of the first borrow.
This commit is contained in:
Matthew Jasper 2018-09-29 11:47:47 +01:00
parent cc09cb5e5a
commit bc4f9b848d
102 changed files with 608 additions and 637 deletions

View file

@ -8,10 +8,9 @@ LL | ptr = box Foo { x: ptr.x + 1 };
| --- first borrow occurs due to use of `ptr` in closure
...
LL | test(&*ptr);
| -----^^^^^-
| | |
| | immutable borrow occurs here
| borrow later used here
| ---- ^^^^^ immutable borrow occurs here
| |
| mutable borrow later used by call
error: aborting due to previous error

View file

@ -2,11 +2,10 @@ error[E0499]: cannot borrow `*s` as mutable more than once at a time
--> $DIR/issue-18566.rs:33:19
|
LL | MyPtr(s).poke(s);
| --------------^-
| | | |
| | | second mutable borrow occurs here
| | first mutable borrow occurs here
| borrow later used here
| - ---- ^ second mutable borrow occurs here
| | |
| | first borrow later used by call
| first mutable borrow occurs here
error: aborting due to previous error

View file

@ -11,7 +11,7 @@ LL | c.push(Box::new(|| y = 0));
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `y` as mutable more than once at a time
LL | }
| - borrow later used here, when `c` is dropped
| - first borrow later used here, when `c` is dropped
error[E0499]: cannot borrow `y` as mutable more than once at a time
--> $DIR/issue-18783.rs:26:29
@ -26,7 +26,7 @@ LL | Push::push(&c, Box::new(|| y = 0));
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `y` as mutable more than once at a time
LL | }
| - borrow later used here, when `c` is dropped
| - first borrow later used here, when `c` is dropped
error: aborting due to 2 previous errors

View file

@ -7,10 +7,9 @@ LL | $this.width.unwrap()
LL | let r = &mut *self;
| ---------- borrow of `*self` occurs here
LL | r.get_size(width!(self))
| ------------------------
| | |
| | in this macro invocation
| borrow later used here
| -------- ------------ in this macro invocation
| |
| borrow later used by call
error: aborting due to previous error

View file

@ -6,7 +6,7 @@ LL | let _a = &collection;
LL | collection.swap(1, 2); //~ ERROR also borrowed as immutable
| ^^^^^^^^^^ mutable borrow occurs here
LL | _a.use_ref();
| -- borrow later used here
| -- immutable borrow later used here
error: aborting due to previous error

View file

@ -8,7 +8,7 @@ LL | let nref = &u.z.c;
| ^^^^^^ immutable borrow occurs here
LL | //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502]
LL | println!("{} {}", mref, nref)
| ---- borrow later used here
| ---- mutable borrow later used here
error: aborting due to previous error