summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2026-06-02 17:17:54 +0300
committerMiguel Ojeda <ojeda@kernel.org>2026-06-05 11:16:11 +0300
commit38c3cbf5072ed85cea1559cbb36a760f7dabb114 (patch)
tree6dcb729e75d50f0ac5204027f96de40b5914c6a2 /include
parent4dda19120a93a559681205fe0476908d8356d52c (diff)
downloadlinux-38c3cbf5072ed85cea1559cbb36a760f7dabb114.tar.xz
rust: ptr: add panicking index projection variant
There have been a few cases where the programmer knows that the indices are in bounds but the compiler cannot deduce that. This is also compiler-version-dependent, so using build indexing here can be problematic. On the other hand, it is also not ideal to use the fallible variant, as it adds an error handling path that is never hit. Add a new panicking index projection for this scenario. Like all panicking operations, this should be used carefully only in cases where the user knows the index is going to be in bounds, and panicking would indicate something is catastrophically wrong. To signify this, require users to explicitly denote the type of index being used. The existing two types of index projections also gain the keyworded version, which will be the recommended way going forward. The keyworded syntax also paves the way of perhaps adding more flavors in the future, e.g. `unsafe` index projection. However, unless the code is extremely performance sensitive and bounds checking cannot be tolerated, the panicking variant is safer and should be preferred, so it will be left to the future when demand arises. Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260602-projection-syntax-rework-v2-3-6989470f5440@garyguo.net [ Fixed broken intra-doc link. Added a few extra intra-doc links. Reworded some docs slightly. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'include')
0 files changed, 0 insertions, 0 deletions