Skip to content

Commit fb3ccb2

Browse files
committed
Removed ignore-test-compare-mode-nll from borrowck-closures-two-mut-fail.rs
by strengthening the tests there.
1 parent dd9f84f commit fb3ccb2

File tree

3 files changed

+93
-10
lines changed

3 files changed

+93
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
error[E0499]: cannot borrow `x` as mutable more than once at a time
2+
--> $DIR/borrowck-closures-two-mut-fail.rs:26:24
3+
|
4+
LL | let c1 = to_fn_mut(|| x = 4);
5+
| -- - first borrow occurs due to use of `x` in closure
6+
| |
7+
| first mutable borrow occurs here
8+
LL | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
9+
| ^^ - second borrow occurs due to use of `x` in closure
10+
| |
11+
| second mutable borrow occurs here
12+
LL | c1;
13+
| -- borrow later used here
14+
15+
error[E0499]: cannot borrow `x` as mutable more than once at a time
16+
--> $DIR/borrowck-closures-two-mut-fail.rs:37:24
17+
|
18+
LL | let c1 = to_fn_mut(|| set(&mut x));
19+
| -- - first borrow occurs due to use of `x` in closure
20+
| |
21+
| first mutable borrow occurs here
22+
LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
23+
| ^^ - second borrow occurs due to use of `x` in closure
24+
| |
25+
| second mutable borrow occurs here
26+
LL | c1;
27+
| -- borrow later used here
28+
29+
error[E0499]: cannot borrow `x` as mutable more than once at a time
30+
--> $DIR/borrowck-closures-two-mut-fail.rs:44:24
31+
|
32+
LL | let c1 = to_fn_mut(|| x = 5);
33+
| -- - first borrow occurs due to use of `x` in closure
34+
| |
35+
| first mutable borrow occurs here
36+
LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
37+
| ^^ - second borrow occurs due to use of `x` in closure
38+
| |
39+
| second mutable borrow occurs here
40+
LL | c1;
41+
| -- borrow later used here
42+
43+
error[E0499]: cannot borrow `x` as mutable more than once at a time
44+
--> $DIR/borrowck-closures-two-mut-fail.rs:51:24
45+
|
46+
LL | let c1 = to_fn_mut(|| x = 5);
47+
| -- - first borrow occurs due to use of `x` in closure
48+
| |
49+
| first mutable borrow occurs here
50+
LL | let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
51+
| ^^ - second borrow occurs due to use of `x` in closure
52+
| |
53+
| second mutable borrow occurs here
54+
LL | //~^ ERROR cannot borrow `x` as mutable more than once
55+
LL | c1;
56+
| -- borrow later used here
57+
58+
error[E0499]: cannot borrow `x` as mutable more than once at a time
59+
--> $DIR/borrowck-closures-two-mut-fail.rs:63:24
60+
|
61+
LL | let c1 = to_fn_mut(|| set(&mut *x.f));
62+
| -- - first borrow occurs due to use of `x` in closure
63+
| |
64+
| first mutable borrow occurs here
65+
LL | let c2 = to_fn_mut(|| set(&mut *x.f));
66+
| ^^ - second borrow occurs due to use of `x` in closure
67+
| |
68+
| second mutable borrow occurs here
69+
LL | //~^ ERROR cannot borrow `x` as mutable more than once
70+
LL | c1;
71+
| -- borrow later used here
72+
73+
error: aborting due to 5 previous errors
74+
75+
For more information about this error, try `rustc --explain E0499`.

src/test/ui/borrowck/borrowck-closures-two-mut-fail.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-compare-mode-nll
12-
1311
// Tests that two closures cannot simultaneously have mutable
1412
// access to the variable, whether that mutable access be used
1513
// for direct assignment or for taking mutable ref. Issue #6801.
1614

17-
// ignore-compare-mode-nll
18-
1915
#![feature(box_syntax)]
2016

17+
18+
19+
20+
2121
fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
2222

2323
fn a() {
2424
let mut x = 3;
2525
let c1 = to_fn_mut(|| x = 4);
2626
let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
27+
c1;
2728
}
2829

