{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

{-# OPTIONS_GHC -Wno-orphans #-}   {- instance Outputable GhcHint -}

module GHC.Types.Hint.Ppr (
  perhapsAsPat
  -- also, and more interesting: instance Outputable GhcHint
  ) where

import GHC.Prelude

import GHC.Parser.Errors.Basic
import GHC.Types.Hint

import GHC.Core.FamInstEnv (FamFlavor(..))
import GHC.Core.TyCon
import GHC.Core.TyCo.Rep     ( mkVisFunTyMany )
import GHC.Hs.Expr ()   -- instance Outputable
import GHC.Types.Id
import GHC.Types.Name
import GHC.Types.Name.Reader (RdrName,ImpDeclSpec (..), rdrNameOcc, rdrNameSpace)
import GHC.Types.SrcLoc (SrcSpan(..), srcSpanStartLine)
import GHC.Unit.Module.Imported (ImportedModsVal(..))
import GHC.Unit.Types
import GHC.Utils.Outputable

import GHC.Driver.Flags

import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map

import qualified GHC.LanguageExtensions as LangExt

instance Outputable GhcHint where
  ppr :: GhcHint -> SDoc
ppr = \case
    UnknownHint a
m
      -> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
m
    SuggestExtension LanguageExtensionHint
extHint
      -> case LanguageExtensionHint
extHint of
          SuggestSingleExtension SDoc
extraUserInfo Extension
ext ->
            (SDoc
"Perhaps you intended to use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
extension_with_implied Extension
ext)
            SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestAnyExtension SDoc
extraUserInfo [Extension]
exts ->
            (SDoc -> SDoc
forall {doc}. (IsLine doc, IsString doc) => doc -> doc
enable SDoc
"any" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> [SDoc] -> SDoc
unquotedListWith SDoc
"or" ((Extension -> SDoc) -> [Extension] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Extension -> SDoc
implied [Extension]
exts))
            SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensions SDoc
extraUserInfo [Extension]
exts ->
            (SDoc -> SDoc
forall {doc}. (IsLine doc, IsString doc) => doc -> doc
enable SDoc
"all" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> [SDoc] -> SDoc
unquotedListWith SDoc
"and" ((Extension -> SDoc) -> [Extension] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Extension -> SDoc
implied [Extension]
exts))
            SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensionInOrderTo SDoc
extraUserInfo Extension
ext ->
            (SDoc
"Use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
extension_with_implied Extension
ext)
            SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
      where extension_with_implied :: Extension -> SDoc
extension_with_implied Extension
ext = SDoc
"the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
"extension" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
pprImpliedExtensions Extension
ext
            implied :: Extension -> SDoc
implied Extension
ext = SDoc -> SDoc
quotes (Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
pprImpliedExtensions Extension
ext
            enable :: doc -> doc
enable doc
any_or_all = doc
"Enable" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> doc
any_or_all doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> doc
"of the following extensions" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
colon
    SuggestCorrectPragmaName [String]
suggestions
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
quotedListWithOr ((String -> SDoc) -> [String] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
forall doc. IsLine doc => String -> doc
text [String]
suggestions)
    GhcHint
SuggestMissingDo
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Possibly caused by a missing 'do'?"
    GhcHint
SuggestLetInDo
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you need a 'let' in a 'do' block?"
           SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"e.g. 'let x = 5' instead of 'x = 5'"
    SuggestAddSignatureCabalFile ModuleName
pi_mod_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try adding" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name)
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"signatures")
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"field in your Cabal file."
    SuggestSignatureInstantiations ModuleName
pi_mod_name [InstantiationSuggestion]
suggestions
      -> let suggested_instantiated_with :: SDoc
suggested_instantiated_with =
               [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat (SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
comma ([SDoc] -> [SDoc]) -> [SDoc] -> [SDoc]
forall a b. (a -> b) -> a -> b
$
                   [ ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
k SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
v
                   | InstantiationSuggestion ModuleName
k Module
v <- [InstantiationSuggestion]
suggestions
                   ])
         in String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try passing -instantiated-with=\"" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<>
              SDoc
suggested_instantiated_with SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\"" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
                String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"replacing <" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"> as necessary."
    GhcHint
SuggestUseSpaces
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Please use spaces instead."
    SuggestUseWhitespaceAfter OperatorWhitespaceSymbol
sym
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add whitespace after the"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OperatorWhitespaceSymbol -> SDoc
pprOperatorWhitespaceSymbol OperatorWhitespaceSymbol
sym) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'.'
    SuggestUseWhitespaceAround String
sym OperatorWhitespaceOccurrence
_occurrence
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add whitespace around" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
sym) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'.'
    GhcHint
SuggestParentheses
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use parentheses."
    GhcHint
SuggestIncreaseMaxPmCheckModels
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Increase the limit or resolve the warnings to suppress this message."
    SuggestAddTypeSignatures AvailableBindings
bindings
      -> case AvailableBindings
bindings of
          -- This might happen when we have bindings which are /too complicated/,
          -- see for example 'DsCannotMixPolyAndUnliftedBindings' in 'GHC.HsToCore.Errors.Types'.
          -- In this case, we emit a generic message.
          AvailableBindings
UnnamedBinding   -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a type signature."
          NamedBindings (Name
x NE.:| [Name]
xs) ->
            let nameList :: SDoc
nameList = case [Name]
xs of
                  [] -> SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Name -> SDoc) -> Name -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> Name -> SDoc
