diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 0ced4e1952a..7207e7b151c 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -375,9 +375,10 @@ impl BTreeMap { /// /// If the map did not have this key present, `None` is returned. /// - /// If the map did have this key present, the key is not updated, the - /// value is updated and the old value is returned. - /// See the [module-level documentation] for more. + /// If the map did have this key present, the value is updated, and the old + /// value is returned. The key is not updated, though; this matters for + /// types that can be `==` without being identical. See the [module-level + /// documentation] for more. /// /// [module-level documentation]: index.html#insert-and-complex-keys /// diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 586fafc2b4a..7220690469c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1157,9 +1157,10 @@ impl HashMap /// /// If the map did not have this key present, `None` is returned. /// - /// If the map did have this key present, the key is not updated, the - /// value is updated and the old value is returned. - /// See the [module-level documentation] for more. + /// If the map did have this key present, the value is updated, and the old + /// value is returned. The key is not updated, though; this matters for + /// types that can be `==` without being identical. See the [module-level + /// documentation] for more. /// /// [module-level documentation]: index.html#insert-and-complex-keys /// diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 417261cf4c3..06c14157606 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -397,12 +397,15 @@ //! } //! //! let mut map = BTreeMap::new(); -//! map.insert(Foo { a: 1, b: "baz" }, ()); +//! map.insert(Foo { a: 1, b: "baz" }, 99); //! //! // We already have a Foo with an a of 1, so this will be updating the value. -//! map.insert(Foo { a: 1, b: "xyz" }, ()); +//! map.insert(Foo { a: 1, b: "xyz" }, 100); //! -//! // ... but the key hasn't changed. b is still "baz", not "xyz" +//! // The value has been updated... +//! assert_eq!(map.values().next().unwrap(), &100); +//! +//! // ...but the key hasn't changed. b is still "baz", not "xyz". //! assert_eq!(map.keys().next().unwrap().b, "baz"); //! ```