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 // As dst-struct.rs, but the unsized field is the only field in the struct.
13 // pretty-expanded FIXME #23616
15 struct Fat
<T
: ?Sized
> {
20 fn foo(x
: &Fat
<[isize]>) {
22 assert
!(x
.ptr
.len() == 3);
24 assert
!(x
.ptr
[1] == 2);
27 fn foo2
<T
:ToBar
>(x
: &Fat
<[T
]>) {
30 assert
!(x
.ptr
.len() == 3);
31 assert
!(y
[0].to_bar() == bar
);
32 assert
!(x
.ptr
[1].to_bar() == bar
);
35 #[derive(Copy, Clone, PartialEq, Eq)]
39 fn to_bar(&self) -> Bar
;
43 fn to_bar(&self) -> Bar
{
49 // With a vec of ints.
50 let f1
= Fat { ptr: [1, 2, 3] }
;
54 let f3
: &Fat
<[isize]> = f2
;
56 let f4
: &Fat
<[isize]> = &f1
;
58 let f5
: &Fat
<[isize]> = &Fat { ptr: [1, 2, 3] }
;
61 // With a vec of Bars.
63 let f1
= Fat { ptr: [bar, bar, bar] }
;
67 let f3
: &Fat
<[Bar
]> = f2
;
69 let f4
: &Fat
<[Bar
]> = &f1
;
71 let f5
: &Fat
<[Bar
]> = &Fat { ptr: [bar, bar, bar] }
;
75 let f5
: &mut Fat
<[isize]> = &mut Fat { ptr: [1, 2, 3] }
;
77 assert
!(f5
.ptr
[0] == 1);
78 assert
!(f5
.ptr
[1] == 34);
79 assert
!(f5
.ptr
[2] == 3);
82 let f5
: &Fat
<[isize]> = &Fat { ptr: [] }
;
83 assert
!(f5
.ptr
.len() == 0);
84 let f5
: &Fat
<[Bar
]> = &Fat { ptr: [] }
;
85 assert
!(f5
.ptr
.len() == 0);