Re: [PATCH v4 2/3] rust: ptr: add projection infrastructure
From: Miguel Ojeda
Date: Tue Mar 03 2026 - 16:14:11 EST
On Mon, 02 Mar 2026 16:42:35 +0000 Gary Guo <gary@xxxxxxxxxx> wrote:
>
> Add a generic infrastructure for performing field and index projections on
> raw pointers. This will form the basis of performing I/O projections.
A few nits below for patch apply time.
> +/// A helper trait to perform index projection.
> +///
> +/// This is similar to `core::slice::SliceIndex`, but operate on raw pointers safely and fallibly.
Intra-doc link.
> +/// The implementation of `index` and `get` (if `Some` is returned) must ensure that, if provided
Intra-doc link.
> +// Forward array impl to slice impl.
`//` empty line between this and the next one.
> +// SAFETY: safety requirement guaranteed by the forwarded impl.
Capitalization (several similar ones, plus a `NOTE:` one, a "vacuously" one and
a "the provided" one).
> +/// implement `Deref`. This will cause an ambiguity error and thus block `Deref` types being used
Intra-doc links.
> +// currently support that as we need to obtain a valid allocation that `&raw const` can operate on.
> +// SAFETY: `proj` invokes `f` with valid allocation.
Probably `//` empty line between them.
> +/// It is not allowed to project into types that implement custom `Deref` or `Index`.
Intra-doc links.
> +/// `OutOfBound` error is raised via `?` if the index is out of bounds.
Intra-doc link.
> +/// Field projections are performed with `.field_name`:
> +/// ```
`//` emtpy line between paragraphs and examples (several more below).
> +/// // This will fail the build.
"would" may be clearer, unless we add "... if uncommented.".
Perhaps even:
// The following invocation would fail the build.
And maybe similarly in the next one.
> +# - Stable since Rust 1.79.0: `feature(slice_ptr_len)`.
> +# - Stable since Rust 1.84.0: `feature(strict_provenance)`.
Added both (plus `feature(exposed_provenance)`, which Andreas asked
about privately in our Zulip) to our usual lists:
https://github.com/Rust-for-Linux/linux/issues/1223
linking to the PRs and to this thread etc.
I hope that helps!
Cheers,
Miguel