-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Explain how Vec::with_capacity is faithful #135933
base: master
Are you sure you want to change the base?
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
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.
Awesome! Not only is this very clear and understandable, it's also a good design that can make use of advanced allocator capabilities.
Linking #101316 for convenience.
library/alloc/src/vec/mod.rs
Outdated
/// and no other size (such as, for example: a size rounded up to the nearest power of 2). | ||
/// The allocator will return an allocation that is at least as large as requested, but it may be larger. | ||
/// | ||
/// It is guaranteed that the [Vec::capacity] method returns a value that is at least the requested capacity |
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.
/// It is guaranteed that the [Vec::capacity] method returns a value that is at least the requested capacity | |
/// It is guaranteed that the [`Vec::capacity`] method returns a value that is at least the requested capacity |
library/alloc/src/vec/mod.rs
Outdated
/// It is guaranteed that the [Vec::capacity] method returns a value that is at least the requested capacity | ||
/// and not more than the allocated capacity. | ||
/// | ||
/// The method [Vec::shrink_to_fit] can discard excess capacity an allocator has given to a `Vec`. |
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.
/// The method [Vec::shrink_to_fit] can discard excess capacity an allocator has given to a `Vec`. | |
/// The method [`Vec::shrink_to_fit`] can discard excess capacity an allocator has given to a `Vec`. |
r? @workingjubilee because there were some open questions on the original PR. |
Could not assign reviewer from: |
Seems they are on vacation. r? libs-api because from what I understand this adds additional guarantees to the public API. |
@rust-lang/libs-api: This PR adds the guarantee that Whether the actual allocation can hold a larger number of elements is up to the allocator. So this still only guarantees that Before this PR, we guaranteed |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
This is a revival of #99790 building on the prose of @workingjubilee and edits of @jmaargh. Closes #99385.