]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/kindck-freeze.rs
test: Make manual changes to deal with the fallout from removal of
[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 use std::vec_ng::Vec;
14
15 fn assert_freeze<T:Freeze>() { }
16 trait Dummy { }
17
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]>();
24
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`
28
29     // ~ pointers are ok
30     assert_freeze::<~int>();
31     assert_freeze::<~str>();
32     assert_freeze::<Vec<int> >();
33
34     // but not if they own a bad thing
35     assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
36
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`
40
41     // ...unless they are properly bounded
42     assert_freeze::<&'a Dummy:Freeze>();
43     assert_freeze::<&'static Dummy:Freeze>();
44     assert_freeze::<~Dummy:Freeze>();
45
46     // ...but even then the pointer overrides
47     assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
48
49     // closures are like an `&mut` object
50     assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze`
51
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`
55 }
56
57 fn main() {
58 }