forall a b. (a -> b) -> a -> b
$ Name
x
                  [Name]
_  -> (Name -> SDoc) -> [Name] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Name -> SDoc) -> Name -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr) [Name]
xs SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"and" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
x)
            in [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider giving"
                    , SDoc
nameList
                    , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"a type signature"]
    SuggestBindToWildcard LHsExpr GhcTc
rhs
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Suppress this warning by saying") Int
2 (SDoc -> SDoc
quotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"_ <-" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsExpr GhcTc) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
rhs)
    SuggestAddInlineOrNoInlinePragma Var
lhs_id Activation
rule_act
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add an INLINE[n] or NOINLINE[n] pragma for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
lhs_id)
              , SDoc -> SDoc
forall doc. IsOutput doc => doc -> doc
whenPprDebug (Activation -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Var -> Activation
idInlineActivation Var
lhs_id) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Activation -> SDoc
forall a. Outputable a => a -> SDoc
ppr Activation
rule_act)
              ]
    SuggestAddPhaseToCompetingRule RuleName
bad_rule
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add phase [n] or [~n] to the competing rule"
              , SDoc -> SDoc
forall doc. IsOutput doc => doc -> doc
whenPprDebug (RuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RuleName
bad_rule) ]
    GhcHint
SuggestIncreaseSimplifierIterations
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Set limit with -fconstraint-solver-iterations=n; n=0 for no limit"
    SuggestUseTypeFromDataKind Maybe RdrName
mb_rdr_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Type")
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Data.Kind") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instead."
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
           SDoc -> (RdrName -> SDoc) -> Maybe RdrName -> SDoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SDoc
forall doc. IsOutput doc => doc
empty
           (\RdrName
rdr_name ->
             String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NB: with NoStarIsType, " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is treated as a regular type operator.")
           Maybe RdrName
mb_rdr_name

    GhcHint
SuggestQualifiedAfterModuleName
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Place" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"qualified")
          SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"after the module name."
    GhcHint
SuggestThQuotationSyntax
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you intended to use quotation syntax of TemplateHaskell,"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but the type variable or constructor is missing"
              ]
    SuggestRoles [Role]
nearby
      -> case [Role]
nearby of
               []  -> SDoc
forall doc. IsOutput doc => doc
empty
               [Role
r] -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Role -> SDoc
forall a. Outputable a => a -> SDoc
ppr Role
r)
               -- will this last case ever happen??
               [Role]
_   -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant one of these:")
                           Int
2 ((Role -> SDoc) -> [Role] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Role -> SDoc) -> Role -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Role -> SDoc
forall a. Outputable a => a -> SDoc
ppr) [Role]
nearby)
    GhcHint
SuggestQualifyStarOperator
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"To use (or export) this operator in"
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"modules with StarIsType,"
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"    including the definition module, you must qualify it."
    GhcHint
SuggestTypeSignatureRemoveQualifier
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant to omit the qualifier"
    SuggestAddToHSigExportList Name
_name Maybe Module
mb_mod
      -> let header :: SDoc
header = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try adding it to the export list of"
         in case Maybe Module
mb_mod of
              Maybe Module
Nothing -> SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"the hsig file."
              Just Module
