diff options
| author | Gary Guo <gary@garyguo.net> | 2026-06-02 15:17:52 +0100 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2026-06-05 10:11:05 +0200 |
| commit | 735bc1c843101aa2383061acb73d3824c7a66e11 (patch) | |
| tree | f0662c2b80ad7e3db7554b784a33583c1792579f /rust/kernel | |
| parent | 03e8578813157c74d9f7033bd797b3939f2facd6 (diff) | |
rust: ptr: rename `ProjectIndex::index` to `build_index`
The corresponding `SliceIndex` trait in Rust uses `index` to mean the
panicking variant, which is also being added to `ProjectIndex`. Hence
rename our custom `build_error!` index variant to `build_index`.
Suggested-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://lore.kernel.org/rust-for-linux/DI5LLN2V3XCS.34H4CG99N4MPA@nvidia.com
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260602-projection-syntax-rework-v2-1-6989470f5440@garyguo.net
[ Reworded docs slightly. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
| -rw-r--r-- | rust/kernel/ptr/projection.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/rust/kernel/ptr/projection.rs b/rust/kernel/ptr/projection.rs index 140ea8e21617..441bc1b83c3f 100644 --- a/rust/kernel/ptr/projection.rs +++ b/rust/kernel/ptr/projection.rs @@ -26,14 +26,14 @@ impl From<OutOfBound> for Error { /// /// # Safety /// -/// The implementation of `index` and `get` (if [`Some`] is returned) must ensure that, if provided -/// input pointer `slice` and returned pointer `output`, then: +/// For a given input pointer `slice` and return value `output`, the implementation of `build_index` +/// and `get` (if [`Some`] is returned) must ensure that: /// - `output` has the same provenance as `slice`; /// - `output.byte_offset_from(slice)` is between 0 to /// `KnownSize::size(slice) - KnownSize::size(output)`. /// -/// This means that if the input pointer is valid, then pointer returned by `get` or `index` is -/// also valid. +/// This means that if the input pointer is valid, then the pointer returned by `get` or +/// `build_index` is also valid. #[diagnostic::on_unimplemented(message = "`{Self}` cannot be used to index `{T}`")] #[doc(hidden)] pub unsafe trait ProjectIndex<T: ?Sized>: Sized { @@ -44,7 +44,7 @@ pub unsafe trait ProjectIndex<T: ?Sized>: Sized { /// Returns an index-projected pointer; fail the build if it cannot be proved to be in bounds. #[inline(always)] - fn index(self, slice: *mut T) -> *mut Self::Output { + fn build_index(self, slice: *mut T) -> *mut Self::Output { Self::get(self, slice).unwrap_or_else(|| build_error!()) } } @@ -64,8 +64,8 @@ where } #[inline(always)] - fn index(self, slice: *mut [T; N]) -> *mut Self::Output { - <I as ProjectIndex<[T]>>::index(self, slice) + fn build_index(self, slice: *mut [T; N]) -> *mut Self::Output { + <I as ProjectIndex<[T]>>::build_index(self, slice) } } @@ -287,7 +287,7 @@ macro_rules! project_pointer { }; // Build-time checked index projection. (@gen $ptr:ident, [$index:expr] $($rest:tt)*) => { - let $ptr = $crate::ptr::projection::ProjectIndex::index($index, $ptr); + let $ptr = $crate::ptr::projection::ProjectIndex::build_index($index, $ptr); $crate::ptr::project!(@gen $ptr, $($rest)*) }; (mut $ptr:expr, $($proj:tt)*) => {{ |
