[Git][ghc/ghc][master] Handle single unused import

Marge Bot gitlab at gitlab.haskell.org
Thu May 14 00:08:24 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
404581ea by Jeff Happily at 2020-05-13T20:08:15-04:00
Handle single unused import

- - - - -


5 changed files:

- compiler/GHC/Rename/Names.hs
- testsuite/tests/rename/should_compile/T13064.stderr
- testsuite/tests/rename/should_compile/rn046.stderr
- testsuite/tests/rename/should_fail/T7454.stderr
- testsuite/tests/rename/should_fail/T8149.stderr


Changes:

=====================================
compiler/GHC/Rename/Names.hs
=====================================
@@ -1498,9 +1498,16 @@ warnUnusedImport flag fld_env (L loc decl, used, unused)
   | null unused
   = return ()
 
+  -- Only one import is unused, with `SrcSpan` covering only the unused item instead of
+  -- the whole import statement
+  | Just (_, L _ imports) <- ideclHiding decl
+  , length unused == 1
+  , Just (L loc _) <- find (\(L _ ie) -> ((ieName ie) :: Name) `elem` unused) imports
+  = addWarnAt (Reason flag) loc msg2
+
   -- Some imports are unused
   | otherwise
-  = addWarnAt (Reason flag) loc  msg2
+  = addWarnAt (Reason flag) loc msg2
 
   where
     msg1 = vcat [ pp_herald <+> quotes pp_mod <+> is_redundant


=====================================
testsuite/tests/rename/should_compile/T13064.stderr
=====================================
@@ -1,3 +1,3 @@
 
-T13064.hs:5:1: warning: [-Wunused-imports (in -Wextra)]
+T13064.hs:5:21: warning: [-Wunused-imports (in -Wextra)]
     The import of ‘pure’ from module ‘Prelude’ is redundant


=====================================
testsuite/tests/rename/should_compile/rn046.stderr
=====================================
@@ -4,5 +4,5 @@ rn046.hs:2:1: warning: [-Wunused-imports (in -Wextra)]
       except perhaps to import instances from ‘Data.List’
     To import instances alone, use: import Data.List()
 
-rn046.hs:3:1: warning: [-Wunused-imports (in -Wextra)]
+rn046.hs:3:19: warning: [-Wunused-imports (in -Wextra)]
     The import of ‘ord’ from module ‘Data.Char’ is redundant


=====================================
testsuite/tests/rename/should_fail/T7454.stderr
=====================================
@@ -1,3 +1,3 @@
 
-T7454.hs:5:1: warning: [-Wunused-imports (in -Wextra)]
+T7454.hs:5:23: warning: [-Wunused-imports (in -Wextra)]
     The import of ‘Arrow’ from module ‘Control.Arrow’ is redundant


=====================================
testsuite/tests/rename/should_fail/T8149.stderr
=====================================
@@ -1,4 +1,4 @@
 
-T8149.hs:5:1: warning: [-Wunused-imports (in -Wextra)]
+T8149.hs:5:36: warning: [-Wunused-imports (in -Wextra)]
     The import of ‘WriterT’
     from module ‘Control.Monad.Trans.Writer’ is redundant



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/404581eaa3bf8d3f100da7610a6a38158bea17c4

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/404581eaa3bf8d3f100da7610a6a38158bea17c4
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200513/8409c3f7/attachment-0001.html>


More information about the ghc-commits mailing list