summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-07-21 17:42:01 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-07-21 17:42:01 +0100
commit4666be5d9471b8227f5e24c0b7860e84923489db (patch)
treea78c4634802c556935eb2e49830f3d6a73ffb231
parenta0ba88bef62af0e7f91720ac6ad71850078fd718 (diff)
downloadhaskell-4666be5d9471b8227f5e24c0b7860e84923489db.tar.gz
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
-rw-r--r--compiler/rename/RnBinds.lhs13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.lhs
index 65df7ba196..75c49437c0 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) }