diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs index 91a1f1d1e66fecb587567faf204a63a936f1cf44..aa29554e9d64c23036c2768a2ed3f7f23c32f4fd 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 af016194bfcb815fe7775d1f75b36385653493e1..3911b9f41dc0efb5f448505587b78def428e685f 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: