Add basic test cases for closure bounds. (#3569)
This commit is contained in:
parent
7c0a0404d5
commit
c454e95fac
@ -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() {
|
||||
}
|
@ -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();
|
||||
}
|
@ -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() {
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
|
||||
fn take_any(_: &fn()) {
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
src/test/run-pass/closure-bounds-can-capture-chan.rs
Normal file
23
src/test/run-pass/closure-bounds-can-capture-chan.rs
Normal file
@ -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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user