-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Document the current aliasing rules for Box<T>
.
#97229
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
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs |
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 needs to be more clear that nothing in this alarming-looking section is relevant to a causal reader who isn't writing their own unsafe code (which is 99%+ of people learning about Box
from its rustdoc).
Perhaps a section like # Considerations for unsafe code
would be more appropriate, saying "raw pointer" instead of "pointer", and being explicit like "For more guidance on working with Box from unsafe code, see ucg#326".
Currently, `Box<T>` gets `noalias`, meaning it has the same rules as `&mut T`. This is sparsely documented, even though it can have quite a big impact on unsafe code using box. Therefore, these rules are documented here, with a big warning that they are not normative and subject to change, since we have not yet committed to an aliasing model and the state of `Box<T>` is especially uncertain.
d5e12b3
to
e7c468d
Compare
That makes sense, this could definitely be confusing for people not using unsafe code. I changed the header as you suggested. Maybe it makes sense to have a h2 that is still called |
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 :) thanks!
@bors r+ rollup |
📌 Commit ffd7f58 has been approved by |
Rollup of 6 pull requests Successful merges: - rust-lang#97089 (Improve settings theme display) - rust-lang#97229 (Document the current aliasing rules for `Box<T>`.) - rust-lang#97371 (Suggest adding a semicolon to a closure without block) - rust-lang#97455 (Stabilize `toowned_clone_into`) - rust-lang#97565 (Add doc alias `memset` to `write_bytes`) - rust-lang#97569 (Remove `memset` alias from `fill_with`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Currently,
Box<T>
getsnoalias
, meaning it has the same rules as&mut T
. This is sparsely documented, even though it can have quite a big impact on unsafe code using box. Therefore, these rules are documented here, with a big warning that they are not normative and subject to change, since we have not yet committed to an aliasing model and the state ofBox<T>
is especially uncertain.If you have any suggestions and improvements, make sure to leave them here. This is mostly intended to inform people about what is currently going on (to prevent misunderstandings such as Jon Gjengset's Box aliasing).
This is supposed to only document current UB and not add any new guarantees or rules.