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. The tests
12 // in this file all test region bound and lifetime violations that are
13 // detected during type check.
16 use core::ptr::Unique;
18 fn assert_send<T:Send>() { }
21 // lifetime pointers with 'static lifetime are ok
23 fn static_lifime_ok<'a,T,U:Send>(_: &'a int) {
24 assert_send::<&'static int>();
25 assert_send::<&'static str>();
26 assert_send::<&'static [int]>();
28 // whether or not they are mutable
29 assert_send::<&'static mut int>();
32 // otherwise lifetime pointers are not ok
34 fn param_not_ok<'a>(x: &'a int) {
35 assert_send::<&'a int>(); //~ ERROR declared lifetime bound not satisfied
38 fn param_not_ok1<'a>(_: &'a int) {
39 assert_send::<&'a str>(); //~ ERROR declared lifetime bound not satisfied
42 fn param_not_ok2<'a>(_: &'a int) {
43 assert_send::<&'a [int]>(); //~ ERROR declared lifetime bound not satisfied
49 assert_send::<Box<int>>();
50 assert_send::<String>();
51 assert_send::<Vec<int>>();
54 // but not if they own a bad thing
56 fn box_with_region_not_ok<'a>() {
57 assert_send::<Box<&'a int>>(); //~ ERROR declared lifetime bound not satisfied
60 // objects with insufficient bounds no ok
62 fn object_with_random_bound_not_ok<'a>() {
63 assert_send::<&'a (Dummy+'a)>();
64 //~^ ERROR reference has a longer lifetime
67 fn object_with_send_bound_not_ok<'a>() {
68 assert_send::<&'a (Dummy+Send)>();
69 //~^ ERROR declared lifetime bound not satisfied
72 fn closure_with_lifetime_not_ok<'a>() {
73 assert_send::<||:'a>();
74 //~^ ERROR not implemented
77 // unsafe pointers are ok unless they point at unsendable things
79 struct UniqueUnsafePtr(Unique<*const int>);
81 unsafe impl Send for UniqueUnsafePtr {}
83 fn unsafe_ok1<'a>(_: &'a int) {
84 assert_send::<UniqueUnsafePtr>();