@@ -115,6 +115,7 @@ import Data.Typeable ( Typeable )
115115import Data.Char ( ord )
116116import Data.List ( partition )
117117import Data.List.NonEmpty ( NonEmpty (.. ) )
118+ import Data.Semigroup ( Semigroup (.. ) )
118119import Data.Word ( Word8 )
119120
120121-- | ABIs support by Rust's foreign function interface (@syntax::abi::Abi@). Note that of these,
@@ -490,6 +491,17 @@ whereClause (Generics _ _ wc _) = wc
490491
491492instance Located a => Located (Generics a ) where spanOf (Generics _ _ _ s) = spanOf s
492493
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+
493505-- | An item within an impl (@syntax::ast::ImplItem@ with @syntax::ast::ImplItemKind@ inlined).
494506--
495507-- Examples:
@@ -1161,6 +1173,13 @@ data WhereClause a = WhereClause [WherePredicate a] a
11611173
11621174instance Located a => Located (WhereClause a ) where spanOf (WhereClause _ s) = spanOf s
11631175
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+
11641183-- | An individual predicate in a 'WhereClause' (@syntax::ast::WherePredicate@).
11651184data WherePredicate a
11661185 -- | type bound (@syntax::ast::WhereBoundPredicate@) (example: @for\<\'c\> Foo: Send+Clone+\'c@)
0 commit comments