mod -> SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"'s hsig file."
    SuggestFixOrphanInst { isFamilyInstance :: GhcHint -> Maybe FamFlavor
isFamilyInstance = Maybe FamFlavor
mbFamFlavor }
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move the instance declaration to the module of the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or of the type, or"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wrap the type with a newtype and declare the instance on the new type."
              ]
      where
        what :: SDoc
what = case Maybe FamFlavor
mbFamFlavor of
          Maybe FamFlavor
Nothing                  -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"class"
          Just  FamFlavor
SynFamilyInst      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type family"
          Just (DataFamilyInst {}) -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"data family"
    GhcHint
SuggestAddStandaloneDerivation
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use a standalone deriving declaration instead"
    SuggestAddStandaloneKindSignature Name
name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a standalone kind signature for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
    GhcHint
SuggestFillInWildcardConstraint
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Fill in the wildcard constraint yourself"
    SuggestAppropriateTHTick NameSpace
ns
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use a" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
how_many SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tick"
        where
          how_many :: SDoc
how_many
            | NameSpace -> TurnOnFlag
isValNameSpace NameSpace
ns = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"single"
            | TurnOnFlag
otherwise         = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"double"
    GhcHint
SuggestDumpSlices
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"If you bound a unique Template Haskell name (NameU)"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"perhaps via newName,"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"then -ddump-splices might be useful." ]
    SuggestAddTick (UntickedConstructor LexicalFixity
fixity Name
name)
      -> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use"
              , Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'\'' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
con
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instead of"
              , SDoc
con SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
mb_dot ]
        where
          con :: SDoc
con = LexicalFixity -> Name -> SDoc
pprUntickedConstructor LexicalFixity
fixity Name
name
          mb_dot :: SDoc
mb_dot
            | LexicalFixity -> Name -> TurnOnFlag
isBareSymbol LexicalFixity
fixity Name
name
            -- A final dot can be confusing for a symbol without parens, e.g.
            --
            --  * Use ': instead of :.
            = SDoc
forall doc. IsOutput doc => doc
empty
            | TurnOnFlag
otherwise
            = SDoc
forall doc. IsLine doc => doc
dot

    SuggestAddTick UntickedPromotedThing
UntickedExplicitList
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a promotion tick, e.g." SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"'[x,y,z]" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
    SuggestMoveToDeclarationSite SDoc
what RdrName
rdr_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the declaration site of"
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
    SuggestSimilarNames RdrName
tried_rdr_name NonEmpty SimilarName
similar_names
      -> case NonEmpty SimilarName
similar_names of
            SimilarName
n NE.:| [] -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SimilarName -> SDoc
pp_item SimilarName
n
            NonEmpty SimilarName
_          -> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use one of these:"
                              , Int -> SDoc -> SDoc
nest Int
2 ((SimilarName -> SDoc) -> [SimilarName] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SimilarName -> SDoc
pp_item ([SimilarName] -> SDoc) -> [SimilarName] -> SDoc
forall a b. (a -> b) -> a -> b
$ NonEmpty SimilarName -> [SimilarName]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty SimilarName
similar_names) ]
        where
          tried_ns :: NameSpace
tried_ns = OccName -> NameSpace
occNameSpace (OccName -> NameSpace) -> OccName -> NameSpace
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc RdrName
tried_rdr_name
          pp_item :: SimilarName -> SDoc
pp_item = NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
tried_ns
    RemindFieldSelectorSuppressed RdrName
rdr_name [Name]
parents
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Notice that" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is a field selector" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
whose
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"that has been suppressed by NoFieldSelectors."
      where
        -- parents may be empty if this is a pattern synonym field without a selector
        whose :: SDoc
whose | [Name] -> TurnOnFlag
forall a. [a] -> TurnOnFlag
forall (t :: * -> *) a. Foldable t => t a -> TurnOnFlag
null [Name]
parents = SDoc
forall doc. IsOutput doc => doc
empty
              | TurnOnFlag
otherwise    = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"belonging to the type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> [Name] -> SDoc
forall a. [a] -> SDoc
plural [Name]
parents
                                 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Name] -> SDoc
forall a. Outputable a => [a] -> SDoc
pprQuotedList [Name]
parents
    ImportSuggestion OccName
occ_name ImportSuggestion
import_suggestion
      -> OccName -> ImportSuggestion -> SDoc
pprImportSuggestion OccName
occ_name ImportSuggestion
import_suggestion
    GhcHint
