- unused = explicit_avail_names `minusNameSet` slurped_names
- (local_unused, imported_unused) = partition isLocallyDefined (nameSetToList unused)
- imports_by_module = equivClasses cmp imported_unused
- name1 `cmp` name2 = nameModule name1 `_CMP_STRING_` nameModule name2
-
- pp_imp sty = sep [text "For information: the following unqualified imports are unused:",
- nest 4 (vcat (map (pp_group sty) imports_by_module))]
- pp_group sty (n:ns) = sep [hcat [text "Module ", pprModule (PprForUser opt_PprUserLength) (nameModule n), char ':'],
- nest 4 (sep (map (pprOccName sty . nameOccName) (n:ns)))]
-
- pp_local sty = sep [text "For information: the following local top-level definitions are unused:",
- nest 4 (sep (map (pprOccName sty . nameOccName) local_unused))]
- in
- (if null imported_unused
- then returnRn ()
- else addWarnRn pp_imp) `thenRn_`
+ unused_info :: FiniteMap Name HowInScope
+ unused_info = foldl delListFromFM
+ (delListFromFM explicit_info (nameSetToList slurped_names))
+ (map availNames export_avails)
+ unused_list = fmToList unused_info
+
+ groups = filter wanted (equivClasses cmp unused_list)
+ where
+ (name1, his1) `cmp` (name2, his2) = his1 `cmph` his2
+
+ (FromLocalDefn _) `cmph` (FromImportDecl _ _) = LT
+ (FromLocalDefn _) `cmph` (FromLocalDefn _) = EQ
+ (FromImportDecl m1 _) `cmph` (FromImportDecl m2 _) = m1 `compare` m2
+ h1 `cmph` h2 = GT
+
+ wanted ((_,FromImportDecl _ _) : _) = opt_WarnUnusedImports
+ wanted ((_,FromLocalDefn _) : _) = opt_WarnUnusedImports
+
+ pp_imp = sep [text "Warning: the following are unused:",
+ nest 4 (vcat (map pp_group groups))]
+
+ pp_group group = sep [msg <> char ':',
+ nest 4 (sep (map (pprOccName . nameOccName . fst) group))]
+ where
+ his = case group of
+ ((_,his) : _) -> his
+
+ msg = case his of
+ FromImportDecl m _ -> text "Imported from" <+> pprModule m
+ FromLocalDefn _ -> text "Locally defined"