Make ui/borrowck/borrowck-reborrow-from-mut.rs
robust w.r.t. NLL.
This commit is contained in:
parent
9f9bf94b8d
commit
6c7d82e1ca
3 changed files with 135 additions and 19 deletions
|
@ -1,3 +1,107 @@
|
|||
error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:23:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1;
|
||||
| ------------- first mutable borrow occurs here
|
||||
LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
| ----- first borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `foo.bar1` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:28:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1;
|
||||
| ------------- mutable borrow occurs here
|
||||
LL | let _bar2 = &foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^ immutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
| ----- mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `foo.bar1` as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:33:17
|
||||
|
|
||||
LL | let _bar1 = &foo.bar1;
|
||||
| --------- immutable borrow occurs here
|
||||
LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
| ----- immutable borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:55:21
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1;
|
||||
| ------------- first mutable borrow occurs here
|
||||
LL | match *foo {
|
||||
LL | Foo { bar1: ref mut _bar1, bar2: _ } => {}
|
||||
| ^^^^^^^^^^^^^ second mutable borrow occurs here
|
||||
...
|
||||
LL | use_mut(_bar1);
|
||||
| ----- first borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `foo.bar1` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:62:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1.int1;
|
||||
| ------------------ mutable borrow occurs here
|
||||
LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^ immutable borrow occurs here
|
||||
LL | let _foo2 = &*foo; //~ ERROR cannot borrow
|
||||
LL | use_mut(_bar1);
|
||||
| ----- mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `*foo` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:63:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1.int1;
|
||||
| ------------------ mutable borrow occurs here
|
||||
LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow
|
||||
LL | let _foo2 = &*foo; //~ ERROR cannot borrow
|
||||
| ^^^^^ immutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
| ----- mutable borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:68:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1.int1;
|
||||
| ------------------ first mutable borrow occurs here
|
||||
LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
| ----- first borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `*foo` as mutable more than once at a time
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:73:17
|
||||
|
|
||||
LL | let _bar1 = &mut foo.bar1.int1;
|
||||
| ------------------ first mutable borrow occurs here
|
||||
LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
| ----- first borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `foo.bar1` as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:78:17
|
||||
|
|
||||
LL | let _bar1 = &foo.bar1.int1;
|
||||
| -------------- immutable borrow occurs here
|
||||
LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
| ----- immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `*foo` as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:83:17
|
||||
|
|
||||
LL | let _bar1 = &foo.bar1.int1;
|
||||
| -------------- immutable borrow occurs here
|
||||
LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
| ----- immutable borrow later used here
|
||||
|
||||
error[E0596]: cannot borrow `foo.bar1` as mutable, as it is behind a `&` reference
|
||||
--> $DIR/borrowck-reborrow-from-mut.rs:98:17
|
||||
|
|
||||
|
@ -6,6 +110,7 @@ LL | fn borrow_mut_from_imm(foo: &Foo) {
|
|||
LL | let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
||||
Some errors occurred: E0499, E0502, E0596.
|
||||
For more information about an error, try `rustc --explain E0499`.
|
||||
|
|
|
@ -21,79 +21,79 @@ struct Bar {
|
|||
fn borrow_same_field_twice_mut_mut(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1;
|
||||
let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_same_field_twice_mut_imm(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1;
|
||||
let _bar2 = &foo.bar1; //~ ERROR cannot borrow
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_same_field_twice_imm_mut(foo: &mut Foo) {
|
||||
let _bar1 = &foo.bar1;
|
||||
let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
use_imm(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_same_field_twice_imm_imm(foo: &mut Foo) {
|
||||
let _bar1 = &foo.bar1;
|
||||
let _bar2 = &foo.bar1;
|
||||
use_imm(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_both_mut(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1;
|
||||
let _bar2 = &mut foo.bar2;
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_both_mut_pattern(foo: &mut Foo) {
|
||||
match *foo {
|
||||
Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
|
||||
Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } =>
|
||||
{ use_mut(_bar1); use_mut(_bar2); }
|
||||
}
|
||||
}
|
||||
|
||||
fn borrow_var_and_pattern(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1;
|
||||
match *foo {
|
||||
Foo { bar1: ref mut _bar1, bar2: _ } => {}
|
||||
//~^ ERROR cannot borrow
|
||||
}
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_mut_and_base_imm(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1.int1;
|
||||
let _foo1 = &foo.bar1; //~ ERROR cannot borrow
|
||||
let _foo2 = &*foo; //~ ERROR cannot borrow
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_mut_and_base_mut(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1.int1;
|
||||
let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_mut_and_base_mut2(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1.int1;
|
||||
let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_imm_and_base_mut(foo: &mut Foo) {
|
||||
let _bar1 = &foo.bar1.int1;
|
||||
let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
use_imm(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_imm_and_base_mut2(foo: &mut Foo) {
|
||||
let _bar1 = &foo.bar1.int1;
|
||||
let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
use_imm(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_imm_and_base_imm(foo: &mut Foo) {
|
||||
let _bar1 = &foo.bar1.int1;
|
||||
let _foo1 = &foo.bar1;
|
||||
let _foo2 = &*foo;
|
||||
use_imm(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_mut_and_imm(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1;
|
||||
let _foo1 = &foo.bar2;
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn borrow_mut_from_imm(foo: &Foo) {
|
||||
let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
}
|
||||
|
@ -101,6 +101,9 @@ fn borrow_mut_from_imm(foo: &Foo) {
|
|||
fn borrow_long_path_both_mut(foo: &mut Foo) {
|
||||
let _bar1 = &mut foo.bar1.int1;
|
||||
let _foo1 = &mut foo.bar2.int2;
|
||||
use_mut(_bar1);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn use_mut<T>(_: &mut T) { }
|
||||
fn use_imm<T>(_: &T) { }
|
||||
|
|
|
@ -5,6 +5,7 @@ LL | let _bar1 = &mut foo.bar1;
|
|||
| -------- first mutable borrow occurs here
|
||||
LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
LL | }
|
||||
| - first borrow ends here
|
||||
|
||||
|
@ -15,6 +16,7 @@ LL | let _bar1 = &mut foo.bar1;
|
|||
| -------- mutable borrow occurs here
|
||||
LL | let _bar2 = &foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ immutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
LL | }
|
||||
| - mutable borrow ends here
|
||||
|
||||
|
@ -25,6 +27,7 @@ LL | let _bar1 = &foo.bar1;
|
|||
| -------- immutable borrow occurs here
|
||||
LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
LL | }
|
||||
| - immutable borrow ends here
|
||||
|
||||
|
@ -47,7 +50,7 @@ LL | let _bar1 = &mut foo.bar1.int1;
|
|||
| ------------- mutable borrow occurs here
|
||||
LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ immutable borrow occurs here
|
||||
LL | let _foo2 = &*foo; //~ ERROR cannot borrow
|
||||
...
|
||||
LL | }
|
||||
| - mutable borrow ends here
|
||||
|
||||
|
@ -59,6 +62,7 @@ LL | let _bar1 = &mut foo.bar1.int1;
|
|||
LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow
|
||||
LL | let _foo2 = &*foo; //~ ERROR cannot borrow
|
||||
| ^^^^ immutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
LL | }
|
||||
| - mutable borrow ends here
|
||||
|
||||
|
@ -69,6 +73,7 @@ LL | let _bar1 = &mut foo.bar1.int1;
|
|||
| ------------- first mutable borrow occurs here
|
||||
LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
LL | }
|
||||
| - first borrow ends here
|
||||
|
||||
|
@ -79,6 +84,7 @@ LL | let _bar1 = &mut foo.bar1.int1;
|
|||
| ------------- first mutable borrow occurs here
|
||||
LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
| ^^^^ second mutable borrow occurs here
|
||||
LL | use_mut(_bar1);
|
||||
LL | }
|
||||
| - first borrow ends here
|
||||
|
||||
|
@ -89,6 +95,7 @@ LL | let _bar1 = &foo.bar1.int1;
|
|||
| ------------- immutable borrow occurs here
|
||||
LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
|
||||
| ^^^^^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
LL | }
|
||||
| - immutable borrow ends here
|
||||
|
||||
|
@ -99,6 +106,7 @@ LL | let _bar1 = &foo.bar1.int1;
|
|||
| ------------- immutable borrow occurs here
|
||||
LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow
|
||||
| ^^^^ mutable borrow occurs here
|
||||
LL | use_imm(_bar1);
|
||||
LL | }
|
||||
| - immutable borrow ends here
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue