Skip to content

Commit b846820

Browse files
pcwaltonpnkfelix
authored andcommitted
Update compile-fail tests for new by-value closure semantics.
1 parent 816a4d3 commit b846820

24 files changed

+48
-342
lines changed

src/test/compile-fail/borrowck-assign-comp-idx.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ fn a() {
2626

2727
fn borrow(_x: &[int], _f: ||) {}
2828

29-
fn b() {
30-
// here we alias the mutable vector into an imm slice and try to
31-
// modify the original:
32-
33-
let mut p = vec!(1);
34-
35-
borrow(
36-
p.as_slice(),
37-
|| *p.get_mut(0) = 5); //~ ERROR cannot borrow `p` as mutable
38-
}
39-
4029
fn c() {
4130
// Legal because the scope of the borrow does not include the
4231
// modification:

src/test/compile-fail/borrowck-autoref-3261.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ impl X {
2121

2222
fn main() {
2323
let mut x = X(Right(main));
24-
(&mut x).with(
25-
|opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
24+
let x_ptr = &mut x;
25+
x_ptr.with(
26+
|opt| { //~ ERROR closure requires unique access
2627
match opt {
2728
&Right(ref f) => {
28-
x = X(Left((0,0)));
29+
*x_ptr = X(Left((0,0))); //~ ERROR cannot move `x_ptr`
2930
(*f)()
3031
},
3132
_ => fail!()

src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ struct Test<'a> {
1919

2020
fn call(f: |Fn|) {
2121
f(|| {
22-
//~^ ERROR: closure requires unique access to `f` but it is already borrowed
2322
f(|| {})
23+
//~^ ERROR: cannot move `f` into closure
2424
});
2525
}
2626

@@ -56,8 +56,9 @@ fn test6() {
5656
fn test7() {
5757
fn foo(_: |g: |int|, b: int|) {}
5858
let f = |g: |int|, b: int| {};
59-
f(|a| { //~ ERROR: cannot borrow `f` as immutable because previous closure
60-
foo(f); //~ ERROR: cannot move out of captured outer variable
59+
f(|a| {
60+
foo(f); //~ ERROR: cannot move `f`
61+
//~^ ERROR cannot move out of captured outer variable
6162
}, 3);
6263
}
6364

src/test/compile-fail/borrowck-closures-mut-and-imm.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/test/compile-fail/borrowck-closures-mut-of-imm.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/test/compile-fail/borrowck-closures-unique.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,8 @@ fn set(x: &mut int) -> int {
2424

2525
fn a(x: &mut int) {
2626
let c1 = || get(x);
27-
let c2 = || get(x);
28-
}
29-
30-
fn b(x: &mut int) {
31-
let c1 = || get(x);
32-
let c2 = || set(x); //~ ERROR closure requires unique access to `x`
33-
}
34-
35-
fn c(x: &mut int) {
36-
let c1 = || get(x);
37-
let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
38-
}
39-
40-
fn d(x: &mut int) {
41-
let c1 = || set(x);
42-
let c2 = || set(x); //~ ERROR closure requires unique access to `x`
43-
}
44-
45-
fn e(x: &mut int) {
46-
let c1: || = || x = fail!(); //~ ERROR closure cannot assign to immutable argument `x`
27+
let c2 = || get(x); //~ ERROR closure requires unique access to `*x`
28+
//~^ ERROR cannot move `x`
4729
}
4830

4931
fn main() {

src/test/compile-fail/borrowck-closures-use-after-free.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ impl Drop for Foo {
2525

2626
fn main() {
2727
let mut ptr = box Foo { x: 0 };
28+
let ptr_ref = &mut ptr;
2829
let test = |foo: &Foo| {
29-
ptr = box Foo { x: ptr.x + 1 };
30+
*ptr_ref = box Foo {
31+
x: ptr_ref.x + 1,
32+
};
3033
};
3134
test(ptr); //~ ERROR cannot borrow `*ptr`
3235
}

src/test/compile-fail/borrowck-insert-during-each.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl Foo {
2525

2626
fn bar(f: &mut Foo) {
2727
f.foo(
28-
|a| { //~ ERROR closure requires unique access to `f`
29-
f.n.insert(*a);
28+
|a| { //~ ERROR closure requires unique access to `*f`
29+
f.n.insert(*a); //~ ERROR cannot move `f`
3030
})
3131
}
3232

src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ fn borrow(v: &int, f: |x: &int|) {
1414

1515
fn box_imm() {
1616
let mut v = box 3;
17-
borrow(v,
18-
|w| { //~ ERROR cannot borrow `v` as mutable
19-
v = box 4;
20-
assert_eq!(*v, 3);
17+
let v_ptr = &mut v;
18+
borrow(*v_ptr,
19+
|w| { //~ ERROR closure requires unique access to `*v_ptr`
20+
*v_ptr = box 4; //~ ERROR cannot move `v_ptr`
21+
assert_eq!(**v_ptr, 3);
2122
assert_eq!(*w, 4);
2223
})
2324
}

src/test/compile-fail/borrowck-loan-rcvr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ fn a() {
3232
p.impurem();
3333

3434
// But in this case we do not honor the loan:
35-
p.blockm(|| { //~ ERROR cannot borrow `p` as mutable
36-
p.x = 10;
35+
p.blockm(|| {
36+
p.x = 10; //~ ERROR cannot move `p` into closure
37+
//~^ ERROR cannot assign to immutable field
3738
})
3839
}
3940

src/test/compile-fail/borrowck-loan-vec-content.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ fn has_mut_vec_but_tries_to_change_it() {
2525
let mut v = vec!(1, 2, 3);
2626
takes_imm_elt(
2727
v.get(0),
28-
|| { //~ ERROR cannot borrow `v` as mutable
29-
*v.get_mut(1) = 4;
28+
|| {
29+
*v.get_mut(1) = 4; //~ ERROR cannot move `v`
30+
//~^ ERROR cannot borrow
3031
})
3132
}
3233

src/test/compile-fail/borrowck-preserve-box-in-field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ struct F { f: Box<int> }
2525
pub fn main() {
2626
let mut x = @F {f: box 3};
2727
borrow(x.f, |b_x| {
28-
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
2928
assert_eq!(*b_x, 3);
3029
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31-
//~^ NOTE borrow occurs due to use of `x` in closure
30+
//~^ ERROR cannot move `x` into closure
3231
x = @F {f: box 4};
32+
//~^ ERROR cannot assign
3333

3434
println!("&*b_x = {:p}", &(*b_x));
3535
assert_eq!(*b_x, 3);

src/test/compile-fail/borrowck-preserve-box-in-uniq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ struct F { f: Box<int> }
2525
pub fn main() {
2626
let mut x = box @F{f: box 3};
2727
borrow(x.f, |b_x| {
28-
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
2928
assert_eq!(*b_x, 3);
3029
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31-
//~^ NOTE borrow occurs due to use of `x` in closure
30+
//~^ ERROR cannot move `x` into closure
3231
*x = @F{f: box 4};
32+
//~^ ERROR cannot assign to immutable dereference
3333

3434
println!("&*b_x = {:p}", &(*b_x));
3535
assert_eq!(*b_x, 3);

src/test/compile-fail/borrowck-preserve-box.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn borrow(x: &int, f: |x: &int|) {
2222
pub fn main() {
2323
let mut x = @3;
2424
borrow(x, |b_x| {
25-
//~^ ERROR cannot borrow `x` as mutable because `*x` is also borrowed as immutable
2625
assert_eq!(*b_x, 3);
2726
assert_eq!(&(*x) as *int, &(*b_x) as *int);
28-
//~^ NOTE borrow occurs due to use of `x` in closure
27+
//~^ ERROR cannot move `x` into closure
2928
x = @22;
29+
//~^ ERROR cannot assign to immutable captured outer variable
3030

3131
println!("&*b_x = {:p}", &(*b_x));
3232
assert_eq!(*b_x, 3);

src/test/compile-fail/borrowck-preserve-expl-deref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ struct F { f: Box<int> }
2525
pub fn main() {
2626
let mut x = @F {f: box 3};
2727
borrow((*x).f, |b_x| {
28-
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
2928
assert_eq!(*b_x, 3);
3029
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31-
//~^ NOTE borrow occurs due to use of `x` in closure
30+
//~^ ERROR cannot move `x` into closure
3231
x = @F {f: box 4};
32+
//~^ ERROR cannot assign to immutable captured outer variable
3333

3434
println!("&*b_x = {:p}", &(*b_x));
3535
assert_eq!(*b_x, 3);

src/test/compile-fail/issue-11192.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ fn main() {
2323
let test = |foo: &Foo| {
2424
println!("access {}", foo.x);
2525
ptr = box Foo { x: ptr.x + 1 };
26+
//~^ ERROR cannot assign to immutable captured outer variable
2627
println!("access {}", foo.x);
2728
};
2829
test(ptr);
29-
//~^ ERROR: cannot borrow `*ptr` as immutable
30+
//~^ ERROR use of moved value
3031
}
3132

src/test/compile-fail/issue-11873.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
fn main() {
1212
let mut v = vec!(1);
1313
let f = || v.push(2);
14-
let _w = v; //~ ERROR: cannot move out of `v`
14+
//~^ ERROR cannot borrow immutable captured outer variable
15+
let _w = v; //~ ERROR: use of moved value
1516

1617
f();
1718
}

0 commit comments

Comments
 (0)