From f46fe1b207ba66cd119801e89e0c203cc6565f47 Mon Sep 17 00:00:00 2001 From: nzrq <42440961+nzrq@users.noreply.github.com> Date: Fri, 3 Jun 2022 13:05:57 -0400 Subject: [PATCH 1/4] Add note to documentation of HashSet::intersection --- std/src/collections/hash/set.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/std/src/collections/hash/set.rs b/std/src/collections/hash/set.rs index 19428fe9a..6ca4b7fa2 100644 --- a/std/src/collections/hash/set.rs +++ b/std/src/collections/hash/set.rs @@ -588,6 +588,13 @@ where /// Visits the values representing the intersection, /// i.e., the values that are both in `self` and `other`. /// + /// Note: this operation does not guarantee which collection + /// is visited from `self` or `other`. This has consequences + /// for values which may be defined as equal by the `Eq` trait + /// but which are not physically equivalent (eg. they may have + /// fields which differ or do not participate in the definition + /// of equivalence). + /// /// # Examples /// /// ``` From 0c504505c1c31ae1a755b22c285a12bce2d3f80a Mon Sep 17 00:00:00 2001 From: nzrq <42440961+nzrq@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:34:15 -0400 Subject: [PATCH 2/4] Update set.rs --- std/src/collections/hash/set.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/std/src/collections/hash/set.rs b/std/src/collections/hash/set.rs index 6ca4b7fa2..de1431b1d 100644 --- a/std/src/collections/hash/set.rs +++ b/std/src/collections/hash/set.rs @@ -588,12 +588,10 @@ where /// Visits the values representing the intersection, /// i.e., the values that are both in `self` and `other`. /// - /// Note: this operation does not guarantee which collection - /// is visited from `self` or `other`. This has consequences - /// for values which may be defined as equal by the `Eq` trait - /// but which are not physically equivalent (eg. they may have - /// fields which differ or do not participate in the definition - /// of equivalence). + /// Note: When an equal element is present in `self` and `other` + /// then the resulting `Intersection` may yield references to + /// one or the other, which will be visible in properties of `T` + /// not participating in the `Eq` implementation. /// /// # Examples /// From da7895002d84b1b6d3df0a1fa540d0fe4e85c38a Mon Sep 17 00:00:00 2001 From: nzrq <42440961+nzrq@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:03:55 -0400 Subject: [PATCH 3/4] Update library/std/src/collections/hash/set.rs Co-authored-by: David Tolnay --- std/src/collections/hash/set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/src/collections/hash/set.rs b/std/src/collections/hash/set.rs index de1431b1d..0a0c08eb1 100644 --- a/std/src/collections/hash/set.rs +++ b/std/src/collections/hash/set.rs @@ -588,7 +588,7 @@ where /// Visits the values representing the intersection, /// i.e., the values that are both in `self` and `other`. /// - /// Note: When an equal element is present in `self` and `other` + /// When an equal element is present in `self` and `other` /// then the resulting `Intersection` may yield references to /// one or the other, which will be visible in properties of `T` /// not participating in the `Eq` implementation. From 6d9498f98c9abb5eeeb6a29949286165e870d26b Mon Sep 17 00:00:00 2001 From: nzrq <42440961+nzrq@users.noreply.github.com> Date: Mon, 6 Jun 2022 17:14:58 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: David Tolnay --- std/src/collections/hash/set.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/std/src/collections/hash/set.rs b/std/src/collections/hash/set.rs index 0a0c08eb1..fa498a987 100644 --- a/std/src/collections/hash/set.rs +++ b/std/src/collections/hash/set.rs @@ -590,8 +590,9 @@ where /// /// When an equal element is present in `self` and `other` /// then the resulting `Intersection` may yield references to - /// one or the other, which will be visible in properties of `T` - /// not participating in the `Eq` implementation. + /// one or the other. This can be relevant if `T` contains fields which + /// are not compared by its `Eq` implementation, and may hold different + /// value between the two equal copies of `T` in the two sets. /// /// # Examples ///