diff options
author | Jeff Happily <goodboy96@live.com.my> | 2020-05-09 13:54:46 +0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-05-13 20:08:15 -0400 |
commit | 404581eaa3bf8d3f100da7610a6a38158bea17c4 (patch) | |
tree | dc5564e70a77e341c6e9d6f664f351ccde4515ca | |
parent | a951e1bab3dfd3e9de31b0d8bf5699a9216b181d (diff) | |
download | haskell-404581eaa3bf8d3f100da7610a6a38158bea17c4.tar.gz |
Handle single unused import
-rw-r--r-- | compiler/GHC/Rename/Names.hs | 9 | ||||
-rw-r--r-- | testsuite/tests/rename/should_compile/T13064.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rename/should_compile/rn046.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T7454.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T8149.stderr | 2 |
5 files changed, 12 insertions, 5 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs index cd39ed701d..db74847707 100644 --- a/compiler/GHC/Rename/Names.hs +++ b/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 diff --git a/testsuite/tests/rename/should_compile/T13064.stderr b/testsuite/tests/rename/should_compile/T13064.stderr index 3175a8563f..a94e5b70d5 100644 --- a/testsuite/tests/rename/should_compile/T13064.stderr +++ b/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 diff --git a/testsuite/tests/rename/should_compile/rn046.stderr b/testsuite/tests/rename/should_compile/rn046.stderr index 458feae39f..e1947d914d 100644 --- a/testsuite/tests/rename/should_compile/rn046.stderr +++ b/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 diff --git a/testsuite/tests/rename/should_fail/T7454.stderr b/testsuite/tests/rename/should_fail/T7454.stderr index 8baef5d139..ba9666cf35 100644 --- a/testsuite/tests/rename/should_fail/T7454.stderr +++ b/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 diff --git a/testsuite/tests/rename/should_fail/T8149.stderr b/testsuite/tests/rename/should_fail/T8149.stderr index 3cef09b317..33b45e9598 100644 --- a/testsuite/tests/rename/should_fail/T8149.stderr +++ b/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 |