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.
15 fn assert_freeze<T:Freeze>() { }
18 fn test<'a,T,U:Freeze>(_: &'a int) {
19 // lifetime pointers are ok...
20 assert_freeze::<&'static int>();
21 assert_freeze::<&'a int>();
22 assert_freeze::<&'a str>();
23 assert_freeze::<&'a [int]>();
25 // ...unless they are mutable
26 assert_freeze::<&'static mut int>(); //~ ERROR does not fulfill `Freeze`
27 assert_freeze::<&'a mut int>(); //~ ERROR does not fulfill `Freeze`
30 assert_freeze::<~int>();
31 assert_freeze::<~str>();
32 assert_freeze::<Vec<int> >();
34 // but not if they own a bad thing
35 assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
37 // careful with object types, who knows what they close over...
38 assert_freeze::<&'a Dummy>(); //~ ERROR does not fulfill `Freeze`
39 assert_freeze::<~Dummy>(); //~ ERROR does not fulfill `Freeze`
41 // ...unless they are properly bounded
42 assert_freeze::<&'a Dummy:Freeze>();
43 assert_freeze::<&'static Dummy:Freeze>();
44 assert_freeze::<~Dummy:Freeze>();
46 // ...but even then the pointer overrides
47 assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
49 // closures are like an `&mut` object
50 assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze`
52 // unsafe ptrs are ok unless they point at unfreezeable things
53 assert_freeze::<*int>();
54 assert_freeze::<*&'a mut int>(); //~ ERROR does not fulfill `Freeze`