Skip to content

Commit

Permalink
Add basic test cases for closure bounds. (rust-lang#3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblum committed Jun 19, 2013
1 parent 2c21b58 commit 24bd5ba
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct X {
field: @fn:Copy(),
}

fn foo(blk: @fn()) -> X {
return X { field: blk }; //~ ERROR expected bounds `Copy` but found no bounds
}

fn main() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::comm;

// If this were legal you could use it to copy captured noncopyables.
// Issue (#2828)

fn foo(blk: ~fn:Copy()) {
blk();
}

fn main() {
let (p,c) = comm::stream();
do foo {
c.send(()); //~ ERROR does not fulfill `Copy`
}
p.recv();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn bar(blk: &fn:'static()) {
}

fn foo(x: &()) {
do bar {
let _ = x; //~ ERROR does not fulfill `'static`
}
}

fn main() {
}
7 changes: 6 additions & 1 deletion src/test/compile-fail/closure-bounds-subtype.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

fn take_any(_: &fn()) {
}

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

fn take_const_owned(_: &fn:Const+Owned()) {
}

fn give_any(f: &fn()) {
take_any(f);
take_copyable(f); //~ ERROR expected bounds `Copy` but found no bounds
Expand All @@ -29,6 +33,7 @@ fn give_copyable_owned(f: &fn:Copy+Owned()) {
take_any(f);
take_copyable(f);
take_copyable_owned(f);
take_const_owned(f); //~ ERROR expected bounds `Owned+Const` but found bounds `Copy+Owned`
}

fn main() {}
fn main() {}
23 changes: 23 additions & 0 deletions src/test/run-pass/closure-bounds-can-capture-chan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::comm;

fn foo(blk: ~fn:Owned()) {
blk();
}

fn main() {
let (p,c) = comm::stream();
do foo {
c.send(());
}
p.recv();
}

0 comments on commit 24bd5ba

Please sign in to comment.