Add excess capacity description for Vec::leak#79257
Add excess capacity description for Vec::leak#79257chansuke wants to merge 3 commits intorust-lang:masterfrom
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.
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.
@m-ou-se Thank you for your support and help. I've been stucking and would like to close my PR.
Fixes #79240