SuggestPlacePragmaInHeader
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant to place it in the module header?"
      SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The module header is the section at the top of the file, before the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"keyword"
    GhcHint
SuggestPatternMatchingSyntax
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use pattern-matching syntax instead"
    SuggestSpecialiseVisibilityHints Name
name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Make sure" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is compiled with -O and that"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"has an INLINABLE pragma"
         where
           mod :: Module
mod = HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
name
    GhcHint
SuggestRenameTypeVariable
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider renaming the type variable."
    SuggestExplicitBidiPatSyn Name
name LPat GhcRn
pat [LIdP GhcRn]
args
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Instead use an explicitly bidirectional"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern synonym, e.g.")
            Int
2 (SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_args SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
larrow
                     SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (Pat GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
pat SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where")
                  Int
2 (SDoc
pp_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_args SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
forall doc. IsLine doc => doc
equals SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"..."))
         where
           pp_name :: SDoc
pp_name = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
           pp_args :: SDoc
pp_args = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated SrcSpanAnnN Name -> SDoc)
-> [GenLocated SrcSpanAnnN Name] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
args)
    GhcHint
SuggestSafeHaskell
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Enable Safe Haskell through either Safe, Trustworthy or Unsafe."
    GhcHint
SuggestRemoveRecordWildcard
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Omit the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"..")
    GhcHint
SuggestIncreaseReductionDepth ->
      [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use -freduction-depth=0 to disable this check"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(any upper bound you could choose might fail unpredictably with"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" minor updates to GHC, so disabling the check is recommended if"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" you're sure that type checking should terminate)" ]
    SuggestMoveNonCanonicalDefinition Name
lhs Name
rhs String
refURL ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move definition from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
rhs) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"See also:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
refURL
    SuggestRemoveNonCanonicalDefinition Name
lhs Name
rhs String
refURL ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Either remove definition for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(recommended)" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or define as" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> SDoc
pprPrefixUnqual Name
rhs) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"See also:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
refURL
    SuggestEtaReduceAbsDataTySyn TyCon
tc
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"If possible, eta-reduce the type synonym" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_tc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"so that it is nullary."
        where ppr_tc :: SDoc
ppr_tc = SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> Name -> SDoc
forall a b. (a -> b) -> a -> b
$ TyCon -> Name
tyConName TyCon
tc)
    RemindRecordMissingField RuleName
x Type
r Type
a ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NB: There is no field selector" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_sel
        SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in scope for record type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_r
      where ppr_sel :: SDoc
ppr_sel = SDoc -> SDoc
quotes (RuleName -> SDoc
forall doc. IsLine doc => RuleName -> doc
ftext RuleName
x SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_arr_r_a)
            ppr_arr_r_a :: SDoc
ppr_arr_r_a = Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Type -> SDoc) -> Type -> SDoc
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => Type -> Type -> Type
Type -> Type -> Type
mkVisFunTyMany Type
r Type
a
            ppr_r :: SDoc
ppr_r = SDoc -> SDoc
quotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
r
    SuggestBindTyVarOnLhs RdrName
tv
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Bind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
tv) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"on the LHS of the type declaration"
    GhcHint
SuggestAnonymousWildcard
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use an anonymous wildcard" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"_")
    SuggestExplicitQuantification RdrName
tv
      -> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use an explicit", SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"forall")
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to quantify over", SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
tv) ]
    SuggestBindTyVarExplicitly Name
tv
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tv)
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"explicitly with" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'@' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tv)
    SuggestDefaultDeclaration TyCon
cls [Type]
tys
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider declaring")
            Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"default" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
cls SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens ((Type -> SDoc) -> [Type] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
tys))
    SuggestExplicitDerivingClauseStrategies Map AssumedDerivingStrategy [LHsSigType GhcRn]
assumed_derivings ->
      SDoc -> Int -> SDoc -> SDoc
