1 // Copyright 2014 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 struct Fat<T: ?Sized> {
17 #[deriving(PartialEq,Eq)]
22 #[deriving(PartialEq,Eq)]
30 fn to_bar(&self) -> Bar;
31 fn to_val(&self) -> int;
35 fn to_bar(&self) -> Bar {
38 fn to_val(&self) -> int {
43 fn to_bar(&self) -> Bar {
46 fn to_val(&self) -> int {
52 fn foo(x: &Fat<ToBar>) {
54 assert!(x.f2 == "some str");
55 assert!(x.ptr.to_bar() == Bar);
56 assert!(x.ptr.to_val() == 42);
59 assert!(y.to_bar() == Bar);
60 assert!(y.to_val() == 42);
64 assert!(x.to_bar() == Bar);
65 assert!(x.to_val() == 42);
68 fn baz(x: &Fat<Fat<ToBar>>) {
70 assert!(x.f2 == "some str");
71 assert!(x.ptr.f1 == 8);
72 assert!(x.ptr.f2 == "deep str");
73 assert!(x.ptr.ptr.to_bar() == Bar);
74 assert!(x.ptr.ptr.to_val() == 42);
77 assert!(y.to_bar() == Bar);
78 assert!(y.to_val() == 42);
83 let f1 = Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
87 let f3: &Fat<ToBar> = f2;
89 let f4: &Fat<ToBar> = &f1;
91 let f5: &Fat<ToBar> = &Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
95 let f6: &Fat<ToBar> = &Fat { f1: 5, f2: "some str", ptr: Bar };
96 assert!(f6.ptr.to_bar() == Bar);
99 let f7: Box<ToBar> = box Bar1 {f :42};
104 Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };
108 let f3: &Fat<Fat<ToBar>> = f2;
110 let f4: &Fat<Fat<ToBar>> = &f1;
112 let f5: &Fat<Fat<ToBar>> =
113 &Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };