Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note to documentation of HashSet::intersection #97700

Merged
merged 4 commits into from
Jun 7, 2022
Merged

Conversation

nzrq
Copy link
Contributor

@nzrq nzrq commented Jun 3, 2022

The functionality of the std::collections::HashSet::intersection(...) method was slightly surprising to me so I wanted to take a sec to contribute to the documentation for this method.

I've added a Note: section if that is appropriate.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 3, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 3, 2022
@thomcc
Copy link
Member

thomcc commented Jun 3, 2022

Ignore me.

Hm. While I don't think I'd encourage writing code that relied on this, the current implementation always provides items from self (and this is true of the BTreeSet::intersection function as well).

This behavior is consistent and possible to observe this with a totally reasonable Eq implementation1, so even if I would personally prefer it be unspecified2, I would not be surprised at all if people relied on this already (and I might even lean towards saying it's already de-facto specified because it's consistent, observable, and (probably) not really worth changing...)

But either way, it's not up to me. I think this needs an explicit T-libs-api decision.

r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs

Footnotes

  1. ISTM that none of the requirements in the documentation of Eq indicate that it is invalid for an Eq impl to only consider a subset of fields.

  2. For example, I think it would likely be faster to iterate over (and yield elements from) whichever set is smaller, (for example, it would perform fewer lookups, which may be more efficient). That said, this sounds... situational at best, so IDK if I really think it's worth risking breakage over.

@rust-highfive rust-highfive assigned dtolnay and unassigned thomcc Jun 3, 2022
@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 3, 2022
@thomcc
Copy link
Member

thomcc commented Jun 3, 2022

CC @Amanieu (who might have stronger opinions about the things we may want to promise here).

@thomcc thomcc added the A-collections Area: std::collections. label Jun 3, 2022
@the8472
Copy link
Member

the8472 commented Jun 3, 2022

Hm. While I don't think I'd encourage writing code that relied on this, the current implementation always provides items from self (and this is true of the BTreeSet::intersection function as well).

😕❓

if self.len() <= other.len() {
Intersection { iter: self.iter(), other }
} else {
Intersection { iter: other.iter(), other: self }
}

@thomcc
Copy link
Member

thomcc commented Jun 3, 2022

Wow, yep, my bad, I'm not sure what I was even looking at (... probably my lunch). So I don't think this needs API decision, although the currently assigned reviewer can take it.

@the8472 the8472 added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 4, 2022
library/std/src/collections/hash/set.rs Outdated Show resolved Hide resolved
library/std/src/collections/hash/set.rs Outdated Show resolved Hide resolved
nzrq and others added 2 commits June 4, 2022 20:03
Co-authored-by: David Tolnay <dtolnay@gmail.com>
Co-authored-by: David Tolnay <dtolnay@gmail.com>
@nzrq nzrq requested a review from dtolnay June 6, 2022 21:15
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Jun 6, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 6, 2022

📌 Commit 7d114c7 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 6, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 6, 2022
…askrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#97700 (Add note to documentation of HashSet::intersection)
 - rust-lang#97792 (More eslint checks)
 - rust-lang#97794 (Fix typo in redundant_pattern_match.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c4bfd10 into rust-lang:master Jun 7, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: std::collections. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants