1
Fork 0

Add ui/borrowck/borrowck-closures-mut-of-mut.rs.

This is a variant of `ui/borrowck/borrowck-closures-mut-of-imm.rs`
that I used to help identify what changes I needed to make to the
latter file in order to recover its instances of E0524 under NLL.

(Basically this test includes the changes you'd need to make to
`ui/borrowck/borrowck-closures-mut-of-imm.rs` in order to get rid of
occurrences of E0596. And then I realized that one needs to add
invocations of the closures in order to properly extend the mutable
reborrows in a manner such that NLL will roughly match AST-borrowck.)
This commit is contained in:
Felix S. Klock II 2018-11-05 15:24:25 +01:00
parent f7ded5dcb6
commit fe29cd0a3d
3 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,18 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
|
LL | let mut c1 = || set(&mut *x);
| -- - first borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | let mut c2 = || set(&mut *x);
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
LL | //~^ ERROR two closures require unique access to `x` at the same time
LL | c2(); c1();
| -- first borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0524`.

View file

@ -0,0 +1,20 @@
// Tests that two closures cannot simultaneously both have mutable
// access to the variable. Related to issue #6801.
fn get(x: &isize) -> isize {
*x
}
fn set(x: &mut isize) {
*x = 4;
}
fn a(x: &mut isize) {
let mut c1 = || set(&mut *x);
let mut c2 = || set(&mut *x);
//~^ ERROR two closures require unique access to `x` at the same time
c2(); c1();
}
fn main() {
}

View file

@ -0,0 +1,18 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
|
LL | let mut c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first 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: aborting due to previous error
For more information about this error, try `rustc --explain E0524`.