Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better error message for shared borrow treated as unique for purposes of lifetimes #77692

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/rustc_mir/src/util/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(
new_loan_span,
format!(
"mutable borrow starts here in previous \
iteration of loop{}",
opt_via
"{}{} was mutably borrowed here in the previous iteration of the loop{}",
desc,
via(opt_via),
opt_via,
),
);
if let Some(old_load_end_span) = old_load_end_span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-mut-borrow-linear-errors.rs:12:30
|
LL | _ => { addr.push(&mut x); }
| ^^^^^^ mutable borrow starts here in previous iteration of loop
| ^^^^^^ `x` was mutably borrowed here in the previous iteration of the loop

error: aborting due to 3 previous errors

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/borrowck/mut-borrow-in-loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
LL | (self.func)(arg)
| ------------^^^-
| | |
| | mutable borrow starts here in previous iteration of loop
| | `*arg` was mutably borrowed here in the previous iteration of the loop
| argument requires that `*arg` is borrowed for `'a`

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

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

error: aborting due to 3 previous errors; 1 warning emitted
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/two-phase-across-loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/two-phase-across-loop.rs:17:22
|
LL | strings.push(foo.get_string());
| ^^^ mutable borrow starts here in previous iteration of loop
| ^^^ `foo` was mutably borrowed here in the previous iteration of the loop

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/closures-in-loops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
LL | v.push(|| x = String::new());
| ^^ - borrows occur due to use of `x` in closure
| |
| mutable borrow starts here in previous iteration of loop
| `x` was mutably borrowed here in the previous iteration of the loop

error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/closures-in-loops.rs:20:16
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/issue-62007-assign-const-index.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn to_refs<T>(mut list: [&mut List<T>; 2]) -> Vec<&mut T> {
| - let's call the lifetime of this reference `'1`
...
LL | result.push(&mut list[0].value);
| ^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
| ^^^^^^^^^^^^^^^^^^ `list[_].value` was mutably borrowed here in the previous iteration of the loop
...
LL | return result;
| ------ returning this value requires that `list[_].value` is borrowed for `'1`
Expand All @@ -19,7 +19,7 @@ LL | fn to_refs<T>(mut list: [&mut List<T>; 2]) -> Vec<&mut T> {
LL | if let Some(n) = list[0].next.as_mut() {
| ^^^^^^^^^^^^---------
| |
| mutable borrow starts here in previous iteration of loop
| `list[_].next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list[_].next` is borrowed for `'1`

error: aborting due to 2 previous errors
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/issue-62007-assign-differing-fields.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a
| -- lifetime `'a` defined here
...
LL | result.push(&mut (list.0).value);
| ^^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
...
LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
Expand All @@ -19,7 +19,7 @@ LL | fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a
LL | if let Some(n) = (list.0).next.as_mut() {
| ^^^^^^^^^^^^^---------
| |
| mutable borrow starts here in previous iteration of loop
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list.0.next` is borrowed for `'a`

error: aborting due to 2 previous errors
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/nll/polonius/assignment-to-differing-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
...
LL | result.push(&mut (list.0).value);
| ^^^^^^^^^^^^^^^^^^^ mutable borrow starts here in previous iteration of loop
| ^^^^^^^^^^^^^^^^^^^ `list.0.value` was mutably borrowed here in the previous iteration of the loop
...
LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a`
Expand All @@ -19,7 +19,7 @@ LL | fn assignment_to_field_projection<'a, T>(
LL | if let Some(n) = (list.0).next.as_mut() {
| ^^^^^^^^^^^^^---------
| |
| mutable borrow starts here in previous iteration of loop
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list.0.next` is borrowed for `'a`

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

error: aborting due to 4 previous errors
Expand Down