hang
        (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use explicit deriving strategies:")
        Int
2
        ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ ((AssumedDerivingStrategy,
  [GenLocated SrcSpanAnnA (HsSigType GhcRn)])
 -> SDoc)
-> [(AssumedDerivingStrategy,
     [GenLocated SrcSpanAnnA (HsSigType GhcRn)])]
-> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (AssumedDerivingStrategy,
 [GenLocated SrcSpanAnnA (HsSigType GhcRn)])
-> SDoc
forall {a} {a}. (Outputable a, Outputable a) => (a, [a]) -> SDoc
pp_derivings (Map
  AssumedDerivingStrategy [GenLocated SrcSpanAnnA (HsSigType GhcRn)]
-> [(AssumedDerivingStrategy,
     [GenLocated SrcSpanAnnA (HsSigType GhcRn)])]
forall k a. Map k a -> [(k, a)]
Map.toList Map AssumedDerivingStrategy [LHsSigType GhcRn]
Map
  AssumedDerivingStrategy [GenLocated SrcSpanAnnA (HsSigType GhcRn)]
assumed_derivings))
      where
        pp_derivings :: (a, [a]) -> SDoc
pp_derivings (a
strat, [a]
preds) =
          [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"deriving", a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
strat, SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens ((a -> SDoc) -> [a] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas a -> SDoc
forall a. Outputable a => a -> SDoc
ppr [a]
preds)]
    SuggestExplicitStandaloneDerivingStrategy AssumedDerivingStrategy
strat LHsSigWcType GhcRn
deriv_sig ->
      SDoc -> Int -> SDoc -> SDoc
hang
        (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use an explicit deriving strategy:")
        Int
2
        ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"deriving", AssumedDerivingStrategy -> SDoc
forall a. Outputable a => a -> SDoc
ppr AssumedDerivingStrategy
strat, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instance", HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigWcType GhcRn
HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
deriv_sig])
    GhcHint
SuggestParenthesizePatternRHS
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Parenthesize the RHS of the view pattern"

perhapsAsPat :: SDoc
perhapsAsPat :: SDoc
perhapsAsPat = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant an as-pattern, which must not be surrounded by whitespace"

-- | Pretty-print an 'ImportSuggestion'.
pprImportSuggestion :: OccName -> ImportSuggestion -> SDoc
pprImportSuggestion :: OccName -> ImportSuggestion -> SDoc
pprImportSuggestion OccName
occ_name (CouldImportFrom NonEmpty (Module, ImportedModsVal)
mods)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the import list"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
      ]
  | TurnOnFlag
otherwise
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to one of these import lists:"
      ]
    SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- NonEmpty (Module, ImportedModsVal) -> [(Module, ImportedModsVal)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])
pprImportSuggestion OccName
occ_name (CouldUnhideFrom NonEmpty (Module, ImportedModsVal)
mods)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Remove"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from the explicit hiding list"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
      ]
  | TurnOnFlag
otherwise
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Remove"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from the hiding clauses"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in one of these imports:"
      ]
    SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- NonEmpty (Module, ImportedModsVal) -> [(Module, ImportedModsVal)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])
pprImportSuggestion OccName
occ_name (CouldAddTypeKeyword ModuleName
mod)
  = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type")
          SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"keyword to the import statement:"
         , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
occ_name)
         ]
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)
pprImportSuggestion OccName
occ_name (CouldRemoveTypeKeyword ModuleName
mod)
  = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Remove the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type")
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"keyword from the import statement:"
         , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
occ_name) ]
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)
pprImportSuggestion OccName
dc_occ (ImportDataCon Maybe (ModuleName, TurnOnFlag)
Nothing OccName
parent_occ)
  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Import the data constructor" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
dc_occ) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
    String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"of" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
parent_occ)
pprImportSuggestion OccName
dc_occ (ImportDataCon (Just (ModuleName
mod, TurnOnFlag
patsyns_enabled)) OccName
parent_occ)
  = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use"
           , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
parent_occ SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
dc_occ))
           , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or"
           , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
parent_occ SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(..)")
           ] [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ if TurnOnFlag
patsyns_enabled
                then [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or"
                     , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
                         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
                         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
dc_occ)
                     ]
                else []
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)

-- | Pretty-print a 'SimilarName'.
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
_ (SimilarName Name
name)
  = SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (Name -> SDoc
pprDefinedAt Name
name)
pprSimilarName NameSpace
tried_ns (SimilarRdrName RdrName
rdr_name Maybe HowInScope
how_in_scope)
  = RdrName -> SDoc
pp_ns RdrName
rdr_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
loc
  where
    loc :: SDoc
loc = case Maybe HowInScope
how_in_scope of
      Maybe HowInScope
Nothing -> SDoc
forall doc. IsOutput doc => doc
empty
      Just HowInScope
scope -> case HowInScope
scope of
        LocallyBoundAt SrcSpan
