mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Document that Index
ops can panic on HashMap
& BTreeMap
.
Fixes https://github.com/rust-lang/rust/issues/47011.
This commit is contained in:
parent
21882aad72
commit
7b4cbbd12d
@ -1748,6 +1748,11 @@ impl<'a, K: Ord, Q: ?Sized, V> Index<&'a Q> for BTreeMap<K, V>
|
|||||||
{
|
{
|
||||||
type Output = 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]
|
#[inline]
|
||||||
fn index(&self, key: &Q) -> &V {
|
fn index(&self, key: &Q) -> &V {
|
||||||
self.get(key).expect("no entry found for key")
|
self.get(key).expect("no entry found for key")
|
||||||
|
@ -1384,9 +1384,14 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S>
|
|||||||
{
|
{
|
||||||
type Output = 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 `HashMap`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &Q) -> &V {
|
fn index(&self, key: &Q) -> &V {
|
||||||
self.get(index).expect("no entry found for key")
|
self.get(key).expect("no entry found for key")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user