Auto merge of #52948 - davidtwco:issue-52633-later-loop-iteration, r=pnkfelix
NLL: Better Diagnostic When "Later" means "A Future Loop Iteration" Part of #52663. r? @pnkfelix
This commit is contained in:
commit
e415b5ecc0
6 changed files with 92 additions and 13 deletions
|
|
@ -17,7 +17,7 @@ LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow
|
|||
| ^^^^^^^^^^^^^^^ second mutable borrow occurs here
|
||||
LL | inner_second.use_mut();
|
||||
LL | inner_first.use_mut();
|
||||
| ----------- borrow later used here
|
||||
| ----------- borrow used here in later iteration of loop
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | let v: Vec<&str> = line.split_whitespace().collect();
|
|||
| ^^^^ borrowed value does not live long enough
|
||||
LL | //~^ ERROR `line` does not live long enough
|
||||
LL | println!("accumulator before add_assign {:?}", acc.map);
|
||||
| ------- borrow later used here
|
||||
| ------- borrow used here in later iteration of loop
|
||||
...
|
||||
LL | }
|
||||
| - `line` dropped here while still borrowed
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | foo.mutate();
|
|||
| ^^^^^^^^^^^^ mutable borrow occurs here
|
||||
LL | //~^ ERROR cannot borrow `foo` as mutable
|
||||
LL | println!("foo={:?}", *string);
|
||||
| ------- borrow later used here
|
||||
| ------- borrow used here in later iteration of loop
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0597]: `x` does not live long enough
|
|||
--> $DIR/regions-escape-loop-via-variable.rs:21:13
|
||||
|
|
||||
LL | let x = 1 + *p;
|
||||
| -- borrow later used here
|
||||
| -- borrow used here in later iteration of loop
|
||||
LL | p = &x;
|
||||
| ^^ borrowed value does not live long enough
|
||||
LL | }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed
|
|||
| ^ use of borrowed `x`
|
||||
LL | let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed
|
||||
LL | _y.push(&mut z);
|
||||
| -- borrow later used here
|
||||
| -- borrow used here in later iteration of loop
|
||||
|
||||
error[E0503]: cannot use `x` because it was mutably borrowed
|
||||
--> $DIR/regions-escape-loop-via-vec.rs:16:21
|
||||
|
|
@ -18,7 +18,7 @@ LL | while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed
|
|||
LL | let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed
|
||||
| ^ use of borrowed `x`
|
||||
LL | _y.push(&mut z);
|
||||
| -- borrow later used here
|
||||
| -- borrow used here in later iteration of loop
|
||||
|
||||
error[E0597]: `z` does not live long enough
|
||||
--> $DIR/regions-escape-loop-via-vec.rs:17:17
|
||||
|
|
@ -26,7 +26,7 @@ error[E0597]: `z` does not live long enough
|
|||
LL | _y.push(&mut z);
|
||||
| -- ^^^^^^ borrowed value does not live long enough
|
||||
| |
|
||||
| borrow later used here
|
||||
| borrow used here in later iteration of loop
|
||||
...
|
||||
LL | }
|
||||
| - `z` dropped here while still borrowed
|
||||
|
|
@ -38,7 +38,7 @@ LL | let mut _y = vec![&mut x];
|
|||
| ------ borrow of `x` occurs here
|
||||
...
|
||||
LL | _y.push(&mut z);
|
||||
| -- borrow later used here
|
||||
| -- borrow used here in later iteration of loop
|
||||
LL | //~^ ERROR `z` does not live long enough
|
||||
LL | x += 1; //~ ERROR cannot assign
|
||||
| ^^^^^^ use of borrowed `x`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue