Skip to content

Commit 42ca326

Browse files
Rollup merge of rust-lang#123271 - JaniM:janim/sliceindex-doc, r=Nilstrieb
doc: describe panic conditions for SliceIndex implementations Implementation note: The most probable place for users to find the documentation is at https://doc.rust-lang.org/std/slice/trait.SliceIndex.html On that page, documentation added to specific methods will not be visible. As such, I opted to add the comments to the impl blocks directly. Helps with rust-lang#121568.
2 parents 9ff4c70 + 4ca3151 commit 42ca326

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/src/slice/index.rs

+11
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
195195
fn index_mut(self, slice: &mut T) -> &mut Self::Output;
196196
}
197197

198+
/// The methods `index` and `index_mut` panic if the index is out of bounds.
198199
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
199200
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
200201
unsafe impl<T> SliceIndex<[T]> for usize {
@@ -328,6 +329,9 @@ unsafe impl<T> SliceIndex<[T]> for ops::IndexRange {
328329
}
329330
}
330331

332+
/// The methods `index` and `index_mut` panic if:
333+
/// - the start of the range is greater than the end of the range or
334+
/// - the end of the range is out of bounds.
331335
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
332336
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
333337
unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
@@ -416,6 +420,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
416420
}
417421
}
418422

423+
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
419424
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
420425
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
421426
unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
@@ -454,6 +459,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
454459
}
455460
}
456461

462+
/// The methods `index` and `index_mut` panic if the start of the range is out of bounds.
457463
#[stable(feature = "slice_get_slice_impls", since = "1.15.0")]
458464
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
459465
unsafe impl<T> SliceIndex<[T]> for ops::RangeFrom<usize> {
@@ -536,6 +542,10 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeFull {
536542
}
537543
}
538544

545+
/// The methods `index` and `index_mut` panic if:
546+
/// - the end of the range is `usize::MAX` or
547+
/// - the start of the range is greater than the end of the range or
548+
/// - the end of the range is out of bounds.
539549
#[stable(feature = "inclusive_range", since = "1.26.0")]
540550
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
541551
unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
@@ -580,6 +590,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
580590
}
581591
}
582592

593+
/// The methods `index` and `index_mut` panic if the end of the range is out of bounds.
583594
#[stable(feature = "inclusive_range", since = "1.26.0")]
584595
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
585596
unsafe impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {

0 commit comments

Comments
 (0)