Skip to content

Commit c454e95

Browse files
committed
Add basic test cases for closure bounds. (rust-lang#3569)
1 parent 7c0a040 commit c454e95

5 files changed

+96
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct X {
12+
field: @fn:Copy(),
13+
}
14+
15+
fn foo(blk: @fn()) -> X {
16+
return X { field: blk }; //~ ERROR expected bounds `Copy` but found no bounds
17+
}
18+
19+
fn main() {
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::comm;
12+
13+
// If this were legal you could use it to copy captured noncopyables.
14+
// Issue (#2828)
15+
16+
fn foo(blk: ~fn:Copy()) {
17+
blk();
18+
}
19+
20+
fn main() {
21+
let (p,c) = comm::stream();
22+
do foo {
23+
c.send(()); //~ ERROR does not fulfill `Copy`
24+
}
25+
p.recv();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn bar(blk: &fn:'static()) {
12+
}
13+
14+
fn foo(x: &()) {
15+
do bar {
16+
let _ = x; //~ ERROR does not fulfill `'static`
17+
}
18+
}
19+
20+
fn main() {
21+
}

src/test/compile-fail/closure-bounds-subtype.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
fn take_any(_: &fn()) {
23
}
34

@@ -7,6 +8,9 @@ fn take_copyable(_: &fn:Copy()) {
78
fn take_copyable_owned(_: &fn:Copy+Owned()) {
89
}
910

11+
fn take_const_owned(_: &fn:Const+Owned()) {
12+
}
13+
1014
fn give_any(f: &fn()) {
1115
take_any(f);
1216
take_copyable(f); //~ ERROR expected bounds `Copy` but found no bounds
@@ -29,6 +33,7 @@ fn give_copyable_owned(f: &fn:Copy+Owned()) {
2933
take_any(f);
3034
take_copyable(f);
3135
take_copyable_owned(f);
36+
take_const_owned(f); //~ ERROR expected bounds `Owned+Const` but found bounds `Copy+Owned`
3237
}
3338

34-
fn main() {}
39+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::comm;
12+
13+
fn foo(blk: ~fn:Owned()) {
14+
blk();
15+
}
16+
17+
fn main() {
18+
let (p,c) = comm::stream();
19+
do foo {
20+
c.send(());
21+
}
22+
p.recv();
23+
}

0 commit comments

Comments
 (0)