summaryrefslogtreecommitdiff
path: root/compiler/rename
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2014-05-02 12:09:52 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2014-05-05 09:12:15 +0100
commit9f3e39d5f8686e511ffca406a6e056dec4095e53 (patch)
tree6f8330a048ed9352f049ef8be341d83f1902630f /compiler/rename
parentf0fcc41d755876a1b02d1c7c79f57515059f6417 (diff)
downloadhaskell-9f3e39d5f8686e511ffca406a6e056dec4095e53.tar.gz
Fix over-zealous unused-import warning
See Note [Un-warnable import decls] in RnNames. Fixes Trac #9061.
Diffstat (limited to 'compiler/rename')
-rw-r--r--compiler/rename/RnNames.lhs24
1 files changed, 20 insertions, 4 deletions
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index 7f6a840295..678eb73395 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -1301,7 +1301,7 @@ type ImportDeclUsage
warnUnusedImportDecls :: TcGblEnv -> RnM ()
warnUnusedImportDecls gbl_env
= do { uses <- readMutVar (tcg_used_rdrnames gbl_env)
- ; let imports = filter explicit_import (tcg_rn_imports gbl_env)
+ ; let imports = filterOut un_warnable_import (tcg_rn_imports gbl_env)
rdr_env = tcg_rdr_env gbl_env
; let usage :: [ImportDeclUsage]
@@ -1315,11 +1315,27 @@ warnUnusedImportDecls gbl_env
; whenGOptM Opt_D_dump_minimal_imports $
printMinimalImports usage }
where
- explicit_import (L _ decl) = not (ideclImplicit decl)
- -- Filter out the implicit Prelude import
- -- which we do not want to bleat about
+ un_warnable_import (L _ decl) -- See Note [Un-warnable import decls]
+ | ideclImplicit decl
+ = True
+ | Just (True, hides) <- ideclHiding decl
+ , not (null hides)
+ , pRELUDE_NAME == unLoc (ideclName decl)
+ = True
+ | otherwise
+ = False
\end{code}
+Note [Un-warnable import decls]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+We do not warn about the implicit import of Prelude, since the user can't remove it
+
+We do not warn about
+ import Prelude hiding( x, y )
+because even if nothing else from Prelude is used, it may be essential to hide
+x,y to avoid name-shadowing warnings. Example (Trac #9061)
+ import Prelude hiding( log )
+ f x = log where log = ()
Note [The ImportMap]
~~~~~~~~~~~~~~~~~~~~