Clarify guarantees for Box allocation#58183
Conversation
|
@rfcbot fcp merge We'll probably want to be a bit more specific about what the specified behavior is, but I do think that we want to guarantee this, in similar ways to how we already guarantee that we'll never e.g. do small string optimizations in String. |
|
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
@rfcbot concern global The principle sounds good, but the diff is incorrect. |
|
Maybe this should mention |
|
I think the language around conversion with pointers needs to be worded more precisely also. |
cc88f02 to
eacadd8
Compare
|
In the changes I just pushed I have elaborated on the conversion.
thanks for catching that.
I used |
|
@SimonSapin is your concern resolved? |
src/liballoc/boxed.rs
Outdated
There was a problem hiding this comment.
Is this all true for zero-sized types?
There was a problem hiding this comment.
Ah yeah, we need to add an exception for ZSTs since those can't interact with global allocators.
There was a problem hiding this comment.
Tangentially related, is there a reason std::alloc::Layout::from_size_align(0, 1) returns Ok?
There was a problem hiding this comment.
Creating a (possibly) zero-size layout is valid. It could be used as an intermediate value passed to Layout::extend, for example.
eacadd8 to
861405c
Compare
|
Yes, thanks. @rfcbot resolve global. One more tweak: what matters is whether the value is zero-size or whether the allocation would be zero-size, rather than the type. This makes a difference for dynamically-sized types: |
|
@rfcbot resolve global |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
861405c to
e41e694
Compare
|
Changed “non-zero-sized types” to “non-zero-sized values”. |
|
Actually, should we add some guarantees around zero-sized values as well? Such as
|
|
Maybe this should all go into the docs for |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process,I would like to thank @sfacklerfor their work and everyone else who contributed. The RFC will be merged soon. |
We can still do this but the current diff looks good already. @bors r+ |
|
📌 Commit e41e694 has been approved by |
|
@RalfJung Oliver suggested we add a miri test for what's written here to ensure it's fine for CTFE; I have no idea how to do that, but maybe you do? |
…=SimonSapin Clarify guarantees for `Box` allocation This basically says `Box` does the obvious things for its allocations. See also: https://users.rust-lang.org/t/alloc-crate-guarantees/24981 This may require a T-libs FCP? Not sure. r? @sfackler
…=SimonSapin Clarify guarantees for `Box` allocation This basically says `Box` does the obvious things for its allocations. See also: https://users.rust-lang.org/t/alloc-crate-guarantees/24981 This may require a T-libs FCP? Not sure. r? @sfackler
Rollup of 6 pull requests Successful merges: - #57364 (Improve parsing diagnostic for negative supertrait bounds) - #58183 (Clarify guarantees for `Box` allocation) - #58442 (Simplify the unix `Weak` functionality) - #58454 (Refactor Windows stdio and remove stdin double buffering ) - #58511 (Const to op simplification) - #58642 (rustdoc: support methods on primitives in intra-doc links) Failed merges: r? @ghost
|
yes |
This basically says
Boxdoes the obvious things for its allocations.See also: https://users.rust-lang.org/t/alloc-crate-guarantees/24981
This may require a T-libs FCP? Not sure.
r? @sfackler