Removed ignore-test-compare-mode-nll from borrowck-closures-two-mut-fail.rs

by strengthening the tests there.
This commit is contained in:
Felix S. Klock II 2018-08-15 23:31:00 +02:00
parent dd9f84f2d3
commit fb3ccb2aa2
3 changed files with 93 additions and 10 deletions

View File

@ -0,0 +1,75 @@
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:26:24
|
LL | let c1 = to_fn_mut(|| x = 4);
| -- - first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
LL | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
| -- borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:37:24
|
LL | let c1 = to_fn_mut(|| set(&mut x));
| -- - first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
| -- borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:44:24
|
LL | let c1 = to_fn_mut(|| x = 5);
| -- - first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
LL | let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
| -- borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:51:24
|
LL | let c1 = to_fn_mut(|| x = 5);
| -- - first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
LL | let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `x` as mutable more than once
LL | c1;
| -- borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:63:24
|
LL | let c1 = to_fn_mut(|| set(&mut *x.f));
| -- - first borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
LL | let c2 = to_fn_mut(|| set(&mut *x.f));
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `x` as mutable more than once
LL | c1;
| -- borrow later used here
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0499`.

View File

@ -8,22 +8,23 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Tests that two closures cannot simultaneously have mutable
// access to the variable, whether that mutable access be used
// for direct assignment or for taking mutable ref. Issue #6801.
// ignore-compare-mode-nll
#![feature(box_syntax)]
fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
fn a() {
let mut x = 3;
let c1 = to_fn_mut(|| x = 4);
let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
c1;
}
fn set(x: &mut isize) {
@ -34,12 +35,14 @@ fn b() {
let mut x = 3;
let c1 = to_fn_mut(|| set(&mut x));
let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
c1;
}
fn c() {
let mut x = 3;
let c1 = to_fn_mut(|| x = 5);
let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
c1;
}
fn d() {
@ -47,6 +50,7 @@ fn d() {
let c1 = to_fn_mut(|| x = 5);
let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
//~^ ERROR cannot borrow `x` as mutable more than once
c1;
}
fn g() {
@ -58,6 +62,7 @@ fn g() {
let c1 = to_fn_mut(|| set(&mut *x.f));
let c2 = to_fn_mut(|| set(&mut *x.f));
//~^ ERROR cannot borrow `x` as mutable more than once
c1;
}
fn main() {

View File

@ -9,11 +9,12 @@ LL | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable mo
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
LL | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:36:24
--> $DIR/borrowck-closures-two-mut-fail.rs:37:24
|
LL | let c1 = to_fn_mut(|| set(&mut x));
| -- - 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
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
LL | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:42:24
--> $DIR/borrowck-closures-two-mut-fail.rs:44:24
|
LL | let c1 = to_fn_mut(|| x = 5);
| -- - 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
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | c1;
LL | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:48:24
--> $DIR/borrowck-closures-two-mut-fail.rs:51:24
|
LL | let c1 = to_fn_mut(|| x = 5);
| -- - 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
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `x` as mutable more than once
...
LL | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-closures-two-mut-fail.rs:59:24
--> $DIR/borrowck-closures-two-mut-fail.rs:63:24
|
LL | let c1 = to_fn_mut(|| set(&mut *x.f));
| -- - previous borrow occurs due to use of `x` in closure
@ -66,7 +69,7 @@ LL | let c2 = to_fn_mut(|| set(&mut *x.f));
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
LL | //~^ ERROR cannot borrow `x` as mutable more than once
...
LL | }
| - first borrow ends here