Skip to content

Commit c34c015

Browse files
committed
Auto merge of #77692 - PankajChaudhary5:issue-76630, r=davidtwco
Added better error message for shared borrow treated as unique for purposes of lifetimes Part of Issue #76630 r? `@jyn514`
2 parents 5b104fc + 50d9b30 commit c34c015

8 files changed

+18
-17
lines changed

compiler/rustc_mir/src/util/borrowck_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
6868
err.span_label(
6969
new_loan_span,
7070
format!(
71-
"mutable borrow starts here in previous \
72-
iteration of loop{}",
73-
opt_via
71+
"{}{} was mutably borrowed here in the previous iteration of the loop{}",
72+
desc,
73+
via(opt_via),
74+
opt_via,
7475
),
7576
);
7677
if let Some(old_load_end_span) = old_load_end_span {

src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
2323
--> $DIR/borrowck-mut-borrow-linear-errors.rs:12:30
2424
|
2525
LL | _ => { addr.push(&mut x); }
26-
| ^^^^^^ mutable borrow starts here in previous iteration of loop
26+
| ^^^^^^ `x` was mutably borrowed here in the previous iteration of the loop
2727

2828
error: aborting due to 3 previous errors
2929

src/test/ui/borrowck/mut-borrow-in-loop.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
1515
LL | (self.func)(arg)
1616
| ------------^^^-
1717
| | |
18-
| | mutable borrow starts here in previous iteration of loop
18+
| | `*arg` was mutably borrowed here in the previous iteration of the loop
1919
| argument requires that `*arg` is borrowed for `'a`
2020

2121
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
@@ -27,7 +27,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
2727
LL | (self.func)(arg)
2828
| ------------^^^-
2929
| | |
30-
| | mutable borrow starts here in previous iteration of loop
30+
| | `*arg` was mutably borrowed here in the previous iteration of the loop
3131
| argument requires that `*arg` is borrowed for `'a`
3232

3333
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
@@ -39,7 +39,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
3939
LL | (self.func)(arg)
4040
| ------------^^^-
4141
| | |
42-
| | mutable borrow starts here in previous iteration of loop
42+
| | `*arg` was mutably borrowed here in the previous iteration of the loop
4343
| argument requires that `*arg` is borrowed for `'a`
4444

4545
error: aborting due to 3 previous errors; 1 warning emitted

src/test/ui/borrowck/two-phase-across-loop.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0499]: cannot borrow `foo` as mutable more than once at a time
22
--> $DIR/two-phase-across-loop.rs:17:22
33
|
44
LL | strings.push(foo.get_string());
5-
| ^^^ mutable borrow starts here in previous iteration of loop
5+
| ^^^ `foo` was mutably borrowed here in the previous iteration of the loop
66

77
error: aborting due to previous error
88

src/test/ui/nll/closures-in-loops.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
1515
LL | v.push(|| x = String::new());
1616
| ^^ - borrows occur due to use of `x` in closure
1717
| |
18-
| mutable borrow starts here in previous iteration of loop
18+
| `x` was mutably borrowed here in the previous iteration of the loop
1919

2020
error[E0524]: two closures require unique access to `x` at the same time
2121
--> $DIR/closures-in-loops.rs:20:16

src/test/ui/nll/issue-62007-assign-const-index.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn to_refs<T>(mut list: [&mut List<T>; 2]) -> Vec<&mut T> {
55
| - let's call the lifetime of this reference `'1`
66
...
77
LL | result.push(&mut list[0].value);
8-
| ^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
8+
| ^^^^^^^^^^^^^^^^^^ `list[_].value` was mutably borrowed here in the previous iteration of the loop
99
...
1010
LL | return result;
1111
| ------ returning this value requires that `list[_].value` is borrowed for `'1`
@@ -19,7 +19,7 @@ LL | fn to_refs<T>(mut list: [&mut List<T>; 2]) -> Vec<&mut T> {
1919
LL | if let Some(n) = list[0].next.as_mut() {
2020
| ^^^^^^^^^^^^---------
2121
| |
22-
| mutable borrow starts here in previous iteration of loop
22+
| `list[_].next` was mutably borrowed here in the previous iteration of the loop
2323
| argument requires that `list[_].next` is borrowed for `'1`
2424

2525
error: aborting due to 2 previous errors

src/test/ui/nll/issue-62007-assign-differing-fields.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a
55
| -- lifetime `'a` defined here
66
...
77
LL | result.push(&mut (list.0).value);
8-
| ^^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
8+
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
99
...
1010
LL | return result;
1111
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
@@ -19,7 +19,7 @@ LL | fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a
1919
LL | if let Some(n) = (list.0).next.as_mut() {
2020
| ^^^^^^^^^^^^^---------
2121
| |
22-
| mutable borrow starts here in previous iteration of loop
22+
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
2323
| argument requires that `list.0.next` is borrowed for `'a`
2424

2525
error: aborting due to 2 previous errors

src/test/ui/nll/polonius/assignment-to-differing-field.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn assignment_to_field_projection<'a, T>(
55
| -- lifetime `'a` defined here
66
...
77
LL | result.push(&mut (list.0).value);
8-
| ^^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
8+
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
99
...
1010
LL | return result;
1111
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
@@ -19,7 +19,7 @@ LL | fn assignment_to_field_projection<'a, T>(
1919
LL | if let Some(n) = (list.0).next.as_mut() {
2020
| ^^^^^^^^^^^^^---------
2121
| |
22-
| mutable borrow starts here in previous iteration of loop
22+
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
2323
| argument requires that `list.0.next` is borrowed for `'a`
2424

2525
error[E0499]: cannot borrow `list.0.0.0.0.0.value` as mutable more than once at a time
@@ -29,7 +29,7 @@ LL | fn assignment_through_projection_chain<'a, T>(
2929
| -- lifetime `'a` defined here
3030
...
3131
LL | result.push(&mut ((((list.0).0).0).0).0.value);
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.value` was mutably borrowed here in the previous iteration of the loop
3333
...
3434
LL | return result;
3535
| ------ returning this value requires that `list.0.0.0.0.0.value` is borrowed for `'a`
@@ -43,7 +43,7 @@ LL | fn assignment_through_projection_chain<'a, T>(
4343
LL | if let Some(n) = ((((list.0).0).0).0).0.next.as_mut() {
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^---------
4545
| |
46-
| mutable borrow starts here in previous iteration of loop
46+
| `list.0.0.0.0.0.next` was mutably borrowed here in the previous iteration of the loop
4747
| argument requires that `list.0.0.0.0.0.next` is borrowed for `'a`
4848

4949
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)