-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add excess capacity description for Vec::leak #79257
Add excess capacity description for Vec::leak #79257
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
This is probably not the behaviour we want to commit to, see the discussion here: rust-lang/rfcs#2969 (comment) |
ec00700
to
edd6110
Compare
trying to fix |
☔ The latest upstream changes (presumably #80530) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @m-ou-se |
edd6110
to
9b7de1c
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
@JohnCSimon I apologize for the late response. I will take a look at it this weekend. |
9b7de1c
to
b2d873f
Compare
@rustbot label -S-waiting-on-author +S-waiting-on-review |
/// let mut v = Vec::with_capacity(10); | ||
/// v.extend([1, 2, 3].iter().cloned()); | ||
/// let slice = v.clone().into_boxed_slice(); | ||
/// | ||
/// unsafe { | ||
/// let p = slice.as_ptr(); | ||
/// let rebuilt = std::slice::from_raw_parts(p, slice.len()); | ||
/// assert_eq!(rebuilt.len(), 3); | ||
/// } |
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.
This example doesn't demonstrate any leaking. .into_boxed_slice()
returns a Box
, which the slice
variable will own.
The issue this PR was originally trying to fix is that the documentation doesn't promise this function drops excess capacity. However, I don't think that's something we want to fix. Instead, I think it'd be better if leak explicitly does not drop the excess capacity. But for that, there's an RFC which has been standing still for a while: rust-lang/rfcs#2969
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.
@m-ou-se Thank you for your support and help. I've been stucking and would like to close my PR.
Fixes #79240