]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/dst-coerce-custom.rs
aa28ae00e2772e4ffff21518b8f9cbe023bfad7d
1 // Copyright 2015 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 // Test a very simple custom DST coercion.
15 use std
::ops
::CoerceUnsized
;
16 use std
::marker
::Unsize
;
18 struct Bar
<T
: ?Sized
> {
22 impl<T
: ?Sized
+Unsize
<U
>, U
: ?Sized
> CoerceUnsized
<Bar
<U
>> for Bar
<T
> {}
29 fn get(&self) -> i32 {
36 let a
: Bar
<[i32; 3]> = Bar { x: &[1, 2, 3] }
;
37 // This is the actual coercion.
38 let b
: Bar
<[i32]> = a
;
41 assert_eq
!((*b
.x
)[0], 1);
42 assert_eq
!((*b
.x
)[1], 2);
43 assert_eq
!((*b
.x
)[2], 3);
47 let a
: Bar
<i32> = Bar { x: &42 }
;
50 assert_eq
!((*b
.x
).get(), 42);