Skip to content

Commit 735bc1c

Browse files
nbdd0121ojeda
authored andcommitted
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>
1 parent 03e8578 commit 735bc1c

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

rust/kernel/ptr/projection.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ impl From<OutOfBound> for Error {
2626
///
2727
/// # Safety
2828
///
29-
/// The implementation of `index` and `get` (if [`Some`] is returned) must ensure that, if provided
30-
/// input pointer `slice` and returned pointer `output`, then:
29+
/// For a given input pointer `slice` and return value `output`, the implementation of `build_index`
30+
/// and `get` (if [`Some`] is returned) must ensure that:
3131
/// - `output` has the same provenance as `slice`;
3232
/// - `output.byte_offset_from(slice)` is between 0 to
3333
/// `KnownSize::size(slice) - KnownSize::size(output)`.
3434
///
35-
/// This means that if the input pointer is valid, then pointer returned by `get` or `index` is
36-
/// also valid.
35+
/// This means that if the input pointer is valid, then the pointer returned by `get` or
36+
/// `build_index` is also valid.
3737
#[diagnostic::on_unimplemented(message = "`{Self}` cannot be used to index `{T}`")]
3838
#[doc(hidden)]
3939
pub unsafe trait ProjectIndex<T: ?Sized>: Sized {
@@ -44,7 +44,7 @@ pub unsafe trait ProjectIndex<T: ?Sized>: Sized {
4444

4545
/// Returns an index-projected pointer; fail the build if it cannot be proved to be in bounds.
4646
#[inline(always)]
47-
fn index(self, slice: *mut T) -> *mut Self::Output {
47+
fn build_index(self, slice: *mut T) -> *mut Self::Output {
4848
Self::get(self, slice).unwrap_or_else(|| build_error!())
4949
}
5050
}
@@ -64,8 +64,8 @@ where
6464
}
6565

6666
#[inline(always)]
67-
fn index(self, slice: *mut [T; N]) -> *mut Self::Output {
68-
<I as ProjectIndex<[T]>>::index(self, slice)
67+
fn build_index(self, slice: *mut [T; N]) -> *mut Self::Output {
68+
<I as ProjectIndex<[T]>>::build_index(self, slice)
6969
}
7070
}
7171

@@ -287,7 +287,7 @@ macro_rules! project_pointer {
287287
};
288288
// Build-time checked index projection.
289289
(@gen $ptr:ident, [$index:expr] $($rest:tt)*) => {
290-
let $ptr = $crate::ptr::projection::ProjectIndex::index($index, $ptr);
290+
let $ptr = $crate::ptr::projection::ProjectIndex::build_index($index, $ptr);
291291
$crate::ptr::project!(@gen $ptr, $($rest)*)
292292
};
293293
(mut $ptr:expr, $($proj:tt)*) => {{

0 commit comments

Comments
 (0)