]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/kindck-send.rs
829bdaa5332753b13f294b7fec07d75c38d8b375
[rust.git] / src / test / compile-fail / kindck-send.rs
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.
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 // Test which of the builtin types are considered sendable.
12
13 fn assert_send<T:Send>() { }
14 trait Dummy { }
15
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]>();
21
22     // whether or not they are mutable
23     assert_send::<&'static mut int>();
24
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`
29
30     // ~ pointers are ok
31     assert_send::<~int>();
32     assert_send::<~str>();
33     assert_send::<Vec<int> >();
34
35     // but not if they own a bad thing
36     assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send`
37
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`
43
44     // ...unless they are properly bounded
45     assert_send::<&'static Dummy:Send>();
46     assert_send::<~Dummy:Send>();
47
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`
52
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`
56 }
57
58 fn main() {
59 }