Skip to content

Commit c25319f

Browse files
committed
Update ui/borrowck/borrowck-closures-mut-of-imm.rs robust w.r.t. NLL.
1 parent fe29cd0 commit c25319f

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed
Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
2-
--> $DIR/borrowck-closures-mut-of-imm.rs:23:21
2+
--> $DIR/borrowck-closures-mut-of-imm.rs:23:25
33
|
4-
LL | let c1 = || set(&mut *x);
5-
| ^^^^^^^ cannot borrow as mutable
4+
LL | let mut c1 = || set(&mut *x);
5+
| ^^^^^^^ cannot borrow as mutable
66

77
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
8-
--> $DIR/borrowck-closures-mut-of-imm.rs:25:21
8+
--> $DIR/borrowck-closures-mut-of-imm.rs:25:25
99
|
10-
LL | let c2 = || set(&mut *x);
11-
| ^^^^^^^ cannot borrow as mutable
10+
LL | let mut c2 = || set(&mut *x);
11+
| ^^^^^^^ cannot borrow as mutable
1212

13-
error: aborting due to 2 previous errors
13+
error[E0524]: two closures require unique access to `x` at the same time
14+
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
15+
|
16+
LL | let mut c1 = || set(&mut *x);
17+
| -- - first borrow occurs due to use of `x` in closure
18+
| |
19+
| first closure is constructed here
20+
LL | //~^ ERROR cannot borrow
21+
LL | let mut c2 = || set(&mut *x);
22+
| ^^ - second borrow occurs due to use of `x` in closure
23+
| |
24+
| second closure is constructed here
25+
...
26+
LL | c2(); c1();
27+
| -- first borrow later used here
28+
29+
error: aborting due to 3 previous errors
1430

15-
For more information about this error, try `rustc --explain E0596`.
31+
Some errors occurred: E0524, E0596.
32+
For more information about an error, try `rustc --explain E0524`.

src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ fn set(x: &mut isize) {
2020
}
2121

2222
fn a(x: &isize) {
23-
let c1 = || set(&mut *x);
23+
let mut c1 = || set(&mut *x);
2424
//~^ ERROR cannot borrow
25-
let c2 = || set(&mut *x);
25+
let mut c2 = || set(&mut *x);
2626
//~^ ERROR cannot borrow
2727
//~| ERROR two closures require unique access to `x` at the same time
28+
c2(); c1();
2829
}
2930

3031
fn main() {

src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
error[E0524]: two closures require unique access to `x` at the same time
2-
--> $DIR/borrowck-closures-mut-of-imm.rs:25:14
2+
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
33
|
4-
LL | let c1 = || set(&mut *x);
5-
| -- - previous borrow occurs due to use of `x` in closure
6-
| |
7-
| first closure is constructed here
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
88
LL | //~^ ERROR cannot borrow
9-
LL | let c2 = || set(&mut *x);
10-
| ^^ - borrow occurs due to use of `x` in closure
11-
| |
12-
| second closure is constructed here
9+
LL | let mut c2 = || set(&mut *x);
10+
| ^^ - borrow occurs due to use of `x` in closure
11+
| |
12+
| second closure is constructed here
1313
...
1414
LL | }
1515
| - borrow from first closure ends here
1616

1717
error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
18-
--> $DIR/borrowck-closures-mut-of-imm.rs:23:26
18+
--> $DIR/borrowck-closures-mut-of-imm.rs:23:30
1919
|
20-
LL | let c1 = || set(&mut *x);
21-
| ^^ cannot borrow as mutable
20+
LL | let mut c1 = || set(&mut *x);
21+
| ^^ cannot borrow as mutable
2222

2323
error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
24-
--> $DIR/borrowck-closures-mut-of-imm.rs:25:26
24+
--> $DIR/borrowck-closures-mut-of-imm.rs:25:30
2525
|
26-
LL | let c2 = || set(&mut *x);
27-
| ^^ cannot borrow as mutable
26+
LL | let mut c2 = || set(&mut *x);
27+
| ^^ cannot borrow as mutable
2828

2929
error: aborting due to 3 previous errors
3030

0 commit comments

Comments
 (0)