1 // Copyright 2012 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.
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.
11 // Test which of the builtin types are considered sendable.
13 fn assert_send<T:Send>() { }
16 fn test<'a,T,U:Send>(_: &'a int) {
17 // lifetime pointers with 'static lifetime are ok
18 assert_send::<&'static int>();
19 assert_send::<&'static str>();
20 assert_send::<&'static [int]>();
22 // whether or not they are mutable
23 assert_send::<&'static mut int>();
25 // otherwise lifetime pointers are not ok
26 assert_send::<&'a int>(); //~ ERROR does not fulfill `Send`
27 assert_send::<&'a str>(); //~ ERROR does not fulfill `Send`
28 assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send`
31 assert_send::<~int>();
32 assert_send::<~str>();
33 assert_send::<Vec<int> >();
35 // but not if they own a bad thing
36 assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send`
38 // careful with object types, who knows what they close over...
39 assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
40 assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
41 assert_send::<&'a Dummy:Send>(); //~ ERROR does not fulfill `Send`
42 assert_send::<~Dummy:>(); //~ ERROR does not fulfill `Send`
44 // ...unless they are properly bounded
45 assert_send::<&'static Dummy:Send>();
46 assert_send::<~Dummy:Send>();
48 // but closure and object types can have lifetime bounds which make
49 // them not ok (FIXME #5121)
50 // assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
51 // assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send`
53 // unsafe ptrs are ok unless they point at unsendable things
54 assert_send::<*int>();
55 assert_send::<*&'a int>(); //~ ERROR does not fulfill `Send`