[commit: ghc] master: Don't report unused bindings of the form (4666be5)
Simon Peyton Jones
simonpj at microsoft.com
Sat Jul 21 18:47:46 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/4666be5d9471b8227f5e24c0b7860e84923489db
>---------------------------------------------------------------
commit 4666be5d9471b8227f5e24c0b7860e84923489db
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Sat Jul 21 17:42:01 2012 +0100
Don't report unused bindings of the form
_ = e
Thse are used in a few libraries, either to add type constraints
via a signature, or to mention some variables that are only
otherwise mentioned in one #ifdef branch
>---------------------------------------------------------------
compiler/rename/RnBinds.lhs | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.lhs
index 65df7ba..75c4943 100644
--- a/compiler/rename/RnBinds.lhs
+++ b/compiler/rename/RnBinds.lhs
@@ -454,9 +454,18 @@ rnBind _ (L loc bind@(PatBind { pat_lhs = pat
-- MonoLocalBinds test in TcBinds.decideGeneralisationPlan
bndrs = collectPatBinders pat
bind' = bind { pat_rhs = grhss', bind_fvs = fvs' }
-
+ is_wild_pat = case pat of
+ L _ (WildPat {}) -> True
+ _ -> False
+
+ -- Warn if the pattern binds no variables, except for the
+ -- entirely-explicit idiom _ = rhs
+ -- which (a) is not that different from _v = rhs
+ -- (b) is sometimes used to give a type sig for,
+ -- or an occurrence of, a variable on the RHS
; ifWOptM Opt_WarnUnusedBinds $
- when (null bndrs) (addWarn $ unusedPatBindWarn bind')
+ when (null bndrs && not is_wild_pat) $
+ addWarn $ unusedPatBindWarn bind'
; fvs' `seq` -- See Note [Free-variable space leak]
return (L loc bind', bndrs, all_fvs) }
More information about the Cvs-ghc
mailing list