{-# LANGUAGE LambdaCase #-}

{-# 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.Hs.Expr ()   -- instance Outputable
import GHC.Types.Id
import GHC.Types.Name (NameSpace, pprDefinedAt, occNameSpace, pprNameSpace, isValNameSpace, nameModule)
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 Data.List (intersperse)
import qualified Data.List.NonEmpty as NE

instance Outputable GhcHint where
  ppr :: GhcHint -> SDoc
ppr = \case
    UnknownHint a
m
      -> forall a. Outputable a => a -> SDoc
ppr a
m
    SuggestExtension LanguageExtensionHint
extHint
      -> case LanguageExtensionHint
extHint of
          SuggestSingleExtension SDoc
extraUserInfo Extension
ext ->
            (String -> SDoc
text String
"Perhaps you intended to use" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
$$ SDoc
extraUserInfo
          SuggestAnyExtension SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = String -> SDoc
text String
"Enable any of the following extensions:"
            in  SDoc
header SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
hcat (forall a. a -> [a] -> [a]
intersperse (String -> SDoc
text String
", ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) SDoc -> SDoc -> SDoc
$$ SDoc
extraUserInfo
          SuggestExtensions SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = String -> SDoc
text String
"Enable all of the following extensions:"
            in  SDoc
header SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
hcat (forall a. a -> [a] -> [a]
intersperse (String -> SDoc
text String
", ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) SDoc -> SDoc -> SDoc
$$ SDoc
extraUserInfo
          SuggestExtensionInOrderTo SDoc
extraUserInfo Extension
ext ->
            (String -> SDoc
text String
"Use" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
$$ SDoc
extraUserInfo
    SuggestCorrectPragmaName [String]
suggestions
      -> String -> SDoc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
quotedListWithOr (forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
text [String]
suggestions)
    GhcHint
SuggestMissingDo
      -> String -> SDoc
text String
"Possibly caused by a missing 'do'?"
    GhcHint
SuggestLetInDo
      -> String -> SDoc
text String
"Perhaps you need a 'let' in a 'do' block?"
           SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"e.g. 'let x = 5' instead of 'x = 5'"
    SuggestAddSignatureCabalFile ModuleName
pi_mod_name
      -> String -> SDoc
text String
"Try adding" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name)
           SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"to the"
           SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"signatures")
           SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"field in your Cabal file."
    SuggestSignatureInstantiations ModuleName
pi_mod_name [InstantiationSuggestion]
suggestions
      -> let suggested_instantiated_with :: SDoc
suggested_instantiated_with =
               [SDoc] -> SDoc
hcat (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma forall a b. (a -> b) -> a -> b
$
                   [ forall a. Outputable a => a -> SDoc
ppr ModuleName
k SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"=" SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr Module
v
                   | InstantiationSuggestion ModuleName
k Module
v <- [InstantiationSuggestion]
suggestions
                   ])
         in String -> SDoc
text String
"Try passing -instantiated-with=\"" SDoc -> SDoc -> SDoc
<>
              SDoc
suggested_instantiated_with SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"\"" SDoc -> SDoc -> SDoc
$$
                String -> SDoc
text String
"replacing <" SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"> as necessary."
    GhcHint
SuggestUseSpaces
      -> String -> SDoc
text String
"Please use spaces instead."
    SuggestUseWhitespaceAfter OperatorWhitespaceSymbol
sym
      -> String -> SDoc
text String
"Add whitespace after the"
           SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (OperatorWhitespaceSymbol -> SDoc
pprOperatorWhitespaceSymbol OperatorWhitespaceSymbol
sym) SDoc -> SDoc -> SDoc
<> Char -> SDoc
char Char
'.'
    SuggestUseWhitespaceAround String
sym OperatorWhitespaceOccurrence
_occurrence
      -> String -> SDoc
text String
"Add whitespace around" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
sym) SDoc -> SDoc -> SDoc
<> Char -> SDoc
char Char
'.'
    GhcHint
SuggestParentheses
      -> String -> SDoc
text String
"Use parentheses."
    GhcHint
SuggestIncreaseMaxPmCheckModels
      -> String -> SDoc
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
text String
"Add a type signature."
          NamedBindings (Name
x NE.:| [Name]
xs) ->
            let nameList :: SDoc
nameList = case [Name]
xs of
                  [] -> SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr forall a b. (a -> b) -> a -> b
$ Name
x
                  [Name]
_  -> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr) [Name]
xs SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"and" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
x)
            in [SDoc] -> SDoc
hsep [ String -> SDoc
text String
"Consider giving"
                    , SDoc
nameList
                    , String -> SDoc
text String
"a type signature"]
    SuggestBindToWildcard LHsExpr GhcTc
rhs
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Suppress this warning by saying") Int
2 (SDoc -> SDoc
quotes forall a b. (a -> b) -> a -> b
$ String -> SDoc
text String
"_ <-" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
rhs)
    SuggestAddInlineOrNoInlinePragma Var
lhs_id Activation
rule_act
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Add an INLINE[n] or NOINLINE[n] pragma for" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Var
lhs_id)
              , SDoc -> SDoc
whenPprDebug (forall a. Outputable a => a -> SDoc
ppr (Var -> Activation
idInlineActivation Var
lhs_id) SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr Activation
rule_act)
              ]
    SuggestAddPhaseToCompetingRule RuleName
bad_rule
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Add phase [n] or [~n] to the competing rule"
              , SDoc -> SDoc
whenPprDebug (forall a. Outputable a => a -> SDoc
ppr RuleName
bad_rule) ]
    GhcHint
