@@ -115,6 +115,7 @@ import Data.Typeable ( Typeable )
115
115
import Data.Char ( ord )
116
116
import Data.List ( partition )
117
117
import Data.List.NonEmpty ( NonEmpty (.. ) )
118
+ import Data.Semigroup ( Semigroup (.. ) )
118
119
import Data.Word ( Word8 )
119
120
120
121
-- | ABIs support by Rust's foreign function interface (@syntax::abi::Abi@). Note that of these,
@@ -490,6 +491,17 @@ whereClause (Generics _ _ wc _) = wc
490
491
491
492
instance Located a => Located (Generics a ) where spanOf (Generics _ _ _ s) = spanOf s
492
493
494
+ instance Semigroup a => Semigroup (Generics a ) where
495
+ Generics lt1 tp1 wc1 x1 <> Generics lt2 tp2 wc2 x2 = Generics lts tps wcs xs
496
+ where lts = lt1 ++ lt2
497
+ tps = tp1 ++ tp2
498
+ wcs = wc1 <> wc2
499
+ xs = x1 <> x2
500
+
501
+ instance (Semigroup a , Monoid a ) => Monoid (Generics a ) where
502
+ mappend = (<>)
503
+ mempty = Generics [] [] mempty mempty
504
+
493
505
-- | An item within an impl (@syntax::ast::ImplItem@ with @syntax::ast::ImplItemKind@ inlined).
494
506
--
495
507
-- Examples:
@@ -1161,6 +1173,13 @@ data WhereClause a = WhereClause [WherePredicate a] a
1161
1173
1162
1174
instance Located a => Located (WhereClause a ) where spanOf (WhereClause _ s) = spanOf s
1163
1175
1176
+ instance Semigroup a => Semigroup (WhereClause a ) where
1177
+ WhereClause wp1 x1 <> WhereClause wp2 x2 = WhereClause (wp1 ++ wp2) (x1 <> x2)
1178
+
1179
+ instance (Semigroup a , Monoid a ) => Monoid (WhereClause a ) where
1180
+ mappend = (<>)
1181
+ mempty = WhereClause [] mempty
1182
+
1164
1183
-- | An individual predicate in a 'WhereClause' (@syntax::ast::WherePredicate@).
1165
1184
data WherePredicate a
1166
1185
-- | type bound (@syntax::ast::WhereBoundPredicate@) (example: @for\<\'c\> Foo: Send+Clone+\'c@)
0 commit comments