File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -438,3 +438,24 @@ fn offset_of_dst() {
438438 assert_eq ! ( offset_of!( Foo , x) , 0 ) ;
439439 assert_eq ! ( offset_of!( Foo , y) , 2 ) ;
440440}
441+
442+ #[ test]
443+ #[ cfg( not( bootstrap) ) ]
444+ fn offset_of_addr ( ) {
445+ #[ repr( C ) ]
446+ struct Foo {
447+ x : u8 ,
448+ y : u16 ,
449+ z : Bar ,
450+ }
451+
452+ #[ repr( C ) ]
453+ struct Bar ( u8 , u8 ) ;
454+
455+ let base = Foo { x : 0 , y : 0 , z : Bar ( 0 , 0 ) } ;
456+
457+ assert_eq ! ( ptr:: addr_of!( base) . addr( ) + offset_of!( Foo , x) , ptr:: addr_of!( base. x) . addr( ) ) ;
458+ assert_eq ! ( ptr:: addr_of!( base) . addr( ) + offset_of!( Foo , y) , ptr:: addr_of!( base. y) . addr( ) ) ;
459+ assert_eq ! ( ptr:: addr_of!( base) . addr( ) + offset_of!( Foo , z. 0 ) , ptr:: addr_of!( base. z. 0 ) . addr( ) ) ;
460+ assert_eq ! ( ptr:: addr_of!( base) . addr( ) + offset_of!( Foo , z. 1 ) , ptr:: addr_of!( base. z. 1 ) . addr( ) ) ;
461+ }
You can’t perform that action at this time.
0 commit comments