SuggestIncreaseSimplifierIterations
      -> String -> SDoc
text String
"Set limit with -fconstraint-solver-iterations=n; n=0 for no limit"
    SuggestUseTypeFromDataKind Maybe RdrName
mb_rdr_name
      -> String -> SDoc
text String
"Use" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"Type")
         SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"from" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"Data.Kind") SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"instead."
         SDoc -> SDoc -> SDoc
$$
           forall b a. b -> (a -> b) -> Maybe a -> b
maybe SDoc
empty
           (\RdrName
rdr_name ->
             String -> SDoc
text String
"NB: with NoStarIsType, " SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
             SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is treated as a regular type operator.")
           Maybe RdrName
mb_rdr_name

    GhcHint
SuggestQualifiedAfterModuleName
      -> String -> SDoc
text String
"Place" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"qualified")
          SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"after the module name."
    GhcHint
SuggestThQuotationSyntax
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Perhaps you intended to use quotation syntax of TemplateHaskell,"
              , String -> SDoc
text String
"but the type variable or constructor is missing"
              ]
    SuggestRoles [Role]
nearby
      -> case [Role]
nearby of
               []  -> SDoc
empty
               [Role
r] -> String -> SDoc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Role
r)
               -- will this last case ever happen??
               [Role]
_   -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Perhaps you meant one of these:")
                           Int
2 (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr) [Role]
nearby)
    GhcHint
SuggestQualifyStarOperator
      -> String -> SDoc
text String
"To use (or export) this operator in"
            SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"modules with StarIsType,"
         SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"    including the definition module, you must qualify it."
    GhcHint
SuggestTypeSignatureForm
      -> String -> SDoc
text String
"A type signature should be of form <variables> :: <type>"
    SuggestAddToHSigExportList Name
_name Maybe Module
mb_mod
      -> let header :: SDoc
header = String -> SDoc
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
<+> String -> SDoc
text String
"the hsig file."
              Just Module
mod -> SDoc
header SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall unit. GenModule unit -> ModuleName
moduleName Module
mod) SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"'s hsig file."
    GhcHint
SuggestFixOrphanInstance
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Move the instance declaration to the module of the class or of the type, or"
              , String -> SDoc
text String
"wrap the type with a newtype and declare the instance on the new type."
              ]
    GhcHint
SuggestAddStandaloneDerivation
      -> String -> SDoc
text String
"Use a standalone deriving declaration instead"
    GhcHint
SuggestFillInWildcardConstraint
      -> String -> SDoc
text String
"Fill in the wildcard constraint yourself"
    GhcHint
SuggestRenameForall
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Consider using another name, such as"
              , SDoc -> SDoc
quotes (String -> SDoc
text String
"forAll") SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<+>
                SDoc -> SDoc
quotes (String -> SDoc
text String
"for_all") SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"or" SDoc -> SDoc -> SDoc
<+>
                SDoc -> SDoc
quotes (String -> SDoc
text String
"forall_") SDoc -> SDoc -> SDoc
<> SDoc
dot ]
    SuggestAppropriateTHTick NameSpace
ns
      -> String -> SDoc
text String
"Perhaps use a" SDoc -> SDoc -> SDoc
<+> SDoc
how_many SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"tick"
        where
          how_many :: SDoc
how_many
            | NameSpace -> Bool
isValNameSpace NameSpace
ns = String -> SDoc
text String
"single"
            | Bool
otherwise         = String -> SDoc
text String
"double"
    GhcHint
SuggestDumpSlices
      -> [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"If you bound a unique Template Haskell name (NameU)"
              , String -> SDoc
text String
"perhaps via newName,"
              , String -> SDoc
text String
"then -ddump-splices might be useful." ]
    SuggestAddTick (UntickedConstructor LexicalFixity
fixity Name
name)
      -> [SDoc] -> SDoc
hsep [ String -> SDoc
text String
"Use"
              , Char -> SDoc
char Char
'\'' SDoc -> SDoc -> SDoc
<> SDoc
con
              , String -> SDoc
text String
"instead of"
              , SDoc
con SDoc -> SDoc -> SDoc
<> SDoc
mb_dot ]
        where
          con :: SDoc
con = LexicalFixity -> Name -> SDoc
pprUntickedConstructor LexicalFixity
fixity Name
name
          mb_dot :: SDoc
mb_dot
            | LexicalFixity -> Name -> Bool
isBareSymbol LexicalFixity
fixity Name
name
            -- A final dot can be confusing for a symbol without parens, e.g.
            --
            --  * Use ': instead of :.
            = SDoc
empty
            | Bool
otherwise
            = SDoc
dot

    SuggestAddTick UntickedPromotedThing
UntickedExplicitList
      -> String -> SDoc
text String
"Add a promotion tick, e.g." SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"'[x,y,z]" SDoc -> SDoc -> SDoc
<> SDoc
dot
    SuggestMoveToDeclarationSite SDoc
what RdrName
rdr_name
      -> String -> SDoc
text String
"Move the" SDoc -> SDoc -> SDoc
<+> SDoc
what SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"to the declaration site of"
         SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
<> SDoc
dot
    SuggestSimilarNames RdrName
tried_rdr_name NonEmpty SimilarName
similar_names
      -> case NonEmpty SimilarName
similar_names of
            SimilarName
n NE.:| [] -> String -> SDoc
text String
"Perhaps use" SDoc -> SDoc -> SDoc
<+> SimilarName -> SDoc
pp_item SimilarName
n
            NonEmpty SimilarName
_          -> [SDoc] -> SDoc
sep [ String -> SDoc
text String
"Perhaps use one of these:"
                              , Int -> SDoc -> SDoc
nest Int
2 (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SimilarName -> SDoc
pp_item forall a b. (a -> b) -> a -> b
$ forall a. NonEmpty a -> [a]
NE.toList NonEmpty SimilarName
similar_names) ]
        where
          tried_ns :: NameSpace
tried_ns = OccName -> NameSpace
occNameSpace 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
text String
"Notice that" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
         SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is a field selector" SDoc -> SDoc -> SDoc
