From df01b3a67b33ef0ff7ab1f27f41056093f5b2574 Mon Sep 17 00:00:00 2001 From: r00ster Date: Sun, 18 Apr 2021 15:51:16 +0200 Subject: [PATCH 1/2] Document that `index` and `index_mut` can panic --- library/core/src/ops/index.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index a8dea4e9b4ea8..515ccd6aa2389 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -61,6 +61,10 @@ pub trait Index { type Output: ?Sized; /// Performs the indexing (`container[index]`) operation. + /// + /// # Panics + /// + /// Panics 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 : Index { /// Performs the mutable indexing (`container[index]`) operation. + /// + /// # Panics + /// + /// Panics 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; From c86ffe9e8910cb1bac1737878a524e146b54375e Mon Sep 17 00:00:00 2001 From: r00ster Date: Sun, 18 Apr 2021 18:16:10 +0200 Subject: [PATCH 2/2] Say that it "may panic" --- library/core/src/ops/index.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 515ccd6aa2389..964378cc9c3c6 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -64,7 +64,7 @@ pub trait Index { /// /// # Panics /// - /// Panics if the index is out of bounds. + /// 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; @@ -168,7 +168,7 @@ pub trait IndexMut: Index { /// /// # Panics /// - /// Panics if the index is out of bounds. + /// 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;