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

Expand CloneToUninit documentation. #133055

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Nov 14, 2024

  • Clarify relationship to dyn after Make CloneToUninit dyn-compatible #133003.
  • Add an example of using it with dyn as Make CloneToUninit dyn-compatible #133003 enabled.
  • Replace parameter name dst with dest to avoid confusion between abbreviations for “DeSTination” and “Dynamically-Sized Type”.
  • Add an example of implementing it.
  • Add links to Rust Reference for the mentioned concepts.
  • Mention that its method should rarely be called.
  • Various small corrections.

Please review the unsafe code closely, as I am not an expert in the best possible ways to express these operations. (It might also be better to omit the implementation example entirely.)

cc @zachs18 #126799

* Clarify relationship to `dyn` after rust-lang#133003.
* Add an example of using it with `dyn` as rust-lang#133003 enabled.
* Add an example of implementing it.
* Add links to Rust Reference for the mentioned concepts.
* Mention that its method should rarely be called.
* Various small corrections.
This avoids confusion between “DeSTination” and “Dynamically-Sized Type”.
@rustbot
Copy link
Collaborator

rustbot commented Nov 14, 2024

r? @cuviper

rustbot has assigned @cuviper.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 14, 2024
@kpreid kpreid changed the title Clone uninit doc Expand CloneToUninit documentation. Nov 14, 2024
Copy link
Contributor

@zachs18 zachs18 left a comment

Choose a reason for hiding this comment

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

The unsafe code in the impl CloneToUninit for MyDst<T> example looks correct to me, with one note about a comment.

Comment on lines +294 to +295
/// // We use `pointer::write()` instead of assignment because the destination may be
/// // uninitialized.
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC it's fine to *ptr = value; for Copy types even if *ptr is uninitialized, but using write is definitely also correct here and doesn't distract from the example, and more importantly would also be correct for a non-Copy field with drop glue (where *ptr = value.clone(); wouldn't be correct, but ptr.write(value.clone()) would), so I think it's good to call out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants