Skip to content

Commit fadc961

Browse files
mention Hash and Ord; refine description of derive
1 parent c72bb70 commit fadc961

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/core/src/clone.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,14 @@ mod uninit;
153153
/// Standard library collections such as
154154
/// [`HashMap`], [`HashSet`], [`BTreeMap`], [`BTreeSet`] and [`BinaryHeap`]
155155
/// rely on their keys respecting this property for correct behavior.
156-
///
157-
/// This property is automatically satisfied when deriving both `Clone` and [`PartialEq`]
158-
/// using `#[derive(Clone, PartialEq)]` or when additionally deriving [`Eq`]
159-
/// using `#[derive(Clone, PartialEq, Eq)]`.
156+
/// Furthermore, these collections require that cloning a key preserves the outcome of the
157+
/// [`Hash`] and [`Ord`] methods. Thankfully, this follows automatically from `x.clone() == x`
158+
/// if `Hash` and `Ord` are correctly implemented according to their own requirements.
159+
///
160+
/// When deriving both `Clone` and [`PartialEq`] using `#[derive(Clone, PartialEq)]`
161+
/// or when additionally deriving [`Eq`] using `#[derive(Clone, PartialEq, Eq)]`,
162+
/// then this property is automatically upheld – provided that it is satisfied by
163+
/// the underlying types.
160164
///
161165
/// Violating this property is a logic error. The behavior resulting from a logic error is not
162166
/// specified, but users of the trait must ensure that such logic errors do *not* result in

0 commit comments

Comments
 (0)