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 #![feature(box_syntax)]
13 struct Fat<T: ?Sized> {
19 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
22 #[derive(Copy, Clone, PartialEq, Eq)]
28 fn to_bar(&self) -> Bar;
29 fn to_val(&self) -> isize;
33 fn to_bar(&self) -> Bar {
36 fn to_val(&self) -> isize {
41 fn to_bar(&self) -> Bar {
44 fn to_val(&self) -> isize {
50 fn foo(x: &Fat<ToBar>) {
52 assert_eq!(x.f2, "some str");
53 assert_eq!(x.ptr.to_bar(), Bar);
54 assert_eq!(x.ptr.to_val(), 42);
57 assert_eq!(y.to_bar(), Bar);
58 assert_eq!(y.to_val(), 42);
62 assert_eq!(x.to_bar(), Bar);
63 assert_eq!(x.to_val(), 42);
66 fn baz(x: &Fat<Fat<ToBar>>) {
68 assert_eq!(x.f2, "some str");
69 assert_eq!(x.ptr.f1, 8);
70 assert_eq!(x.ptr.f2, "deep str");
71 assert_eq!(x.ptr.ptr.to_bar(), Bar);
72 assert_eq!(x.ptr.ptr.to_val(), 42);
75 assert_eq!(y.to_bar(), Bar);
76 assert_eq!(y.to_val(), 42);
81 let f1 = Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
85 let f3: &Fat<ToBar> = f2;
87 let f4: &Fat<ToBar> = &f1;
89 let f5: &Fat<ToBar> = &Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
93 let f6: &Fat<ToBar> = &Fat { f1: 5, f2: "some str", ptr: Bar };
94 assert_eq!(f6.ptr.to_bar(), Bar);
98 let f7: Box<ToBar> = Box::new(Bar1 {f :42});
103 Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };
107 let f3: &Fat<Fat<ToBar>> = f2;
109 let f4: &Fat<Fat<ToBar>> = &f1;
111 let f5: &Fat<Fat<ToBar>> =
112 &Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };