Skip to content

Commit ae93c8d

Browse files
authored
Rollup merge of rust-lang#114605 - Easyoakland:hash-collection-doc, r=thomcc
Increase clarity about Hash - Eq consistency in HashMap and HashSet docs As discussed [here](https://users.rust-lang.org/t/what-hapens-if-hash-and-partialeq-dont-match-when-using-hashmap/98052/13) the description of logic errors in `HashMap` and `HashSet` does not explicitly apply to ```text k1 == k2 -> hash(k1) == hash(k2) ``` but this is likely what is intended. This PR is a small doc change to correct this. r? rust-lang/libs
2 parents b596930 + 98e434a commit ae93c8d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

library/std/src/collections/hash/map.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ use crate::sys;
4949
/// ```
5050
///
5151
/// In other words, if two keys are equal, their hashes must be equal.
52+
/// Violating this property is a logic error.
5253
///
53-
/// It is a logic error for a key to be modified in such a way that the key's
54+
/// It is also a logic error for a key to be modified in such a way that the key's
5455
/// hash, as determined by the [`Hash`] trait, or its equality, as determined by
5556
/// the [`Eq`] trait, changes while it is in the map. This is normally only
5657
/// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
57-
/// The behavior resulting from such a logic error is not specified, but will
58+
///
59+
/// The behavior resulting from either logic error is not specified, but will
5860
/// be encapsulated to the `HashMap` that observed the logic error and not
5961
/// result in undefined behavior. This could include panics, incorrect results,
6062
/// aborts, memory leaks, and non-termination.

library/std/src/collections/hash/set.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use super::map::{map_try_reserve_error, RandomState};
2424
/// ```
2525
///
2626
/// In other words, if two keys are equal, their hashes must be equal.
27+
/// Violating this property is a logic error.
2728
///
28-
///
29-
/// It is a logic error for a key to be modified in such a way that the key's
29+
/// It is also a logic error for a key to be modified in such a way that the key's
3030
/// hash, as determined by the [`Hash`] trait, or its equality, as determined by
3131
/// the [`Eq`] trait, changes while it is in the map. This is normally only
3232
/// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
33-
/// The behavior resulting from such a logic error is not specified, but will
33+
///
34+
/// The behavior resulting from either logic error is not specified, but will
3435
/// be encapsulated to the `HashSet` that observed the logic error and not
3536
/// result in undefined behavior. This could include panics, incorrect results,
3637
/// aborts, memory leaks, and non-termination.

0 commit comments

Comments
 (0)