Skip to content
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

Clarify that Cow::into_owned returns owned data #94022

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

jongiddy
Copy link
Contributor

@jongiddy jongiddy commented Feb 15, 2022

Two sections of the Cow::into_owned docs imply that into_owned returns a Cow. Clarify that it returns the underlying owned object, either cloned or extracted from the Cow.

@jongiddy
Copy link
Contributor Author

r? @m-ou-se

rust-highfive didn't tag this PR, so pinging you as library team lead.

@jongiddy jongiddy marked this pull request as draft February 19, 2022 14:19
@jongiddy jongiddy marked this pull request as ready for review February 19, 2022 14:20
@jongiddy
Copy link
Contributor Author

@rustbot label S-waiting-on-review

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2022
@@ -307,7 +306,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
/// );
/// ```
///
/// Calling `into_owned` on a `Cow::Owned` is a no-op:
/// Calling `into_owned` on a `Cow::Owned` returns the owned data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important to explicitly say that it's the original owned data and doesn't involve any new allocations/newly cloned data.

Maybe something like this:

Suggested change
/// Calling `into_owned` on a `Cow::Owned` returns the owned data:
/// Calling `into_owned` on a `Cow::Owned` returns the owned data unmodified, without cloning it:

(I see that the example doesn't really show that. Maybe a better example would show that the pointer (cow.as_ptr()) doesn't change before and after into_owned().)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the text to say that the value is moved and not cloned. I did not change the example, as the two examples demonstrate that we get the same outcome regardless of the Cow variant. Adding code to the Owned version to prove that the additional statement is true would obscure this.

@m-ou-se m-ou-se added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
@jongiddy jongiddy force-pushed the cow-into-owned-docs branch from 667fda9 to 9f4934e Compare March 23, 2022 13:01
@jongiddy
Copy link
Contributor Author

@rustbot label: +S-waiting-on-review -S-waiting-on-author

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 23, 2022
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2022
@Dylan-DPC
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 26, 2022

📌 Commit 9f4934e has been approved by Dylan-DPC

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 26, 2022
…an-DPC

Clarify that `Cow::into_owned` returns owned data

Two sections of the `Cow::into_owned` docs imply that `into_owned` returns a `Cow`. Clarify that it returns the underlying owned object, either cloned or extracted from the `Cow`.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Apr 26, 2022
…an-DPC

Clarify that `Cow::into_owned` returns owned data

Two sections of the `Cow::into_owned` docs imply that `into_owned` returns a `Cow`. Clarify that it returns the underlying owned object, either cloned or extracted from the `Cow`.
This was referenced Apr 26, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 26, 2022
…laumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#94022 (Clarify that `Cow::into_owned` returns owned data)
 - rust-lang#94703 (Fix codegen bug in "ptx-kernel" abi related to arg passing)
 - rust-lang#95949 (Implement Default for AssertUnwindSafe)
 - rust-lang#96361 (Switch JS code to ES6)
 - rust-lang#96372 (Suggest calling method on nested field when struct is missing method)
 - rust-lang#96386 (simplify `describe_field` func in borrowck's diagnostics part)
 - rust-lang#96400 (Correct documentation for `Rvalue::ShallowInitBox`)
 - rust-lang#96415 (Remove references to git.io)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit eaf8beb into rust-lang:master Apr 26, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 26, 2022
@jongiddy jongiddy deleted the cow-into-owned-docs branch April 29, 2022 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants