File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ impl<T: Trace> Gc<T> {
88
88
89
89
/// Returns `true` if the two `Gc`s point to the same allocation.
90
90
pub fn ptr_eq ( this : & Gc < T > , other : & Gc < T > ) -> bool {
91
- this. ptr_root . get ( ) . as_ptr ( ) == other. ptr_root . get ( ) . as_ptr ( )
91
+ ptr :: eq ( this. inner ( ) , other. inner ( ) )
92
92
}
93
93
}
94
94
Original file line number Diff line number Diff line change @@ -267,3 +267,27 @@ fn trait_gc() {
267
267
use_trait_gc ( gc_foo) ;
268
268
use_trait_gc ( gc_bar) ;
269
269
}
270
+
271
+ #[ test]
272
+ fn ptr_eq ( ) {
273
+ #[ derive( Finalize , Trace ) ]
274
+ struct A ;
275
+ #[ derive( Finalize , Trace ) ]
276
+ struct B ( Gc < A > ) ;
277
+
278
+ let a = Gc :: new ( A ) ;
279
+ let aa = a. clone ( ) ;
280
+ assert ! ( Gc :: ptr_eq( & a, & aa) ) ;
281
+ let b = Gc :: new ( B ( aa) ) ;
282
+ assert ! ( Gc :: ptr_eq( & a, & b. 0 ) ) ;
283
+ let bb = Gc :: new ( B ( a. clone ( ) ) ) ;
284
+ assert ! ( Gc :: ptr_eq( & b. 0 , & bb. 0 ) ) ;
285
+
286
+ let a2 = Gc :: new ( A ) ;
287
+ assert ! ( !Gc :: ptr_eq( & a, & a2) ) ;
288
+ let b2 = Gc :: new ( B ( a2. clone ( ) ) ) ;
289
+ assert ! ( Gc :: ptr_eq( & a2, & b2. 0 ) ) ;
290
+ assert ! ( !Gc :: ptr_eq( & a, & b2. 0 ) ) ;
291
+ assert ! ( !Gc :: ptr_eq( & b. 0 , & b2. 0 ) ) ;
292
+ assert ! ( !Gc :: ptr_eq( & b. 0 , & a2) ) ;
293
+ }
You can’t perform that action at this time.
0 commit comments