#![restrict(unsafe, modules = "platform::win")] (bikesheddable)

I've recently found myself creating a library which includes some platform-specific ffi usage as well as some much higher-level functionality, which I'd really rather not split into 2 crates.

This means I cannot #![forbid(unsafe)] at the top level, only #![deny(unsafe)] and that allows #[expect(unsafe)] anywhere.

Ideally, I would like to forbid unsafe except for a pre-determined set of modules, where it was simply deny-ed. I would see 2 advantages for this:

  1. added safety for anyone reviewing / auditing the crate - they know where to look for unsafe, can reason about whether there is a need and be confident that no other unsafe exists.
  2. deterministic verification via a lint or test is always[1] better than non-deterministic via a human reviewer, however trustworthy that human is.

Does anything like this already exist? I couldn't find any historical proposals for something along the lines of #![restrict(unsafe, modules = "platform::win")] (bikesheddable).


  1. for a given definition of "always" :wink: ↩︎