Skip to content

Spans now derive equality #31277

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 1 commit into from
Feb 1, 2016
Merged

Conversation

DanielJCampbell
Copy link
Contributor

r? @nrc

@rust-highfive
Copy link
Contributor

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

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@petrochenkov
Copy link
Contributor

Why is this needed if derived equality is never used (but now can be used accidentally)?

@DanielJCampbell
Copy link
Contributor Author

Spans derive hashing, and are used in HashSets - I felt it strange to derive hashing and not derive equality.

}

pub fn contains(self, other: Span) -> bool {
self.lo <= other.lo && other.hi <= self.hi
}

pub fn source_equal(&self, other: &Span) -> bool {
(*self).lo == (*other).lo && (*self).hi == (*other).hi
Copy link
Contributor

Choose a reason for hiding this comment

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

The dereferencing is unnecessary. Just let autoderef do its job

@petrochenkov
Copy link
Contributor

Spans derive hashing, and are used in HashSets ... and not derive equality.

I can't check right now, but this usually means that hashes are incorrect and the hash sets work by chance.

@mitaa
Copy link
Contributor

mitaa commented Jan 29, 2016

This comment/code should probably be updated as well
https://github.com/DanielJCampbell/rust/blob/SpanEquality/src/libsyntax/errors/emitter.rs#L178-L180

@DanielJCampbell
Copy link
Contributor Author

Good catch, I'll update that in the morning.

@nrc
Copy link
Member

nrc commented Jan 31, 2016

@petrochenkov yes, without this PR hashing for spans is probably buggy. The point of this PR is to fix that so that == for spans is a structural equality test.

}

pub fn contains(self, other: Span) -> bool {
self.lo <= other.lo && other.hi <= self.hi
}

pub fn source_equal(&self, other: &Span) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment stating when to use this vs when to use ==

@DanielJCampbell
Copy link
Contributor Author

Suggested changes made

@nrc
Copy link
Member

nrc commented Feb 1, 2016

@bors: r+

@bors
Copy link
Collaborator

bors commented Feb 1, 2016

📌 Commit e1be504 has been approved by nrc

bors added a commit that referenced this pull request Feb 1, 2016
@bors
Copy link
Collaborator

bors commented Feb 1, 2016

⌛ Testing commit e1be504 with merge aaab14d...

@bors bors merged commit e1be504 into rust-lang:master Feb 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants