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