]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-bounded-by-send.rs
Do not use entropy during gen_weighted_bool(1)
[rust.git] / src / test / compile-fail / regions-bounded-by-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. The tests
12 // in this file all test region bound and lifetime violations that are
13 // detected during type check.
14
15 extern crate core;
16 use core::ptr::Unique;
17
18 fn assert_send<T:Send>() { }
19 trait Dummy:Send { }
20
21 // lifetime pointers with 'static lifetime are ok
22
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]>();
27
28     // whether or not they are mutable
29     assert_send::<&'static mut int>();
30 }
31
32 // otherwise lifetime pointers are not ok
33
34 fn param_not_ok<'a>(x: &'a int) {
35     assert_send::<&'a int>(); //~ ERROR declared lifetime bound not satisfied
36 }
37
38 fn param_not_ok1<'a>(_: &'a int) {
39     assert_send::<&'a str>(); //~ ERROR declared lifetime bound not satisfied
40 }
41
42 fn param_not_ok2<'a>(_: &'a int) {
43     assert_send::<&'a [int]>(); //~ ERROR declared lifetime bound not satisfied
44 }
45
46 // boxes are ok
47
48 fn box_ok() {
49     assert_send::<Box<int>>();
50     assert_send::<String>();
51     assert_send::<Vec<int>>();
52 }
53
54 // but not if they own a bad thing
55
56 fn box_with_region_not_ok<'a>() {
57     assert_send::<Box<&'a int>>(); //~ ERROR declared lifetime bound not satisfied
58 }
59
60 // objects with insufficient bounds no ok
61
62 fn object_with_random_bound_not_ok<'a>() {
63     assert_send::<&'a (Dummy+'a)>();
64     //~^ ERROR reference has a longer lifetime
65 }
66
67 fn object_with_send_bound_not_ok<'a>() {
68     assert_send::<&'a (Dummy+Send)>();
69     //~^ ERROR declared lifetime bound not satisfied
70 }
71
72 fn closure_with_lifetime_not_ok<'a>() {
73     assert_send::<||:'a>();
74     //~^ ERROR not implemented
75 }
76
77 // unsafe pointers are ok unless they point at unsendable things
78
79 struct UniqueUnsafePtr(Unique<*const int>);
80
81 unsafe impl Send for UniqueUnsafePtr {}
82
83 fn unsafe_ok1<'a>(_: &'a int) {
84     assert_send::<UniqueUnsafePtr>();
85 }
86
87 fn main() {
88 }