# SAFETY comments - nomicon

**URL:** <https://internals.rust-lang.org/t/safety-comments-nomicon/24721>\
**Category:** Unsafe Code Guidelines\
**Created:** [October 29, 2026, 2:07pm UTC](https://internals.rust-lang.org/t/safety-comments-nomicon/24721 "2026-10-29T14:07:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MusicalNinjaDad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/musicalninjadad/32/11986_2.png) [@MusicalNinjaDad](https://internals.rust-lang.org/u/MusicalNinjaDad)\
**Post date:** [October 29, 2026, 2:07pm UTC](https://internals.rust-lang.org/t/safety-comments-nomicon/24721/1 "2026-10-29T14:07:15Z")

</div>

This, in an [ongoing discussion on URLO](https://users.rust-lang.org/t/mutation-soundness-safety-in-ffi-code/143166/37), really hit home for me too.

> [@Jookia](#):
>
> Looking at the random crates I have downloaded, sdl3-sys, sdl3-rs, parley, fontations, they all use unsafe without a SAFETY quite a lot. std is even guilty of it, but seems to follow the suggestions here more. I tend to learn by doing or reading other people's work so this is where a source of my confusion comes from.

I've also noticed that there are some excellent examples of SAFETY comments and many, very many, examples of unsafe with no comments.

While agreeing with the OP, I thought "I'll refer to the nomicon, that will contain great guidelines on how to add SAFETY comments to code ..." - oops!

- The nomicon doesn't mention SAFETY comments once, nor safety-related lints
- While it does include inline comments in the "implementing Vec" example - they don't match today's expectations for format or content

I'd like to suggest raising a PR to the nomicon to:

1. add a dedicated section 1.4 "Documenting & auditing unsafe code" covering how to write safety comments as well as the fundamental rustc & clippy lints
2. update the implementing Vec example to include exemplary safety documentation

Given that we should expect a significant increase in the amount of unsafe being written in the next year, I'd consider now to be the right time to get ahead of this and hopefully push towards a positive feedback loop with more of that code including good comments.

I'd be happy to work on this, but only if it has a chance of landing 😉

---

<div class="post-metadata">

**Author:** ![danjl1100](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danjl1100/32/6466_2.png) [@danjl1100](https://internals.rust-lang.org/u/danjl1100)\
**Post date:** [October 29, 2026, 4:44pm UTC](https://internals.rust-lang.org/t/safety-comments-nomicon/24721/2 "2026-10-29T16:44:20Z")

</div>

> [@MusicalNinjaDad](#):
>
> we should expect a significant increase in the amount of unsafe being written in the next year,

As a passive observer (generally in favor of documenting this if not available elsewhere), I am curious:  
Is this more a "more code in general, some of which is unsafe" or specifically "unsafe"?

---

<div class="post-metadata">

**Author:** ![MusicalNinjaDad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/musicalninjadad/32/11986_2.png) [@MusicalNinjaDad](https://internals.rust-lang.org/u/MusicalNinjaDad)\
**Post date:** [October 29, 2026, 8:23pm UTC](https://internals.rust-lang.org/t/safety-comments-nomicon/24721/3 "2026-10-29T20:23:02Z")

</div>

> [@danjl1100](#):
>
> I am curious: Is this more a "more code in general, some of which is unsafe" or specifically "unsafe"?

My hypothesis is that we will see a larger proportion of unsafe in the next 1-2 years than usual up to now.

2 technical reasons & 1 human one:

1. migrating large code bases from C/C++ needs to happen incrementally, so there will be an unusually high need to cross ffi-boundaries while this happens.
2. codebases targeted for migration will somewhat disproportionately weigh towards including low-level elements which require unsafe (that's why they were in C and not something else)
3. mimicking the old c-style is only natural - there will be unsafe which could be idiomatically avoided (and the more effort goes into safety-commenting, the more this will be noticed and avoided)

But whatever anyone's views on the above, which is just a personal guess from my side, there is a lot of value to providing guidance on how to document unsafe.

---

<div class="post-metadata">

**Author:** ![Evian-Zhang](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/evian-zhang/32/12170_2.png) [@Evian-Zhang](https://internals.rust-lang.org/u/Evian-Zhang)\
**Post date:** [October 30, 2026, 2:01am UTC](https://internals.rust-lang.org/t/safety-comments-nomicon/24721/4 "2026-10-30T02:01:59Z")

</div>

I guess how to write SAFETY documentation is still an ongoing topic, as listed in the Rust project goal [Improving Unsafe Code Documentation in the Rust Standard Library](https://goals.rust-lang.org/2026/improve-std-unsafe.html) and [safer-rust/rust-safety-standard](https://github.com/safer-rust/rust-safety-standard), where both the goal and the repo is maintained by @hxuhack
