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