@@ -53,6 +53,87 @@ impl ByteRepr for StructWithCtor {
5353pub fn foo_0 ( x : Ptr < i32 > ) -> Ptr < i32 > {
5454 return ( x) . clone ( ) ;
5555}
56+ #[ derive( Default ) ]
57+ pub struct Value_ {
58+ pub v : Value < i32 > ,
59+ }
60+ impl Value_ {
61+ pub fn new ( u : i32 ) -> Self {
62+ let u: Value < i32 > = Rc :: new ( RefCell :: new ( u) ) ;
63+ let __this: Value < Value_ > = Rc :: new ( RefCell :: new ( Self {
64+ v : Rc :: new ( RefCell :: new ( ( * u. borrow ( ) ) ) ) ,
65+ } ) ) ;
66+ let this: Ptr < Value_ > = __this. as_pointer ( ) ;
67+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
68+ }
69+ }
70+ impl Clone for Value_ {
71+ fn clone ( & self ) -> Self {
72+ let __this: Value < Value_ > = Rc :: new ( RefCell :: new ( Self {
73+ v : Rc :: new ( RefCell :: new ( ( * self . v . borrow ( ) ) ) ) ,
74+ } ) ) ;
75+ let this: Ptr < Value_ > = __this. as_pointer ( ) ;
76+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
77+ }
78+ }
79+ impl ByteRepr for Value_ {
80+ fn byte_size ( ) -> usize {
81+ 4
82+ }
83+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
84+ ( * self . v . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
85+ }
86+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
87+ Self {
88+ v : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
89+ }
90+ }
91+ }
92+ #[ derive( ) ]
93+ pub struct Ptr_ {
94+ pub v1 : Value < Value_ > ,
95+ pub v2 : Value < Value_ > ,
96+ }
97+ impl Ptr_ {
98+ pub fn new ( ) -> Self {
99+ let __this: Value < Ptr_ > = Rc :: new ( RefCell :: new ( Self {
100+ v1 : Rc :: new ( RefCell :: new ( Value_ :: new ( { 11 } ) ) ) ,
101+ v2 : Rc :: new ( RefCell :: new ( Value_ :: new ( { 22 } ) ) ) ,
102+ } ) ) ;
103+ let this: Ptr < Ptr_ > = __this. as_pointer ( ) ;
104+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
105+ }
106+ }
107+ impl Clone for Ptr_ {
108+ fn clone ( & self ) -> Self {
109+ let __this: Value < Ptr_ > = Rc :: new ( RefCell :: new ( Self {
110+ v1 : Rc :: new ( RefCell :: new ( ( * self . v1 . borrow ( ) ) . clone ( ) ) ) ,
111+ v2 : Rc :: new ( RefCell :: new ( ( * self . v2 . borrow ( ) ) . clone ( ) ) ) ,
112+ } ) ) ;
113+ let this: Ptr < Ptr_ > = __this. as_pointer ( ) ;
114+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
115+ }
116+ }
117+ impl Default for Ptr_ {
118+ fn default ( ) -> Self {
119+ { Ptr_ :: new ( ) }
120+ }
121+ }
122+ impl ByteRepr for Ptr_ {
123+ fn byte_size ( ) -> usize {
124+ 8
125+ }
126+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
127+ ( * self . v1 . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
128+ ( * self . v2 . borrow ( ) ) . to_bytes ( & mut buf[ 4 ..8 ] ) ;
129+ }
130+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
131+ Self {
132+ v1 : Rc :: new ( RefCell :: new ( <Value_ >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
133+ v2 : Rc :: new ( RefCell :: new ( <Value_ >:: from_bytes ( & buf[ 4 ..8 ] ) ) ) ,
134+ }
135+ }
136+ }
56137pub fn main ( ) {
57138 __cpp2rust_init_globals ( ) ;
58139 std:: process:: exit ( main_0 ( ) ) ;
@@ -66,6 +147,9 @@ fn main_0() -> i32 {
66147 && ( ( ( { StructWithCtorImpl :: x1( & struct_with_ctor. as_pointer( ) , ) } ) . read( ) ) == 2 ) )
67148 && ( ( ( { StructWithCtorImpl :: x2( & struct_with_ctor. as_pointer( ) , ) } ) . read( ) ) == 1 )
68149 ) ;
150+ let p: Value < Ptr_ > = Rc :: new ( RefCell :: new ( Ptr_ :: new ( ) ) ) ;
151+ assert ! ( ( ( * ( * ( * p. borrow( ) ) . v1. borrow( ) ) . v. borrow( ) ) == 11 ) ) ;
152+ assert ! ( ( ( * ( * ( * p. borrow( ) ) . v2. borrow( ) ) . v. borrow( ) ) == 22 ) ) ;
69153 return 0 ;
70154}
71155pub trait StructWithCtorImpl {
0 commit comments