Skip to content
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

Closed

Conversation

nicholasbishop
Copy link
Contributor

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 #94473

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 19, 2022
/// 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)`
Copy link
Contributor

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?

Copy link
Contributor Author

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
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2022
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2022
Copy link
Member

@JohnTitor JohnTitor left a 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!

@JohnTitor
Copy link
Member

r? @JohnTitor @bors r+ rollup

@bors
Copy link
Contributor

bors commented May 23, 2022

📌 Commit 5398b83 has been approved by JohnTitor

@rust-highfive rust-highfive assigned JohnTitor and unassigned m-ou-se May 23, 2022
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 23, 2022
/// 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:
Copy link
Member

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.

@JohnTitor
Copy link
Member

@bors r-
@nicholasbishop Could you address the review comment above?

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 23, 2022
@RalfJung

This comment was marked as outdated.

@RalfJung

This comment was marked as outdated.

@RalfJung
Copy link
Member

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned JohnTitor May 23, 2022
@apiraino apiraino added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 23, 2022
@JohnCSimon
Copy link
Member

ping from triage:
@nicholasbishop

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@Dylan-DPC
Copy link
Member

closing this due to inactivity

@Dylan-DPC Dylan-DPC closed this Jul 19, 2022
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for addr_of_mut! is contradictory
10 participants