From 2ea9e04bf71e85746453b26d3bebe4d0400b7421 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 --- library/std/src/collections/hash/set.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 19428fe9a23..6ca4b7fa2d9 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/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 fdd8b6229e3fea8d29c2262a123df05123797040 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 --- library/std/src/collections/hash/set.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 6ca4b7fa2d9..de1431b1dba 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/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 fc4e8c7f0d4611a4fce40b0e991c03fbe349af04 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 --- library/std/src/collections/hash/set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index de1431b1dba..0a0c08eb1e9 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/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 7d114c7713537af3a1f67c15a67473e6f3f5a509 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 --- library/std/src/collections/hash/set.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 0a0c08eb1e9..fa498a987d6 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/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 ///