rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 258 forks source link

Add safety comments #333

Closed 5225225 closed 1 year ago

5225225 commented 2 years ago

This is mostly asking if this is the right way to go about this, the comments are nowhere near done.

The wording can be updated, but my main questions are

  1. Would it be too verbose to add safety comments to all of the unsafe blocks here? I could instead have a chapter implementing something simpler. I'm expecting a few lines of docs above every unsafe block.
  2. I sometimes need to call back to invariants on the type (i.e. pointer is either allocated or dangling). For now I think I'll not do anything about that, but in the future I might decide to copy paste the Vec's definition with all the invariants (or just copy paste the invariant text) whenever we use them.
  3. Sometimes we can't actually prove safety of something because it was ignored for simplicity reasons. I don't actually remember which comments were like this, but I distinctly remember some safety being unprovable. Assuming this comes up, what should I do?