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:
- 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.
- 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).
for a given definition of "always"
↩︎