diff options
| author | Corey Farwell <coreyf@rwell.org> | 2018-01-28 21:50:01 -0500 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2018-01-28 21:51:33 -0500 |
| commit | 7b4cbbd12d88c8e64d9c7aa1e326c7c78f2a7ed9 (patch) | |
| tree | 0102cb79109da30fd2c1ff54f5d949fe748842fb /src | |
| parent | 21882aad7299e8e859785845ac12374990f24dae (diff) | |
| download | rust-7b4cbbd12d88c8e64d9c7aa1e326c7c78f2a7ed9.tar.gz rust-7b4cbbd12d88c8e64d9c7aa1e326c7c78f2a7ed9.zip | |
Document that `Index` ops can panic on `HashMap` & `BTreeMap`.
Fixes https://github.com/rust-lang/rust/issues/47011.
Diffstat (limited to 'src')
| -rw-r--r-- | src/liballoc/btree/map.rs | 5 | ||||
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index b114dc640fb..b320bed5432 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -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") diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index b01420f36a0..82a687ae5e4 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -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") } } |
