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 freezeable.
14 fn assert_freeze<T:Freeze>() { }
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]>();
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`
29 assert_freeze::<~int>();
30 assert_freeze::<~str>();
31 assert_freeze::<Vec<int> >();
33 // but not if they own a bad thing
34 assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
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`
40 // ...unless they are properly bounded
41 assert_freeze::<&'a Dummy:Freeze>();
42 assert_freeze::<&'static Dummy:Freeze>();
43 assert_freeze::<~Dummy:Freeze>();
45 // ...but even then the pointer overrides
46 assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
48 // closures are like an `&mut` object
49 assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze`
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`