rust-lang / rust-lang/rust

std::pin documentation should be clearer about the precise drop guarantee/requirement

Open
#147,777 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-destructors A-docs A-pin T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The current version of the documentation on the std::pin "drop guarantee" has a lot of exposition about why the drop guarantee is needed. That's great, but it doesn't super directly and explicitly say what the drop guarantee actually is, only sort of implying it in the second paragraph as part of a sentence that also contains exposition. I think I can infer it, but I find this makes it a lot harder to be sure I'm actually providing the guarantee correctly as a user.

Could you please add a more direct callout to exactly what the requirement/guarantee is, in more precise language? For example, with a block quote callout like the following, assuming it is accurate:

If you create a Pin<Ptr> where Ptr::Target is not Unpin, you must ensure that the storage for the pointee (i.e. the Ptr::Target object) will not be reused unless the pointee is first dropped.

This is phrased as a requirement on the creator rather than a guarantee for the pinned object because I find it easier to understand that way, but a guarantee-phrased version would also be helpful.

(I also think the rest of the documentation could use some work to be more precise about other requirements/guarantees. Perhaps they could all be collected into one section with precise succinct language instead of needing to read all of what feels like an RFC each time to find them.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The relevant documentation is in library/core/src/pin.rs, around the drop guarantee section at lines 537-586. Read that section first, then revise it to state the precise requirement or guarantee directly and succinctly, while preserving the existing explanation. Done means the rendered std::pin documentation makes the storage-reuse and prior-drop requirement explicit.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.