= rhs_uses `unionNameSets` uses
get (Just defs, rhs_uses) uses
| defs `intersectsNameSet` uses -- Used
- || not (all (reportIfUnused . nameOccName) (nameSetToList defs))
+ || any (startsWithUnderscore . nameOccName) (nameSetToList defs)
-- At least one starts with an "_",
-- so treat the group as used
= rhs_uses `unionNameSets` uses
occNameFS, occNameString, occNameSpace,
isVarOcc, isTvOcc, isTcOcc, isDataOcc, isDataSymOcc, isSymOcc, isValOcc,
- parenSymOcc, reportIfUnused,
+ parenSymOcc, startsWithUnderscore,
isTcClsNameSpace, isTvNameSpace, isDataConNameSpace, isVarNameSpace, isValNameSpace,
\begin{code}
-reportIfUnused :: OccName -> Bool
--- ^ Haskell 98 encourages compilers to suppress warnings about
--- unused names in a pattern if they start with @_@: this implements
--- that test
-reportIfUnused occ = case occNameString occ of
- ('_' : _) -> False
- _other -> True
+startsWithUnderscore :: OccName -> Bool
+-- ^ Haskell 98 encourages compilers to suppress warnings about unsed
+-- names in a pattern if they start with @_@: this implements that test
+startsWithUnderscore occ = case occNameString occ of
+ ('_' : _) -> True
+ _other -> False
\end{code}
; mappM_ check_shadow loc_rdr_names }
where
check_shadow (loc, occ)
+ | startsWithUnderscore occ = return () -- Do not report shadowing for "_x"
+ -- See Trac #3262
| Just n <- mb_local = complain [ptext (sLit "bound at") <+> ppr (nameSrcLoc n)]
| otherwise = do { gres' <- filterM is_shadowed_gre gres
; complain (map pprNameProvenance gres') }
| isWiredInName name = False -- Don't report unused wired-in names
-- Otherwise we get a zillion warnings
-- from Data.Tuple
- | otherwise = reportIfUnused (nameOccName name)
+ | otherwise = not (startsWithUnderscore (nameOccName name))
-------------------------
(Nothing, NoDefMeth) -> do -- No default method in the class
{ warn <- doptM Opt_WarnMissingMethods
; warnTc (warn -- Warn only if -fwarn-missing-methods
- && reportIfUnused (getOccName sel_id))
+ && not (startsWithUnderscore (getOccName sel_id)))
-- Don't warn about _foo methods
omitted_meth_warn
; return (error_rhs, emptyBag) }
typographical errors that turn into hard-to-find bugs, e.g.,
in the inadvertent capture of what would be a recursive call in
<literal>f = ... let f = id in ... f ...</literal>.</para>
+ <para>The warning is suppressed for names beginning with an underscore. For example
+ <programlisting>
+ f x = do { _ignore <- this; _ignore <- that; return (the other) }
+ </programlisting>
+ </para>
</listitem>
</varlistentry>