-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand addr_of[_mut] UB documentation #95117
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
library/core/src/ptr/mod.rs
Outdated
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to other rules: | ||
/// * A [dangling] pointer cannot be dereferenced. In particular, `addr_of!(*ptr::null_mut())` | ||
/// is undefined behavior because it dereferences a null pointer. | ||
/// * An unaligned pointer cannot be dereferenced. For example, `addr_of!((*an_unaligned_ptr).field)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does unaligned deserve a link to a better description / example or will everyone that reads this have that context already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I've added a link there to the Type layout reference page.
Explicitly list the things you aren't allowed to do with `expr`, and add a link to the exact definition of a dangling pointer. Fixes rust-lang#94473
996f7d8
to
5398b83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
r? @JohnTitor @bors r+ rollup |
📌 Commit 5398b83 has been approved by |
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all | ||
/// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined | ||
/// Behavior because it dereferences a null pointer. | ||
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to other rules: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a good idea to make it clear that these are just the normal rules for all expr
in place context, and not something specific to addr_of!
.
For example, addr_of!(unsafe { unreachable_unchecked() })
is also still UB, of course. We don't want to list all language UB again here.
@bors r- |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
r? @RalfJung |
ping from triage: FYI: when a PR is ready for review, send a message containing |
closing this due to inactivity |
Explicitly list the things you aren't allowed to do with
expr
, and adda link to the exact definition of a dangling pointer.
Fixes #94473