Private unsafe fields are a poorly motivated feature
Rust Internals [Unofficial]
February 5, 2026
tczajka:
Or should
valbe anunsafefield here, even though the module doesn't use it for memory safety?
I would respond that the example is poor.
It should clarify whether "guaranteed" is correctness or soundness, and then either
- make
set_uncheckednot beunsafe, or - make
valbeunsafe, updating thenewwith a safety comment about why constructing it there is correct
Right now it's unclear to consumers whether they can soundly do std::num::NonZero::new_unchecked(your_nz.get()) or not, so even without this feature that should be clarified.
(Similarly, if set_unchecked is going to be unsafe fn then it should have a # Safety comment to state its preconditions.)
Discussion in the ATmosphere