Skip to content

Commit 930e00f

Browse files
authored
Rollup merge of rust-lang#84301 - r00ster91:patch-1, r=kennytm
Document that `index` and `index_mut` can panic I thought this was noteworthy and I think a bit more explicitness does no harm.
2 parents fab8b25 + c86ffe9 commit 930e00f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/ops/index.rs

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub trait Index<Idx: ?Sized> {
6161
type Output: ?Sized;
6262

6363
/// Performs the indexing (`container[index]`) operation.
64+
///
65+
/// # Panics
66+
///
67+
/// May panic if the index is out of bounds.
6468
#[stable(feature = "rust1", since = "1.0.0")]
6569
#[track_caller]
6670
fn index(&self, index: Idx) -> &Self::Output;
@@ -161,6 +165,10 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
161165
#[doc(alias = "[]")]
162166
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
163167
/// Performs the mutable indexing (`container[index]`) operation.
168+
///
169+
/// # Panics
170+
///
171+
/// May panic if the index is out of bounds.
164172
#[stable(feature = "rust1", since = "1.0.0")]
165173
#[track_caller]
166174
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;

0 commit comments

Comments
 (0)