From 8ec5ceb009299fbb3c5ff1fef39180f5a8fbb774 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus <oleg.grenrus@iki.fi> Date: Tue, 7 May 2019 12:02:15 +0300 Subject: [PATCH] Add -Wmissing-safe-haskell-mode warning --- compiler/main/HscMain.hs | 10 ++++++++++ docs/users_guide/safe_haskell.rst | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs index 91a1f1d1e66f..aa29554e9d64 100644 --- a/compiler/main/HscMain.hs +++ b/compiler/main/HscMain.hs @@ -498,6 +498,14 @@ tcRnModule' sum save_rn_syntax mod = do hsc_env <- getHscEnv dflags <- getDynFlags + -- -Wmissing-safe-haskell-mode + when (not (safeHaskellModeEnabled dflags) + && wopt Opt_WarnMissingSafeHaskellMode dflags) $ + logWarnings $ unitBag $ + makeIntoWarning (Reason Opt_WarnMissingSafeHaskellMode) $ + mkPlainWarnMsg dflags (getLoc (hpm_module mod)) $ + warnMissingSafeHaskellMode + tcg_res <- {-# SCC "Typecheck-Rename" #-} ioMsgMaybe $ tcRnModule hsc_env sum @@ -544,6 +552,8 @@ tcRnModule' sum save_rn_syntax mod = do errSafe t = quotes (pprMod t) <+> text "has been inferred as safe!" errTwthySafe t = quotes (pprMod t) <+> text "is marked as Trustworthy but has been inferred as safe!" + warnMissingSafeHaskellMode = ppr (moduleName (ms_mod sum)) + <+> text "is missing Safe Haskell mode" -- | Convert a typechecked module to Core hscDesugar :: HscEnv -> ModSummary -> TcGblEnv -> IO ModGuts diff --git a/docs/users_guide/safe_haskell.rst b/docs/users_guide/safe_haskell.rst index af016194bfcb..3911b9f41dc0 100644 --- a/docs/users_guide/safe_haskell.rst +++ b/docs/users_guide/safe_haskell.rst @@ -740,7 +740,7 @@ And one general flag: requiring the package that ``M`` resides in be considered trusted, for ``M`` to be considered trusted. -And four warning flags: +And five warning flags: .. ghc-flag:: -Wunsafe :shortdesc: warn if the module being compiled is regarded to be unsafe. @@ -809,6 +809,22 @@ And four warning flags: ``B``, it will cause compilation error of ``A``. When :ghc-flag:`-Winferred-safe-imports` is enabled, the compiler will emit a warning about this. + This option is off by default. + +.. ghc-flag:: -Wmissing-safe-haskell-mode + :shortdesc: warn when the Safe Haskell mode is not explicitly specified. + :type: dynamic + :reverse: -Wno-missing-safe-haskell-mode + :category: + + :since: 8.10.1 + + .. index:: + single: safe haskell mode, missing + + The compiler will warn when none of :extension:`Safe`, + :extension:`Trustworthy` or :extension:`Unsafe` is specified. + This option is off by default. .. _safe-compilation: -- GitLab