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.
12 #![allow(unknown_features)]
13 #![feature(box_syntax)]
15 struct Fat<T: ?Sized> {
21 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
24 #[derive(Copy, Clone, PartialEq, Eq)]
30 fn to_bar(&self) -> Bar;
31 fn to_val(&self) -> isize;
35 fn to_bar(&self) -> Bar {
38 fn to_val(&self) -> isize {
43 fn to_bar(&self) -> Bar {
46 fn to_val(&self) -> isize {
52 fn foo(x: &Fat<ToBar>) {
54 assert_eq!(x.f2, "some str");
55 assert_eq!(x.ptr.to_bar(), Bar);
56 assert_eq!(x.ptr.to_val(), 42);
59 assert_eq!(y.to_bar(), Bar);
60 assert_eq!(y.to_val(), 42);
64 assert_eq!(x.to_bar(), Bar);
65 assert_eq!(x.to_val(), 42);
68 fn baz(x: &Fat<Fat<ToBar>>) {
70 assert_eq!(x.f2, "some str");
71 assert_eq!(x.ptr.f1, 8);
72 assert_eq!(x.ptr.f2, "deep str");
73 assert_eq!(x.ptr.ptr.to_bar(), Bar);
74 assert_eq!(x.ptr.ptr.to_val(), 42);
77 assert_eq!(y.to_bar(), Bar);
78 assert_eq!(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_eq!(f6.ptr.to_bar(), Bar);
100 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
101 let f7: Box<ToBar> = Box::new(Bar1 {f :42});
106 Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };
110 let f3: &Fat<Fat<ToBar>> = f2;
112 let f4: &Fat<Fat<ToBar>> = &f1;
114 let f5: &Fat<Fat<ToBar>> =
115 &Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: Bar1 {f :42}} };