Update ui/borrowck/borrowck-closures-mut-of-imm.rs robust w.r.t. NLL.

This commit is contained in:
Felix S. Klock II 2018-11-05 15:25:11 +01:00
parent fe29cd0a3d
commit c25319fcfc
3 changed files with 43 additions and 25 deletions

View File

@ -1,15 +1,32 @@
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-closures-mut-of-imm.rs:23:21
--> $DIR/borrowck-closures-mut-of-imm.rs:23:25
|
LL | let c1 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
LL | let mut c1 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-closures-mut-of-imm.rs:25:21
--> $DIR/borrowck-closures-mut-of-imm.rs:25:25
|
LL | let c2 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
LL | let mut c2 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
error: aborting due to 2 previous errors
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
|
LL | let mut c1 = || set(&mut *x);
| -- - first borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | //~^ ERROR cannot borrow
LL | let mut c2 = || set(&mut *x);
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
...
LL | c2(); c1();
| -- first borrow later used here
For more information about this error, try `rustc --explain E0596`.
error: aborting due to 3 previous errors
Some errors occurred: E0524, E0596.
For more information about an error, try `rustc --explain E0524`.

View File

@ -20,11 +20,12 @@ fn set(x: &mut isize) {
}
fn a(x: &isize) {
let c1 = || set(&mut *x);
let mut c1 = || set(&mut *x);
//~^ ERROR cannot borrow
let c2 = || set(&mut *x);
let mut c2 = || set(&mut *x);
//~^ ERROR cannot borrow
//~| ERROR two closures require unique access to `x` at the same time
c2(); c1();
}
fn main() {

View File

@ -1,30 +1,30 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-imm.rs:25:14
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
|
LL | let c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | let mut c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | //~^ ERROR cannot borrow
LL | let c2 = || set(&mut *x);
| ^^ - borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
LL | let mut c2 = || set(&mut *x);
| ^^ - borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
...
LL | }
| - borrow from first closure ends here
error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
--> $DIR/borrowck-closures-mut-of-imm.rs:23:26
--> $DIR/borrowck-closures-mut-of-imm.rs:23:30
|
LL | let c1 = || set(&mut *x);
| ^^ cannot borrow as mutable
LL | let mut c1 = || set(&mut *x);
| ^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
--> $DIR/borrowck-closures-mut-of-imm.rs:25:26
--> $DIR/borrowck-closures-mut-of-imm.rs:25:30
|
LL | let c2 = || set(&mut *x);
| ^^ cannot borrow as mutable
LL | let mut c2 = || set(&mut *x);
| ^^ cannot borrow as mutable
error: aborting due to 3 previous errors