I think if this proposal were fleshed out a little more, we could reconcile these concerns. Namely, I suggested unsafe-features would be off-by-default in my proposal. What if that were only the case if allow-unsafe = false or unsafe-features were present for that crate, and if they weren’t, all unsafe-features were on-by-default? (or perhaps default unsafe-features would only be honored in the event that allow-unsafe = false or unsafe-features weren’t in use)
Furthermore, since this proposal is built on a conditional compilation, crate authors could even include a safe fallback for users of allow-unsafe, with the option to opt-in to the additional performance using unsafe-features. I think this approach could give consumers of crates choices around security vs performance:
- Nothing would change for projects which don’t choose to make use of the
allow-unsafe or unsafe-features attributes. They’d automatically get opted into the unsafe performance optimizations.
- Users of
allow-unsafe could get a less performant, safe fallback.
- If the additional performance is desired,
unsafe-features can be used instead of allow-unsafe to opt-in to the unsafe optimization.
I imagine things like [patch] could even be used to globally enable certain unsafe-features for all crates.
Overall I would expect a feature like this isn’t commonly used, and would require transitive adoption and support on a crate-by-crate basis in a dependency hierarchy. In that regard I think it’s a bit like #![no_std]: a feature which is extremely useful to a subset of the community (people using Rust in any sort of “high assurance” capacity) which can be largely ignored by the rest.
I discussed this in the “Tough questions” section of my proposal, and suggested that std could be allowed to “bless” certain unsafe code which does not provide access to ambient authority or cause potentially security-critical side effects.
Though I didn’t explicitly call it out as such, I think allocators would belong to this category.