loc ->
          case SrcSpan
loc of
            UnhelpfulSpan UnhelpfulSpanReason
l -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (UnhelpfulSpanReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnhelpfulSpanReason
l)
            RealSrcSpan RealSrcSpan
l Maybe BufSpan
_ -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"line" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
l))
        ImportedBy ImpDeclSpec
is ->
          SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"imported from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName (Module -> ModuleName) -> Module -> ModuleName
forall a b. (a -> b) -> a -> b
$ ImpDeclSpec -> Module
is_mod ImpDeclSpec
is))
    pp_ns :: RdrName -> SDoc
    pp_ns :: RdrName -> SDoc
pp_ns RdrName
rdr | NameSpace
ns NameSpace -> NameSpace -> TurnOnFlag
forall a. Eq a => a -> a -> TurnOnFlag
/= NameSpace
tried_ns = NameSpace -> SDoc
pprNameSpace NameSpace
ns
              | TurnOnFlag
otherwise      = SDoc
forall doc. IsOutput doc => doc
empty
      where ns :: NameSpace
ns = RdrName -> NameSpace
rdrNameSpace RdrName
rdr

pprImpliedExtensions :: LangExt.Extension -> SDoc
pprImpliedExtensions :: Extension -> SDoc
pprImpliedExtensions Extension
extension = case [SDoc]
implied of
    [] -> SDoc
forall doc. IsOutput doc => doc
empty
    [SDoc]
xs -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ SDoc
"implied by" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> [SDoc] -> SDoc
unquotedListWith SDoc
"and" [SDoc]
xs
  where implied :: [SDoc]
implied = (Extension -> SDoc) -> [Extension] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Extension -> SDoc) -> Extension -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr)
                ([Extension] -> [SDoc])
-> ([(Extension, TurnOnFlag, Extension)] -> [Extension])
-> [(Extension, TurnOnFlag, Extension)]
-> [SDoc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Extension -> TurnOnFlag) -> [Extension] -> [Extension]
forall a. (a -> TurnOnFlag) -> [a] -> [a]
filter (\Extension
ext -> Extension -> ExtensionDeprecation
extensionDeprecation Extension
ext ExtensionDeprecation -> ExtensionDeprecation -> TurnOnFlag
forall a. Eq a => a -> a -> TurnOnFlag
== ExtensionDeprecation
ExtensionNotDeprecated)
                ([Extension] -> [Extension])
-> ([(Extension, TurnOnFlag, Extension)] -> [Extension])
-> [(Extension, TurnOnFlag, Extension)]
-> [Extension]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Extension, TurnOnFlag, Extension) -> Extension)
-> [(Extension, TurnOnFlag, Extension)] -> [Extension]
forall a b. (a -> b) -> [a] -> [b]
map (\(Extension
impl, TurnOnFlag
_, Extension
_) -> Extension
impl)
                ([(Extension, TurnOnFlag, Extension)] -> [Extension])
-> ([(Extension, TurnOnFlag, Extension)]
    -> [(Extension, TurnOnFlag, Extension)])
-> [(Extension, TurnOnFlag, Extension)]
-> [Extension]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Extension, TurnOnFlag, Extension) -> TurnOnFlag)
-> [(Extension, TurnOnFlag, Extension)]
-> [(Extension, TurnOnFlag, Extension)]
forall a. (a -> TurnOnFlag) -> [a] -> [a]
filter (\(Extension
_, TurnOnFlag
t, Extension
orig) -> Extension
orig Extension -> Extension -> TurnOnFlag
forall a. Eq a => a -> a -> TurnOnFlag
== Extension
extension TurnOnFlag -> TurnOnFlag -> TurnOnFlag
&& TurnOnFlag
t TurnOnFlag -> TurnOnFlag -> TurnOnFlag
forall a. Eq a => a -> a -> TurnOnFlag
== TurnOnFlag
turnOn)
                ([(Extension, TurnOnFlag, Extension)] -> [SDoc])
-> [(Extension, TurnOnFlag, Extension)] -> [SDoc]
forall a b. (a -> b) -> a -> b
$ [(Extension, TurnOnFlag, Extension)]
impliedXFlags

pprPrefixUnqual :: Name -> SDoc
pprPrefixUnqual :: Name -> SDoc
pprPrefixUnqual Name
name =
  OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName Name
name)