2 // Test a very simple custom DST coercion.
4 #![feature(unsize, coerce_unsized)]
6 use std::ops::CoerceUnsized;
7 use std::marker::Unsize;
9 struct Bar<T: ?Sized> {
13 impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Bar<U>> for Bar<T> {}
20 fn get(&self) -> i32 {
27 let a: Bar<[i32; 3]> = Bar { x: &[1, 2, 3] };
28 // This is the actual coercion.
29 let b: Bar<[i32]> = a;
32 assert_eq!((*b.x)[0], 1);
33 assert_eq!((*b.x)[1], 2);
34 assert_eq!((*b.x)[2], 3);
38 let a: Bar<i32> = Bar { x: &42 };
39 let b: Bar<dyn Baz> = a;
41 assert_eq!((*b.x).get(), 42);