]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/kindck-freeze.rs
rand: Use fill() instead of read()
[rust.git] / src / test / compile-fail / kindck-freeze.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 freezeable.
12
13
14 fn assert_freeze<T:Freeze>() { }
15 trait Dummy { }
16
17 fn test<'a,T,U:Freeze>(_: &'a int) {
18     // lifetime pointers are ok...
19     assert_freeze::<&'static int>();
20     assert_freeze::<&'a int>();
21     assert_freeze::<&'a str>();
22     assert_freeze::<&'a [int]>();
23
24     // ...unless they are mutable
25     assert_freeze::<&'static mut int>(); //~ ERROR does not fulfill `Freeze`
26     assert_freeze::<&'a mut int>(); //~ ERROR does not fulfill `Freeze`
27
28     // ~ pointers are ok
29     assert_freeze::<~int>();
30     assert_freeze::<~str>();
31     assert_freeze::<Vec<int> >();
32
33     // but not if they own a bad thing
34     assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
35
36     // careful with object types, who knows what they close over...
37     assert_freeze::<&'a Dummy>(); //~ ERROR does not fulfill `Freeze`
38     assert_freeze::<~Dummy>(); //~ ERROR does not fulfill `Freeze`
39
40     // ...unless they are properly bounded
41     assert_freeze::<&'a Dummy:Freeze>();
42     assert_freeze::<&'static Dummy:Freeze>();
43     assert_freeze::<~Dummy:Freeze>();
44
45     // ...but even then the pointer overrides
46     assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
47
48     // closures are like an `&mut` object
49     assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze`
50
51     // unsafe ptrs are ok unless they point at unfreezeable things
52     assert_freeze::<*int>();
53     assert_freeze::<*&'a mut int>(); //~ ERROR does not fulfill `Freeze`
54 }
55
56 fn main() {
57 }