Module is annotated as trustworthy, but is inferred as safe [GHC-19244]

Flag: -Wtrustworthy-safe
Enabled by: -Wall

GHC implements the SafeHaskell extension which allows programmers to restrict modules to a specific subset which is considered safe, and restricts access to “escape hatches” such as unsafePerformIO. Details about Safe Haskell are available in the GHC User’s Guide. There are two levels of safety: Safe modules are checked by GHC and are guaranteed to be safe, whereas trustworthy modules are checked by the programmer who promises that the code cannot violate the guarantees of safe Haskell. If GHC sees a module which is annotated as trustworthy, but inferred as safe, it emits a warning that the stricter “safe” annotation should be used instead.

Examples

A module was annotated as trustworthy, but inferred as safe

In this example the module was annotated as trustworthy, but GHC inferred that the module is also safe. Since “safe” is a stronger guarantee than “trustworthy”, GHC warns that the module should be annotated as safe instead. The warning can therefore be fixed by changing the annotation from trustworthy to safe.

messages/GHC-19244/trustworthy-safe/before/TrustworthySafe.hs:1:27: warning: [GHC-19244] [-Wtrustworthy-safe]
    ‘TrustworthySafe’ is marked as Trustworthy but has been inferred as safe!
  |
1 | {-# LANGUAGE Haskell2010, Trustworthy #-}
  |
TrustworthySafe.hs
Before
{-# LANGUAGE Haskell2010, Trustworthy #-}
{-# OPTIONS_GHC -fwarn-trustworthy-safe #-}
module TrustworthySafe where

theAnswer :: Int
theAnswer = 42
After
{-# LANGUAGE Haskell2010, Safe #-}
{-# OPTIONS_GHC -fwarn-trustworthy-safe #-}
module TrustworthySafe where

theAnswer :: Int
theAnswer = 42