Rollup merge of #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.
This commit is contained in:
Mara Bos 2021-04-21 23:06:16 +02:00 committed by GitHub
commit d341851f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,10 @@ pub trait Index<Idx: ?Sized> {
type Output: ?Sized;
/// Performs the indexing (`container[index]`) operation.
///
/// # Panics
///
/// May panic if the index is out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
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
#[doc(alias = "[]")]
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
/// Performs the mutable indexing (`container[index]`) operation.
///
/// # Panics
///
/// May panic if the index is out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;