-
Notifications
You must be signed in to change notification settings - Fork 13.6k
document assumptions about Clone
and Eq
traits
#144330
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
30033b4
document assumptions about `Clone` and `Eq` traits
gewitternacht cdbcd72
remove trailing whitespace
gewitternacht 623317e
add links to collections
gewitternacht c72bb70
clearer wording for `unsafe` code
gewitternacht fadc961
mention `Hash` and `Ord`; refine description of `derive`
gewitternacht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear whether this should apply to
PartialEq
.However this definitely needs to be extended to include
Hash
andOrd
sinceHashMap
andBTreeMap
rely on this. It could also have vague wording that this may extend to other traits as well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean this in the sense that the property cannot be required of
PartialEq
andClone
as we might have to deliberalty break it in some contexts? Or in the sense that we just don't know of anything that depends on this property forPartialEq
?In case of the latter, I would argue that the documentation of
Clone
– "creation of a duplicate value" – very strongly suggests that I get the "same" thing by cloning, andPartialEq
defines "sameness" of objects. E.g., iff == 1.0_f64
, I expect thatf.clone() == 1.0_f64
, too. But without the propertyx == x -> x.clone() == x
, this is never explicitly guaranteed anywhere.I only wrote about
PartialEq
/Eq
becausex.clone() == x
already ensures thatclone
preserves the hash and ordering of elements, when put together with the guarantees that are required ofHash
(see "Hash
andEq
") andOrd
(due to the conditions forPartialOrd
). But I could make this interaction explicit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it, you are correct and
PartialEq
is the right place to introduce this requirement.