1 // Adapted from rustc run-pass test suite
3 #![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)]
4 #![feature(rustc_attrs)]
7 ops::{Deref, CoerceUnsized, DispatchFromDyn},
11 struct Ptr<T: ?Sized>(Box<T>);
13 impl<T: ?Sized> Deref for Ptr<T> {
16 fn deref(&self) -> &T {
21 impl<T: Unsize<U> + ?Sized, U: ?Sized> CoerceUnsized<Ptr<U>> for Ptr<T> {}
22 impl<T: Unsize<U> + ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T> {}
24 struct Wrapper<T: ?Sized>(T);
26 impl<T: ?Sized> Deref for Wrapper<T> {
29 fn deref(&self) -> &T {
34 impl<T: CoerceUnsized<U>, U> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
35 impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}
39 // This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
40 // without unsized_locals), but wrappers around `Self` currently are not.
41 // FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented
42 // fn wrapper(self: Wrapper<Self>) -> i32;
43 fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
44 fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
45 fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32;
49 fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32 {
52 fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32 {
55 fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32 {
61 let pw = Ptr(Box::new(Wrapper(5))) as Ptr<Wrapper<dyn Trait>>;
62 assert_eq!(pw.ptr_wrapper(), 5);
64 let wp = Wrapper(Ptr(Box::new(6))) as Wrapper<Ptr<dyn Trait>>;
65 assert_eq!(wp.wrapper_ptr(), 6);
67 let wpw = Wrapper(Ptr(Box::new(Wrapper(7)))) as Wrapper<Ptr<Wrapper<dyn Trait>>>;
68 assert_eq!(wpw.wrapper_ptr_wrapper(), 7);