@@ -85,6 +85,56 @@ pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool {
8585 return ( ( ( * a) . v ) > ( ( * b) . v ) ) ;
8686}
8787#[ repr( C ) ]
88+ #[ derive( FnPtrArg , MoveCtorUnsafe , CppFromUnsafe , MoveAssignUnsafe , Default ) ]
89+ #[ cpp_from( i32 , new, value) ]
90+ pub struct MoveOnly {
91+ pub v : i32 ,
92+ }
93+ impl MoveOnly {
94+ pub unsafe fn new ( mut v : i32 ) -> Self {
95+ let mut this = Self { v : v } ;
96+ this
97+ }
98+ pub unsafe fn move_from ( _a0 : * mut MoveOnly ) -> Self {
99+ let mut this = Self { v : ( * _a0) . v } ;
100+ this
101+ }
102+ pub unsafe fn move_assign ( & mut self , _a0 : * mut MoveOnly ) -> * mut MoveOnly {
103+ self . v = ( * _a0) . v ;
104+ return & mut ( * ( self as * mut MoveOnly ) ) ;
105+ }
106+ }
107+ impl std:: cmp:: Ord for MoveOnly {
108+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
109+ unsafe {
110+ if operator_lt_3 ( self as * const MoveOnly , other as * const MoveOnly ) {
111+ std:: cmp:: Ordering :: Less
112+ } else if operator_lt_3 ( other as * const MoveOnly , self as * const MoveOnly ) {
113+ std:: cmp:: Ordering :: Greater
114+ } else {
115+ std:: cmp:: Ordering :: Equal
116+ }
117+ }
118+ }
119+ }
120+ impl std:: cmp:: PartialOrd for MoveOnly {
121+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
122+ Some ( self . cmp ( other) )
123+ }
124+ }
125+ impl std:: cmp:: PartialEq for MoveOnly {
126+ fn eq ( & self , other : & Self ) -> bool {
127+ unsafe {
128+ !( operator_lt_3 ( self as * const MoveOnly , other as * const MoveOnly ) )
129+ && !( operator_lt_3 ( other as * const MoveOnly , self as * const MoveOnly ) )
130+ }
131+ }
132+ }
133+ impl std:: cmp:: Eq for MoveOnly { }
134+ pub unsafe fn operator_lt_3 ( a : * const MoveOnly , b : * const MoveOnly ) -> bool {
135+ return ( ( ( * a) . v ) < ( ( * b) . v ) ) ;
136+ }
137+ #[ repr( C ) ]
88138#[ derive( Clone , VaArg , FnPtrArg , MoveCtorUnsafe , MoveAssignUnsafe , Default ) ]
89139pub struct Bag {
90140 pub items : Vec < Tracked > ,
@@ -107,9 +157,9 @@ impl Bag {
107157impl std:: cmp:: Ord for Bag {
108158 fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
109159 unsafe {
110- if operator_lt_3 ( self as * const Bag , other as * const Bag ) {
160+ if operator_lt_4 ( self as * const Bag , other as * const Bag ) {
111161 std:: cmp:: Ordering :: Less
112- } else if operator_lt_3 ( other as * const Bag , self as * const Bag ) {
162+ } else if operator_lt_4 ( other as * const Bag , self as * const Bag ) {
113163 std:: cmp:: Ordering :: Greater
114164 } else {
115165 std:: cmp:: Ordering :: Equal
@@ -124,14 +174,14 @@ impl std::cmp::PartialOrd for Bag {
124174}
125175impl std:: cmp:: PartialEq for Bag {
126176 fn eq ( & self , other : & Self ) -> bool {
127- unsafe { operator_eq_4 ( self as * const Bag , other as * const Bag ) }
177+ unsafe { operator_eq_5 ( self as * const Bag , other as * const Bag ) }
128178 }
129179}
130180impl std:: cmp:: Eq for Bag { }
131- pub unsafe fn operator_lt_3 ( a : * const Bag , b : * const Bag ) -> bool {
181+ pub unsafe fn operator_lt_4 ( a : * const Bag , b : * const Bag ) -> bool {
132182 return ( ( ( * a) . items . len ( ) ) < ( ( * b) . items . len ( ) ) ) ;
133183}
134- pub unsafe fn operator_eq_4 ( a : * const Bag , b : * const Bag ) -> bool {
184+ pub unsafe fn operator_eq_5 ( a : * const Bag , b : * const Bag ) -> bool {
135185 return ( ( ( * a) . items . len ( ) ) == ( ( * b) . items . len ( ) ) ) ;
136186}
137187pub fn main ( ) {
@@ -437,6 +487,81 @@ unsafe fn main_0() -> i32 {
437487 assert ! ( ( ( ( * bag_map. find( & bags[ ( 2 ) as usize ] ) . iter_deref( ) ) . 1 ) == ( 2 ) ) ) ;
438488 assert ! ( bag_map. find( & bags[ ( 1 ) as usize ] ) == bag_map. end( ) ) ;
439489 assert ! ( ( ( * std:: cell:: LazyCell :: force_mut( & mut * & raw mut copies_0) ) == ( 0 ) ) ) ;
490+ let mut moves: Vec < MoveOnly > = Vec :: new ( ) ;
491+ {
492+ let __init = MoveOnly :: new ( { 3 } ) ;
493+ moves. push ( __init)
494+ } ;
495+ {
496+ let __init = MoveOnly :: new ( { 1 } ) ;
497+ moves. push ( __init)
498+ } ;
499+ {
500+ let __init = MoveOnly :: new ( { 2 } ) ;
501+ moves. push ( __init)
502+ } ;
503+ match ( { moves. begin ( ) } , ) {
504+ ( mut __tmp_11, ) => {
505+ let __n = moves. end ( ) . iter_distance ( & __tmp_11) ;
506+ let mut __order: Vec < isize > = ( 0 ..__n) . collect ( ) ;
507+ __order. sort_by ( |& __x, & __y| ( * __tmp_11. iter_at ( __x) ) . cmp ( & * __tmp_11. iter_at ( __y) ) ) ;
508+ let __values: Vec < _ > = __order
509+ . iter ( )
510+ . map ( |& __i| std:: ptr:: read ( __tmp_11. iter_at ( __i) ) )
511+ . collect ( ) ;
512+ for ( __i, __v) in ( 0 ..__n) . zip ( __values) {
513+ std:: ptr:: write ( __tmp_11. iter_at ( __i) , __v) ;
514+ }
515+ }
516+ } ;
517+ assert ! (
518+ ( ( ( moves[ ( 0_usize ) ] . v) == ( 1 ) ) && ( ( moves[ ( 1_usize ) ] . v) == ( 2 ) ) )
519+ && ( ( moves[ ( 2_usize ) ] . v) == ( 3 ) )
520+ ) ;
521+ match ( { moves. begin ( ) } , ) {
522+ ( mut __tmp_12, ) => {
523+ let __n = moves. end ( ) . iter_distance ( & __tmp_12) ;
524+ let mut __order: Vec < isize > = ( 0 ..__n) . collect ( ) ;
525+ __order. sort_by ( |& __x, & __y| {
526+ let __a = __tmp_12. iter_at ( __x) as * const _ ;
527+ let __b = __tmp_12. iter_at ( __y) as * const _ ;
528+ if FnPtr :: < fn ( * const MoveOnly , * const MoveOnly ) -> bool > :: new (
529+ |a : * const MoveOnly , b : * const MoveOnly | -> bool {
530+ unsafe {
531+ return ( ( ( * a) . v ) > ( ( * b) . v ) ) ;
532+ }
533+ } ,
534+ )
535+ . call ( __a, __b)
536+ {
537+ std:: cmp:: Ordering :: Less
538+ } else if FnPtr :: < fn ( * const MoveOnly , * const MoveOnly ) -> bool > :: new (
539+ |a : * const MoveOnly , b : * const MoveOnly | -> bool {
540+ unsafe {
541+ return ( ( ( * a) . v ) > ( ( * b) . v ) ) ;
542+ }
543+ } ,
544+ )
545+ . call ( __b, __a)
546+ {
547+ std:: cmp:: Ordering :: Greater
548+ } else {
549+ std:: cmp:: Ordering :: Equal
550+ }
551+ } ) ;
552+ let __values: Vec < _ > = __order
553+ . iter ( )
554+ . map ( |& __i| std:: ptr:: read ( __tmp_12. iter_at ( __i) ) )
555+ . collect ( ) ;
556+ for ( __i, __v) in ( 0 ..__n) . zip ( __values) {
557+ std:: ptr:: write ( __tmp_12. iter_at ( __i) , __v) ;
558+ }
559+ }
560+ } ;
561+ assert ! (
562+ ( ( ( moves[ ( 0_usize ) ] . v) == ( 3 ) ) && ( ( moves[ ( 1_usize ) ] . v) == ( 2 ) ) )
563+ && ( ( moves[ ( 2_usize ) ] . v) == ( 1 ) )
564+ ) ;
440565 return ( * std:: cell:: LazyCell :: force_mut ( & mut * & raw mut copies_0) ) ;
441566}
442567pub unsafe fn __cpp2rust_init_globals ( ) {
0 commit comments