1
Fork 0

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`
This commit is contained in:
bors 2020-12-24 07:32:19 +00:00
commit c34c015fe2
8 changed files with 18 additions and 17 deletions

View file

@ -68,9 +68,10 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
err.span_label( err.span_label(
new_loan_span, new_loan_span,
format!( format!(
"mutable borrow starts here in previous \ "{}{} was mutably borrowed here in the previous iteration of the loop{}",
iteration of loop{}", desc,
opt_via via(opt_via),
opt_via,
), ),
); );
if let Some(old_load_end_span) = old_load_end_span { if let Some(old_load_end_span) = old_load_end_span {

View file

@ -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 --> $DIR/borrowck-mut-borrow-linear-errors.rs:12:30
| |
LL | _ => { addr.push(&mut x); } 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 error: aborting due to 3 previous errors

View file

@ -15,7 +15,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
LL | (self.func)(arg) 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` | argument requires that `*arg` is borrowed for `'a`
error[E0499]: cannot borrow `*arg` as mutable more than once at a time 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> {
LL | (self.func)(arg) 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` | argument requires that `*arg` is borrowed for `'a`
error[E0499]: cannot borrow `*arg` as mutable more than once at a time 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> {
LL | (self.func)(arg) 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` | argument requires that `*arg` is borrowed for `'a`
error: aborting due to 3 previous errors; 1 warning emitted error: aborting due to 3 previous errors; 1 warning emitted

View file

@ -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 --> $DIR/two-phase-across-loop.rs:17:22
| |
LL | strings.push(foo.get_string()); 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 error: aborting due to previous error

View file

@ -15,7 +15,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
LL | v.push(|| x = String::new()); LL | v.push(|| x = String::new());
| ^^ - borrows occur due to use of `x` in closure | ^^ - 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 error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/closures-in-loops.rs:20:16 --> $DIR/closures-in-loops.rs:20:16

View file

@ -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` | - let's call the lifetime of this reference `'1`
... ...
LL | result.push(&mut list[0].value); 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; LL | return result;
| ------ returning this value requires that `list[_].value` is borrowed for `'1` | ------ 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> {
LL | if let Some(n) = list[0].next.as_mut() { 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` | argument requires that `list[_].next` is borrowed for `'1`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -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 | -- lifetime `'a` defined here
... ...
LL | result.push(&mut (list.0).value); 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; LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a` | ------ 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
LL | if let Some(n) = (list.0).next.as_mut() { 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` | argument requires that `list.0.next` is borrowed for `'a`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -5,7 +5,7 @@ LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here | -- lifetime `'a` defined here
... ...
LL | result.push(&mut (list.0).value); 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; LL | return result;
| ------ returning this value requires that `list.0.value` is borrowed for `'a` | ------ returning this value requires that `list.0.value` is borrowed for `'a`
@ -19,7 +19,7 @@ LL | fn assignment_to_field_projection<'a, T>(
LL | if let Some(n) = (list.0).next.as_mut() { 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` | 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 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>(
| -- lifetime `'a` defined here | -- lifetime `'a` defined here
... ...
LL | result.push(&mut ((((list.0).0).0).0).0.value); 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; LL | return result;
| ------ returning this value requires that `list.0.0.0.0.0.value` is borrowed for `'a` | ------ 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>(
LL | if let Some(n) = ((((list.0).0).0).0).0.next.as_mut() { 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` | argument requires that `list.0.0.0.0.0.next` is borrowed for `'a`
error: aborting due to 4 previous errors error: aborting due to 4 previous errors