Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRewrite/expand doc examples for `Vec::set_len`. #34911
Conversation
steveklabnik
reviewed
Jul 19, 2016
| @@ -532,9 +532,33 @@ impl<T> Vec<T> { | |||
| /// # Examples | |||
| /// | |||
| /// ``` | |||
| /// let mut v = vec![1, 2, 3, 4]; | |||
| /// use std::ptr::drop_in_place; | |||
This comment has been minimized.
This comment has been minimized.
steveklabnik
reviewed
Jul 19, 2016
| /// unsafe { | ||
| /// v.set_len(1); | ||
| /// drop_in_place(&mut vec[3]); |
This comment has been minimized.
This comment has been minimized.
steveklabnik
reviewed
Jul 19, 2016
| /// ``` | ||
| /// | ||
| /// In this example, there is a memory leak since the memory locations | ||
| /// owned by the vector were not freed prior to the `set_len` called: |
This comment has been minimized.
This comment has been minimized.
steveklabnik
reviewed
Jul 19, 2016
| @@ -532,9 +532,33 @@ impl<T> Vec<T> { | |||
| /// # Examples | |||
| /// | |||
| /// ``` | |||
| /// let mut v = vec![1, 2, 3, 4]; | |||
| /// use std::ptr::drop_in_place; | |||
| /// let mut vec = vec!['r', 'u', 's', 't']; | |||
This comment has been minimized.
This comment has been minimized.
steveklabnik
reviewed
Jul 19, 2016
| /// owned by the vector were not freed prior to the `set_len` called: | ||
| /// | ||
| /// ``` | ||
| /// let mut vec = vec!['r', 'u', 's', 't']; |
This comment has been minimized.
This comment has been minimized.
steveklabnik
reviewed
Jul 19, 2016
| /// values of unallocated memory: | ||
| /// | ||
| /// ``` | ||
| /// let mut vec = Vec::new(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I have a bunch of teeny nitpicks, but this is great! Thanks so much. r=me after they're fixed |
frewsxcv
force-pushed the
frewsxcv:vec-set-len
branch
2 times, most recently
from
231227b
to
102419a
Jul 19, 2016
This comment has been minimized.
This comment has been minimized.
|
Comments have been addressed. Thanks for the review! |
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ rollup thanks so much!!! |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
frewsxcv
force-pushed the
frewsxcv:vec-set-len
branch
from
102419a
to
a005b2c
Jul 19, 2016
This comment has been minimized.
This comment has been minimized.
|
Changes made: @@ -538,7 +554,7 @@ impl<T> Vec<T> {
///
/// unsafe {
/// ptr::drop_in_place(&mut vec[3]);
- /// v.set_len(3);
+ /// vec.set_len(3);
/// }
/// assert_eq!(vec, ['r', 'u', 's']);
/// ```@@ -559,7 +575,7 @@ impl<T> Vec<T> {
/// values of unallocated memory:
///
/// ```
- /// let mut vec = Vec::new();
+ /// let mut vec: Vec<char> = Vec::new();
///
/// unsafe {
/// vec.set_len(4); |
rust-highfive
assigned
steveklabnik
Jul 19, 2016
This comment has been minimized.
This comment has been minimized.
|
ah, nice catch. @bors: r+ rollup |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 20, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Tue, Jul 19, 2016 at 10:01 PM, bors notifications@github.com wrote:
|
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Jul 20, 2016
bors
added a commit
that referenced
this pull request
Jul 20, 2016
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Jul 20, 2016
bors
added a commit
that referenced
this pull request
Jul 20, 2016
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Wed, Jul 20, 2016 at 6:27 PM, bors notifications@github.com wrote:
|
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Jul 21, 2016
bors
added a commit
that referenced
this pull request
Jul 21, 2016
bors
merged commit a005b2c
into
rust-lang:master
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
There is no leak here. |
This comment has been minimized.
This comment has been minimized.
|
You're absolutely right. Do you want to open a pull request to fix the example? If not, I can do it. |
This comment has been minimized.
This comment has been minimized.
|
Please, go ahead and fix it. |
This comment has been minimized.
This comment has been minimized.
|
Opened a PR: #34989 |
frewsxcv commentedJul 19, 2016
No description provided.