]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/dst-tuple-sole.rs
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-tuple.rs, but the unsized field is the only field in the tuple.
14 #![feature(unsized_tuple_coercion)]
16 type Fat
<T
: ?Sized
> = (T
,);
19 fn foo(x
: &Fat
<[isize]>) {
21 assert_eq
!(x
.0.len(), 3);
23 assert_eq
!(x
.0[1], 2);
26 fn foo2
<T
:ToBar
>(x
: &Fat
<[T
]>) {
29 assert_eq
!(x
.0.len(), 3);
30 assert_eq
!(y
[0].to_bar(), bar
);
31 assert_eq
!(x
.0[1].to_bar(), bar
);
34 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
38 fn to_bar(&self) -> Bar
;
42 fn to_bar(&self) -> Bar
{
48 // With a vec of ints.
49 let f1
= ([1, 2, 3],);
53 let f3
: &Fat
<[isize]> = f2
;
55 let f4
: &Fat
<[isize]> = &f1
;
57 let f5
: &Fat
<[isize]> = &([1, 2, 3],);
60 // With a vec of Bars.
62 let f1
= ([bar
, bar
, bar
],);
66 let f3
: &Fat
<[Bar
]> = f2
;
68 let f4
: &Fat
<[Bar
]> = &f1
;
70 let f5
: &Fat
<[Bar
]> = &([bar
, bar
, bar
],);
74 let f5
: &mut Fat
<[isize]> = &mut ([1, 2, 3],);
76 assert_eq
!(f5
.0
[0], 1);
77 assert_eq
!(f5
.0
[1], 34);
78 assert_eq
!(f5
.0
[2], 3);
81 let f5
: &Fat
<[isize]> = &([],);
82 assert
!(f5
.0
.is_empty());
83 let f5
: &Fat
<[Bar
]> = &([],);
84 assert
!(f5
.0
.is_empty());