From: Alice Ryhl <aliceryhl@google.com>
To: Gary Guo <gary@kernel.org>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Benno Lossin" <lossin@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
"Gary Guo" <gary@garyguo.net>
Subject: Re: [PATCH] rust: pin-init: document self-referential feature
Date: Thu, 26 Nov 2026 08:13:44 +0000 [thread overview]
Message-ID: <20261126081346.3466629-1-aliceryhl@google.com> (raw)
In-Reply-To: <20261124-dev-pin-init-doc-v1-1-dd0a3eda9018@garyguo.net>
On Tue, Nov 24, 2026 at 10:16:23PM +0000, Gary Guo wrote:
> +/// When initializing such a struct with [`pin_init!`], every named initialized field have a
> +/// binding generated for it (as `&T`/`Pin<&T>` for fields share-borrowed, or `&mut`/`Pin<&mut T>`
> +/// for fields mutably-borrowed), so a field can borrow from the fields initialized before it:
A couple of minor typos here:
- "have a" -> "has a"
- "share-borrowed" -> "shared-borrowed" (to match "Mutable Borrows" below)
- "`&mut`/`Pin<&mut T>`" -> "`&mut T`/`Pin<&mut T>`"
> +/// Note that `&mut`/`Pin<&mut T>` bindings are also generated for non-borrowed field, but access to
> +/// them are limited to within the initializer.
Same here:
- "`&mut`/`Pin<&mut T>`" -> "`&mut T`/`Pin<&mut T>`"
- "non-borrowed field" -> "non-borrowed fields"
- "access to them are" -> "access to them is"
> +/// The macro verifies that captures marked covariant really are covariant. `#[uses]` accepts a
> +/// comma-separated list of lifetimes, each with an optional variance (the default being
> +/// `covariant`). The special lifetime `'_` stands for all field lifetimes mentioned in the type
> +/// of the field, e.g. `#[uses('_: invariant)]`.
I think `'_` also applies to existential lifetimes mentioned in the
field type, not just field lifetimes.
> +/// An existential lifetime is not a parameter of the struct, so just like a field lifetime it is
> +/// hidden from the type of the struct. Unlike a field lifetime, it is not tied to a field; the
> +/// only bounds placed on it are those written in the where clause (here `'x: 'a`).
I think it'd be useful to explicitly say:
are those written in the where clause (here `'x: 'a`, i.e. 'x is
shorter than 'a).
> +/// - `project(self: Pin<&mut Self>)` — the pin projection: `#[pin]` fields are projected as
> +/// `Pin<&mut T>`, all other fields as `&mut T`. Fields that capture a field lifetime covariantly
> +/// are only projected as (possibly pinned) shared references; fields with invariant field
> +/// lifetime capture are omitted entirely.
> +/// - `with_project(self: Pin<&mut Self>, f)` — calls `f` with a projection in which every
> +/// visible field has its actual field lifetime, so even invariant captures are visible.
> +/// - `with_project_ref(self: Pin<&Self>, f)` — the shared version of `with_project`.
> +///
> +/// For all projections, shared borrow fields are only accessible with shared references, and
> +/// mutably borrowed fields are omitted (they are only accessible through the fields that borrow
> +/// them).
"shared borrow fields" -> "shared-borrowed fields" (to match "mutably
borrowed fields" and avoid sounding like fields that hold a borrow).
> +/// The fields are initialized in the order that they appear in the initializer. A let binding
> +/// is generated so already initialized fields can be read. For [self-referential
> +/// structs](pin_data#self-referential-structs), you may also use such generated bindings to
> +/// initialize fields that borrow from them.
`init!` just below still has `- no references to fields are allowed to
be created inside of the initializer.` even though `init!` generates the
same `let` bindings for named fields.
Alice
next prev parent reply other threads:[~2026-11-26 8:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:16 Gary Guo
2026-11-26 8:13 ` Alice Ryhl [this message]
2026-11-26 9:56 ` Philipp Stanner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126081346.3466629-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gary@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®