-- | Build error message for equation with injective type variables unused in
-- the RHS.
unusedInjectiveVarsErr :: Pair TyVarSet -> InjErrorBuilder -> CoAxBranch
                       -> (SDoc, SrcSpan)
unusedInjectiveVarsErr (Pair invis_vars vis_vars) errorBuilder tyfamEqn
  = errorBuilder (injectivityErrorHerald True $$ msg)
                 [tyfamEqn]
    where
      tvs = varSetElemsWellScoped (invis_vars `unionVarSet` vis_vars)
      has_types = not $ isEmptyVarSet vis_vars
      has_kinds = not $ isEmptyVarSet invis_vars

      doc = sep [ what <+> text "variable" <>
                  plural tvs <+> pprQuotedList tvs
                , text "cannot be inferred from the right-hand side." ]
      what = case (has_types, has_kinds) of
               (True, True)   -> text "Type and kind"
               (True, False)  -> text "Type"
               (False, True)  -> text "Kind"
               (False, False) -> pprPanic "mkUnusedInjectiveVarsErr" $ ppr tvs
      print_kinds_info = ppWhen has_kinds ppSuggestExplicitKinds
      msg = doc $$ print_kinds_info $$
            text "In the type family equation:"

-- | Build error message for equation that has a type family call at the top
-- level of RHS
unusedInjectiveVarsErr :: Pair TyVarSet -> InjErrorBuilder -> CoAxBranch
                       -> (SDoc, SrcSpan)
unusedInjectiveVarsErr (Pair invis_vars vis_vars) errorBuilder tyfamEqn
  = errorBuilder (injectivityErrorHerald True $$ msg)
                 [tyfamEqn]
    where
      tvs = varSetElemsWellScoped (invis_vars `unionVarSet` vis_vars)
      has_types = not $ isEmptyVarSet vis_vars
      has_kinds = not $ isEmptyVarSet invis_vars

      doc = sep [ what <+> text "variable" <>
                  plural tvs <+> pprQuotedList tvs
                , text "cannot be inferred from the right-hand side." ]
      what = case (has_types, has_kinds) of
               (True, True)   -> text "Type and kind"
               (True, False)  -> text "Type"
               (False, True)  -> text "Kind"
               (False, False) -> pprPanic "mkUnusedInjectiveVarsErr" $ ppr tvs
      print_kinds_info = ppWhen has_kinds ppSuggestExplicitKinds
      msg = doc $$ print_kinds_info $$
            text "In the type family equation:"

-- | Build error message for equation that has a type family call at the top
-- level of RHS
unusedInjectiveVarsErr (Pair invis_vars vis_vars) errorBuilder tyfamEqn
  = errorBuilder (injectivityErrorHerald True $$ msg)
                 [tyfamEqn]
    where
      tvs = varSetElemsWellScoped (invis_vars `unionVarSet` vis_vars)
      has_types = not $ isEmptyVarSet vis_vars
      has_kinds = not $ isEmptyVarSet invis_vars

      doc = sep [ what <+> text "variable" <>
                  plural tvs <+> pprQuotedList tvs
                , text "cannot be inferred from the right-hand side." ]
      what = case (has_types, has_kinds) of
               (True, True)   -> text "Type and kind"
               (True, False)  -> text "Type"
               (False, True)  -> text "Kind"
               (False, False) -> pprPanic "mkUnusedInjectiveVarsErr" $ ppr tvs
      print_kinds_info = ppWhen has_kinds ppSuggestExplicitKinds
      msg = doc $$ print_kinds_info $$
            text "In the type family equation:"

-- | Build error message for equation that has a type family call at the top
-- level of RHS