Skip to content

Commit

Permalink
Update tests for restrictive two-phase borrows
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 25, 2019
1 parent aa3780b commit 58d9280
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | for &x in &vector {
| immutable borrow later used here
LL | let cap = vector.capacity();
LL | vector.extend(repeat(0)); //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
| ^^^^^^ mutable borrow occurs here

error[E0502]: cannot borrow `vector` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-for-loop-head-linkage.rs:8:9
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-object-lifetime.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immut
LL | let y = x.borrowed();
| - immutable borrow occurs here
LL | let z = x.mut_borrowed(); //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^^ mutable borrow occurs here
| ^ mutable borrow occurs here
LL | y.use_ref();
| - immutable borrow later used here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | vec.get({
| immutable borrow occurs here
LL |
LL | vec.push(2);
| ^^^^^^^^^^^ mutable borrow occurs here
| ^^^ mutable borrow occurs here

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@

// This is similar to two-phase-reservation-sharing-interference.rs
// in that it shows a reservation that overlaps with a shared borrow.
//
// Currently, this test fails with lexical lifetimes, but succeeds
// with non-lexical lifetimes. (The reason is because the activation
// of the mutable borrow ends up overlapping with a lexically-scoped
// shared borrow; but a non-lexical shared borrow can end before the
// activation occurs.)
//
// So this test is just making a note of the current behavior.

#![feature(rustc_attrs)]

#[rustc_error]
fn main() { //~ ERROR compilation successful
fn main() {
let mut v = vec![0, 1, 2];
let shared = &v;

v.push(shared.len());
v.push(shared.len()); //~ ERROR cannot borrow `v` as mutable

assert_eq!(v, [0, 1, 2, 3]);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: compilation successful
--> $DIR/two-phase-reservation-sharing-interference-2.rs:17:1
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-reservation-sharing-interference-2.rs:10:5
|
LL | / fn main() { //~ ERROR compilation successful
LL | | let mut v = vec![0, 1, 2];
LL | | let shared = &v;
LL | |
... |
LL | | assert_eq!(v, [0, 1, 2, 3]);
LL | | }
| |_^
LL | let shared = &v;
| -- immutable borrow occurs here
LL |
LL | v.push(shared.len()); //~ ERROR cannot borrow `v` as mutable
| ^ ------ immutable borrow later used here
| |
| mutable borrow occurs here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0502`.
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0502.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0502]: cannot borrow `*a` as mutable because it is also borrowed as immutable
--> $DIR/E0502.rs:4:5
--> $DIR/E0502.rs:4:9
|
LL | let ref y = a;
| ----- immutable borrow occurs here
LL | bar(a); //~ ERROR E0502
| ^^^^^^ mutable borrow occurs here
| ^ mutable borrow occurs here
LL | y.use_ref();
| - immutable borrow later used here

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/hashmap-iter-value-lifetime.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let (_, thing) = my_stuff.iter().next().unwrap();
| -------- immutable borrow occurs here
LL |
LL | my_stuff.clear(); //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^^ mutable borrow occurs here
| ^^^^^^^^ mutable borrow occurs here
LL |
LL | println!("{}", *thing);
| ------ immutable borrow later used here
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/hashmap-lifetimes.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `my_stuff` as mutable because it is also borrowed as
LL | let mut it = my_stuff.iter();
| -------- immutable borrow occurs here
LL | my_stuff.insert(1, 43); //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
| ^^^^^^^^ mutable borrow occurs here
LL | it;
| -- immutable borrow later used here

Expand Down
84 changes: 0 additions & 84 deletions src/test/ui/nll/get_default.nll.stderr

This file was deleted.

39 changes: 0 additions & 39 deletions src/test/ui/nll/region-ends-after-if-condition.nll.stderr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `foo` as mutable because it is also borrowed as immu
LL | while let Some(Ok(string)) = foo.get() {
| --- immutable borrow occurs here
LL | foo.mutate();
| ^^^^^^^^^^^^ mutable borrow occurs here
| ^^^ mutable borrow occurs here
LL | //~^ ERROR cannot borrow `foo` as mutable
LL | println!("foo={:?}", *string);
| ------- immutable borrow later used here
Expand Down

0 comments on commit 58d9280

Please sign in to comment.