Uh oh!
There was an error while loading. Please reload this page.
Document the current aliasing rules for Box<T>. - #97229
Conversation
rust-highfive
commented
May 20, 2022
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
rust-highfive
commented
May 20, 2022
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
Noratrieb
commented
May 20, 2022
r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs |
dtolnay
left a comment
There was a problem hiding this comment.
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.
Noratrieb
commented
May 26, 2022
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 |
Uh oh!
There was an error while loading. Please reload this page.
dtolnay
commented
May 30, 2022
@bors r+ rollup |
bors
commented
May 30, 2022
📌 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.