Rollup merge of #47839 - frewsxcv:frewsxcv-map-index, r=QuietMisdreavus

Document that `Index` ops can panic on `HashMap` & `BTreeMap`.

Fixes https://github.com/rust-lang/rust/issues/47011.
This commit is contained in:
kennytm 2018-01-30 17:10:58 +08:00 committed by GitHub
commit 95572df8eb
2 changed files with 12 additions and 2 deletions

View file

@ -1748,6 +1748,11 @@ impl<'a, K: Ord, Q: ?Sized, V> Index<&'a Q> for BTreeMap<K, V>
{
type Output = V;
/// Returns a reference to the value corresponding to the supplied key.
///
/// # Panics
///
/// Panics if the key is not present in the `BTreeMap`.
#[inline]
fn index(&self, key: &Q) -> &V {
self.get(key).expect("no entry found for key")

View file

@ -1384,9 +1384,14 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S>
{
type Output = V;
/// Returns a reference to the value corresponding to the supplied key.
///
/// # Panics
///
/// Panics if the key is not present in the `HashMap`.
#[inline]
fn index(&self, index: &Q) -> &V {
self.get(index).expect("no entry found for key")
fn index(&self, key: &Q) -> &V {
self.get(key).expect("no entry found for key")
}
}