2930
fn set(x: &mut isize) {
@@ -34,19 +35,22 @@ fn b() {
3435
let mut x = 3;
3536
let c1 = to_fn_mut(|| set(&mut x));
3637
let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
38+
c1;
3739
}
3840

3941
fn c() {
4042
let mut x = 3;
4143
let c1 = to_fn_mut(|| x = 5);
4244
let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
45+
c1;
4346
}
4447

4548
fn d() {
4649
let mut x = 3;
4750
let c1 = to_fn_mut(|| x = 5);
4851
let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
4952
//~^ ERROR cannot borrow `x` as mutable more than once
53+
c1;
5054
}
5155

5256
fn g() {
@@ -58,6 +62,7 @@ fn g() {
5862
let c1 = to_fn_mut(|| set(&mut *x.f));
5963
let c2 = to_fn_mut(|| set(&mut *x.f));
6064
//~^ ERROR cannot borrow `x` as mutable more than once
65+
c1;
6166
}
6267

6368
fn main() {

src/test/ui/borrowck/borrowck-closures-two-mut-fail.stderr

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ LL | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable mo
99
| ^^ - borrow occurs due to use of `x` in closure
1010
| |
1111
| second mutable borrow occurs here
12+
LL | c1;
1213
LL | }
1314
| - first borrow ends here
1415

1516
error[E0499]: cannot borrow `x` as mutable more than once at a time
16-
--> $DIR/borrowck-closures-two-mut-fail.rs:36:24
17+
--> $DIR/borrowck-closures-two-mut-fail.rs:37:24
1718
|
1819
LL | let c1 = to_fn_mut(|| set(&mut x));
1920
| -- - previous borrow occurs due to use of `x` in closure
@@ -23,11 +24,12 @@ LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as muta
2324
| ^^ - borrow occurs due to use of `x` in closure
2425
| |
2526
| second mutable borrow occurs here
27+
LL | c1;
2628
LL | }
2729
| - first borrow ends here
2830

2931
error[E0499]: cannot borrow `x` as mutable more than once at a time
30-
--> $DIR/borrowck-closures-two-mut-fail.rs:42:24
32+
--> $DIR/borrowck-closures-two-mut-fail.rs:44:24
3133
|
3234
LL | let c1 = to_fn_mut(|| x = 5);
3335
| -- - previous borrow occurs due to use of `x` in closure
@@ -37,11 +39,12 @@ LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as muta
3739
| ^^ - borrow occurs due to use of `x` in closure
3840
| |
3941
| second mutable borrow occurs here
42+
LL | c1;
4043
LL | }
4144
| - first borrow ends here
4245

4346
error[E0499]: cannot borrow `x` as mutable more than once at a time
44-
--> $DIR/borrowck-closures-two-mut-fail.rs:48:24
47+
--> $DIR/borrowck-closures-two-mut-fail.rs:51:24
4548
|
4649
LL | let c1 = to_fn_mut(|| x = 5);
4750
| -- - previous borrow occurs due to use of `x` in closure
@@ -51,12 +54,12 @@ LL | let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nes
5154
| ^^ - borrow occurs due to use of `x` in closure
5255
| |
5356
| second mutable borrow occurs here
54-
LL | //~^ ERROR cannot borrow `x` as mutable more than once
57+
...
5558
LL | }
5659
| - first borrow ends here
5760

5861
error[E0499]: cannot borrow `x` as mutable more than once at a time
59-
--> $DIR/borrowck-closures-two-mut-fail.rs:59:24
62+
--> $DIR/borrowck-closures-two-mut-fail.rs:63:24
6063
|
6164
LL | let c1 = to_fn_mut(|| set(&mut *x.f));
6265
| -- - previous borrow occurs due to use of `x` in closure
@@ -66,7 +69,7 @@ LL | let c2 = to_fn_mut(|| set(&mut *x.f));
6669
| ^^ - borrow occurs due to use of `x` in closure
6770
| |
6871
| second mutable borrow occurs here
69-
LL | //~^ ERROR cannot borrow `x` as mutable more than once
72+
...
7073
LL | }
7174
| - first borrow ends here
7275

0 commit comments

Comments
 (0)