File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,19 @@ impl S {
3636 }
3737 Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
3838 }
39+ pub fn S3 ( a : i32 , other : Ptr < S > ) -> Self {
40+ let a: Value < i32 > = Rc :: new ( RefCell :: new ( a) ) ;
41+ let other: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( other) ) ;
42+ let __this: Value < S > = Rc :: new ( RefCell :: new ( Self {
43+ a_ : Rc :: new ( RefCell :: new ( ( * a. borrow ( ) ) ) ) ,
44+ self__ : Rc :: new ( RefCell :: new ( Ptr :: < S > :: null ( ) ) ) ,
45+ } ) ) ;
46+ let this: Ptr < S > = __this. as_pointer ( ) ;
47+ if ( this == ( * other. borrow ( ) ) ) {
48+ ( * ( * this. upgrade ( ) . deref ( ) ) . self__ . borrow_mut ( ) ) = Ptr :: < S > :: null ( ) ;
49+ }
50+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
51+ }
3952}
4053impl Clone for S {
4154 fn clone ( & self ) -> Self {
@@ -186,6 +199,9 @@ fn main_0() -> i32 {
186199 let _lhs = ( * ( * u. borrow( ) ) . self__. borrow( ) ) . clone( ) ;
187200 _lhs == ( s. as_pointer( ) )
188201 } ) ;
202+ let s_const: Value < S > = Rc :: new ( RefCell :: new ( S :: S1 ( { 100 } ) ) ) ;
203+ let u1: Value < S > = Rc :: new ( RefCell :: new ( S :: S3 ( { 1 } , { ( s_const. as_pointer ( ) ) } ) ) ) ;
204+ assert ! ( ( * ( * u1. borrow( ) ) . self__. borrow( ) ) . is_null( ) ) ;
189205 return 0 ;
190206}
191207pub trait SImpl {
Original file line number Diff line number Diff line change @@ -32,6 +32,16 @@ impl S {
3232 }
3333 this
3434 }
35+ pub unsafe fn S3 ( mut a : i32 , mut other : * const S ) -> Self {
36+ let mut this = Self {
37+ a_ : a,
38+ self__ : std:: ptr:: null_mut ( ) ,
39+ } ;
40+ if ( ( ( & raw mut this) . cast_const ( ) ) == ( other) ) {
41+ this. self__ = std:: ptr:: null_mut ( ) ;
42+ }
43+ this
44+ }
3545 pub unsafe fn returns_this_reference ( & mut self ) -> * mut S {
3646 return & mut ( * ( self as * mut S ) ) as * mut S ;
3747 }
@@ -170,5 +180,8 @@ unsafe fn main_0() -> i32 {
170180 assert ! ( ( ( s. self__) == ( other. self__) ) ) ;
171181 let mut u: S = S :: S2 ( { 1 } , { ( & mut s as * mut S ) } ) ;
172182 assert ! ( ( ( u. self__) == ( & mut s as * mut S ) ) ) ;
183+ let s_const: S = S :: S1 ( { 100 } ) ;
184+ let mut u1: S = S :: S3 ( { 1 } , { ( & s_const as * const S ) } ) ;
185+ assert ! ( ( u1. self__) . is_null( ) ) ;
173186 return 0 ;
174187}
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ struct S {
1414 }
1515 }
1616
17+ S (int a, const S *other) : a_(a) {
18+ if (this == other) {
19+ self_ = nullptr ;
20+ }
21+ }
22+
1723 S &returns_this_reference () { return *this ; }
1824
1925 S *returns_this_pointer () { return this ; }
@@ -131,5 +137,9 @@ int main() {
131137 S u (1 , &s);
132138 assert (u.self_ == &s);
133139
140+ const S s_const = S (100 );
141+ S u1 (1 , &s_const);
142+ assert (u1.self_ == nullptr );
143+
134144 return 0 ;
135145}
You can’t perform that action at this time.
0 commit comments