@@ -692,44 +692,45 @@ where
692692 }
693693}
694694
695- macro_rules! arith_scalar_func {
696- ( $rust_type : ty , $ op_name: ident, $fn_name: ident) => {
695+ macro_rules! arith_rhs_scalar_func {
696+ ( $op_name: ident, $fn_name: ident) => {
697697 // Implement (&Array<T> op_name rust_type)
698- impl <' f, T > $op_name<$rust_type > for & ' f Array <T >
698+ impl <' f, T , U > $op_name<U > for & ' f Array <T >
699699 where
700- T : HasAfEnum + ImplicitPromote <$rust_type>,
701- $rust_type: HasAfEnum + ImplicitPromote <T >,
702- <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
700+ T : HasAfEnum + ImplicitPromote <U >,
701+ U : HasAfEnum + ImplicitPromote <T > + Clone + ConstGenerator <OutType = U >,
703702 {
704- type Output = Array <<T as ImplicitPromote <$rust_type >>:: Output >;
703+ type Output = Array <<T as ImplicitPromote <U >>:: Output >;
705704
706- fn $fn_name( self , rhs: $rust_type ) -> Self :: Output {
705+ fn $fn_name( self , rhs: U ) -> Self :: Output {
707706 let temp = rhs. clone( ) ;
708707 $fn_name( self , & temp, false )
709708 }
710709 }
711710
712711 // Implement (Array<T> op_name rust_type)
713- impl <T : HasAfEnum > $op_name<$rust_type > for Array <T >
712+ impl <T , U > $op_name<U > for Array <T >
714713 where
715- T : HasAfEnum + ImplicitPromote <$rust_type>,
716- $rust_type: HasAfEnum + ImplicitPromote <T >,
717- <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
714+ T : HasAfEnum + ImplicitPromote <U >,
715+ U : HasAfEnum + ImplicitPromote <T > + Clone + ConstGenerator <OutType = U >,
718716 {
719- type Output = Array <<T as ImplicitPromote <$rust_type >>:: Output >;
717+ type Output = Array <<T as ImplicitPromote <U >>:: Output >;
720718
721- fn $fn_name( self , rhs: $rust_type ) -> Self :: Output {
719+ fn $fn_name( self , rhs: U ) -> Self :: Output {
722720 let temp = rhs. clone( ) ;
723721 $fn_name( & self , & temp, false )
724722 }
725723 }
724+ } ;
725+ }
726726
727+ macro_rules! arith_lhs_scalar_func {
728+ ( $rust_type: ty, $op_name: ident, $fn_name: ident) => {
727729 // Implement (rust_type op_name &Array<T>)
728730 impl <' f, T > $op_name<& ' f Array <T >> for $rust_type
729731 where
730732 T : HasAfEnum + ImplicitPromote <$rust_type>,
731733 $rust_type: HasAfEnum + ImplicitPromote <T >,
732- <$rust_type as ImplicitPromote <T >>:: Output : HasAfEnum ,
733734 {
734735 type Output = Array <<$rust_type as ImplicitPromote <T >>:: Output >;
735736
@@ -743,7 +744,6 @@ macro_rules! arith_scalar_func {
743744 where
744745 T : HasAfEnum + ImplicitPromote <$rust_type>,
745746 $rust_type: HasAfEnum + ImplicitPromote <T >,
746- <$rust_type as ImplicitPromote <T >>:: Output : HasAfEnum ,
747747 {
748748 type Output = Array <<$rust_type as ImplicitPromote <T >>:: Output >;
749749
@@ -754,12 +754,17 @@ macro_rules! arith_scalar_func {
754754 } ;
755755}
756756
757+ arith_rhs_scalar_func ! ( Add , add) ;
758+ arith_rhs_scalar_func ! ( Sub , sub) ;
759+ arith_rhs_scalar_func ! ( Mul , mul) ;
760+ arith_rhs_scalar_func ! ( Div , div) ;
761+
757762macro_rules! arith_scalar_spec {
758763 ( $ty_name: ty) => {
759- arith_scalar_func !( $ty_name, Add , add) ;
760- arith_scalar_func !( $ty_name, Sub , sub) ;
761- arith_scalar_func !( $ty_name, Mul , mul) ;
762- arith_scalar_func !( $ty_name, Div , div) ;
764+ arith_lhs_scalar_func !( $ty_name, Add , add) ;
765+ arith_lhs_scalar_func !( $ty_name, Sub , sub) ;
766+ arith_lhs_scalar_func !( $ty_name, Mul , mul) ;
767+ arith_lhs_scalar_func !( $ty_name, Div , div) ;
763768 } ;
764769}
765770
0 commit comments