<+> SDoc
whose
         SDoc -> SDoc -> SDoc
$$ String -> SDoc
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 | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
parents = SDoc
empty
              | Bool
otherwise    = String -> SDoc
text String
"belonging to the type" SDoc -> SDoc -> SDoc
<> forall a. [a] -> SDoc
plural [Name]
parents
                                 SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => [a] -> SDoc
pprQuotedList [Name]
parents
    ImportSuggestion ImportSuggestion
import_suggestion
      -> ImportSuggestion -> SDoc
pprImportSuggestion ImportSuggestion
import_suggestion
    GhcHint
SuggestImportingDataCon
      -> String -> SDoc
text String
"Import the data constructor to bring it into scope"
    GhcHint
SuggestPlacePragmaInHeader
      -> String -> SDoc
text String
"Perhaps you meant to place it in the module header?"
      SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"The module header is the section at the top of the file, before the" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"module") SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"keyword"
    GhcHint
SuggestPatternMatchingSyntax
      -> String -> SDoc
text String
"Use pattern-matching syntax instead"
    SuggestSpecialiseVisibilityHints Name
name
      -> String -> SDoc
text String
"Make sure" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is compiled with -O and that"
           SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"has an INLINABLE pragma"
         where
           mod :: Module
mod = HasDebugCallStack => Name -> Module
nameModule Name
name

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

-- | Pretty-print an 'ImportSuggestion'.
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion (CouldImportFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
fsep
      [ String -> SDoc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
text String
"to the import list"
      , String -> SDoc
text String
"in the import of"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
<> SDoc
dot
      ]
  | Bool
otherwise
  = [SDoc] -> SDoc
fsep
      [ String -> SDoc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
text String
"to one of these import lists:"
      ]
    SDoc -> SDoc -> SDoc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
vcat
        [ SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])
pprImportSuggestion (CouldUnhideFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
fsep
      [ String -> SDoc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
text String
"from the explicit hiding list"
      , String -> SDoc
text String
"in the import of"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
<> SDoc
dot
      ]
  | Bool
otherwise
  = [SDoc] -> SDoc
fsep
      [ String -> SDoc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
text String
"from the hiding clauses"
      , String -> SDoc
text String
"in one of these imports:"
      ]
    SDoc -> SDoc -> SDoc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
vcat
        [ SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])

-- | Pretty-print a 'SimilarName'.
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
_ (SimilarName Name
name)
  = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (Name -> SDoc
pprDefinedAt Name
name)
pprSimilarName NameSpace
tried_ns (SimilarRdrName RdrName
rdr_name HowInScope
how_in_scope)
  = case HowInScope
how_in_scope of
      LocallyBoundAt SrcSpan
loc ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
<+> SDoc
loc'
          where
            loc' :: SDoc
loc' = case SrcSpan
loc of
              UnhelpfulSpan UnhelpfulSpanReason
l -> SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr UnhelpfulSpanReason
l)
              RealSrcSpan RealSrcSpan
l Maybe BufSpan
_ -> SDoc -> SDoc
parens (String -> SDoc
text String
"line" SDoc -> SDoc -> SDoc
<+> Int -> SDoc
int (RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
l))
      ImportedBy ImpDeclSpec
is ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
<+>
        SDoc -> SDoc
parens (String -> SDoc
text String
"imported from" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ImpDeclSpec -> ModuleName
is_mod ImpDeclSpec
is))

  where
    pp_ns :: RdrName -> SDoc
    pp_ns :: RdrName -> SDoc
pp_ns RdrName
rdr | NameSpace
ns forall a. Eq a => a -> a -> Bool
/= NameSpace
tried_ns = NameSpace -> SDoc
pprNameSpace NameSpace
ns
              | Bool
otherwise      = SDoc
empty
      where ns :: NameSpace
ns = RdrName -> NameSpace
rdrNameSpace RdrName
rdr