Skip to content

Commit fe29cd0

Browse files
committed
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.)
1 parent f7ded5d commit fe29cd0

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0524]: two closures require unique access to `x` at the same time
2+
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
3+
|
4+
LL | let mut c1 = || set(&mut *x);
5+
| -- - first borrow occurs due to use of `x` in closure
6+
| |
7+
| first closure is constructed here
8+
LL | let mut c2 = || set(&mut *x);
9+
| ^^ - second borrow occurs due to use of `x` in closure
10+
| |
11+
| second closure is constructed here
12+
LL | //~^ ERROR two closures require unique access to `x` at the same time
13+
LL | c2(); c1();
14+
| -- first borrow later used here
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0524`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Tests that two closures cannot simultaneously both have mutable
2+
// access to the variable. Related to issue #6801.
3+
4+
fn get(x: &isize) -> isize {
5+
*x
6+
}
7+
8+
fn set(x: &mut isize) {
9+
*x = 4;
10+
}
11+
12+
fn a(x: &mut isize) {
13+
let mut c1 = || set(&mut *x);
14+
let mut c2 = || set(&mut *x);
15+
//~^ ERROR two closures require unique access to `x` at the same time
16+
c2(); c1();
17+
}
18+
19+
fn main() {
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0524]: two closures require unique access to `x` at the same time
2+
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
3+
|
4+
LL | let mut c1 = || set(&mut *x);
5+
| -- - previous borrow occurs due to use of `x` in closure
6+
| |
7+
| first closure is constructed here
8+
LL | let mut c2 = || set(&mut *x);
9+
| ^^ - borrow occurs due to use of `x` in closure
10+
| |
11+
| second closure is constructed here
12+
...
13+
LL | }
14+
| - borrow from first closure ends here
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0524`.

0 commit comments

Comments
 (0)