Backport `RTS: Fix restrictive cast` into ghc-8.8
requested to merge RyanGlScott/ghc:wip/backport-ecc9366a0e0db107c286935130837b2222e2dd82 into ghc-8.8
This backports ecc9366a, a critical bugfix which is necessary to make Haddock build without running out of memory when GHC is compiled with the quick
build flavour. Fixes https://github.com/haskell/haddock/issues/1061 for good.