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 the ability to merge spans to codemap #36585

Merged
merged 2 commits into from
Sep 22, 2016

Conversation

sophiajt
Copy link
Contributor

This PR adds the ability to merge Spans. To do so, it builds on the Codemap's ability to verify the locations of spans, namely that following can be verified:

  • the expn_id of both spans much match
  • the lhs span needs to end on the same line the rhs span begins
  • the lhs span must start at or before the rhs span

If all of these are met, a new span is returned that is min(lo), max(hi) of the two spans.

This PR also removes an older Span merge, as this new functionality subsumes it.

r? @nrc

if let Some(_) = cm.merge_spans(span1, span2) {
assert!(false);
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

nit: no new line here

Copy link
Member

Choose a reason for hiding this comment

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

In fact you don't need the else branch at all, and you can use panic!() instead of assert!(false)

Copy link
Member

Choose a reason for hiding this comment

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

or assert!(cm.merge_spans(span1, span2).is_none())

/// For this to work, the spans have to be:
/// * the expn_id of both spans much match
/// * the lhs span needs to end on the same line the rhs span begins
/// * the lhs span must start at or before the rhs span
Copy link
Member

Choose a reason for hiding this comment

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

Do you expect spans to overlap sometimes? The only time I would expect that is if one is strictly larger than the other, in which case maybe this method shouldn't be used. If you agree, you could be stricter and require the sp.lhs.hi < sp.rhs.lo, rather than comparing both los

@sophiajt
Copy link
Contributor Author

@nrc - comments addressed. I check for overlap now. Simplified the negative unit test also.

@sophiajt
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Sep 20, 2016

📌 Commit e4b1842 has been approved by nrc

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 21, 2016
…, r=nrc

Add the ability to merge spans to codemap

This PR adds the ability to merge Spans.  To do so, it builds on the Codemap's ability to verify the locations of spans, namely that following can be verified:

* the expn_id of both spans much match
* the lhs span needs to end on the same line the rhs span begins
* the lhs span must start at or before the rhs span

If all of these are met, a new span is returned that is min(lo), max(hi) of the two spans.

This PR also removes an older Span merge, as this new functionality subsumes it.

r? @nrc
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 21, 2016
…, r=nrc

Add the ability to merge spans to codemap

This PR adds the ability to merge Spans.  To do so, it builds on the Codemap's ability to verify the locations of spans, namely that following can be verified:

* the expn_id of both spans much match
* the lhs span needs to end on the same line the rhs span begins
* the lhs span must start at or before the rhs span

If all of these are met, a new span is returned that is min(lo), max(hi) of the two spans.

This PR also removes an older Span merge, as this new functionality subsumes it.

r? @nrc
bors added a commit that referenced this pull request Sep 22, 2016
Add the ability to merge spans to codemap

This PR adds the ability to merge Spans.  To do so, it builds on the Codemap's ability to verify the locations of spans, namely that following can be verified:

* the expn_id of both spans much match
* the lhs span needs to end on the same line the rhs span begins
* the lhs span must start at or before the rhs span

If all of these are met, a new span is returned that is min(lo), max(hi) of the two spans.

This PR also removes an older Span merge, as this new functionality subsumes it.

r? @nrc
@bors
Copy link
Contributor

bors commented Sep 22, 2016

⌛ Testing commit e4b1842 with merge 6ad1084...

@bors bors merged commit e4b1842 into rust-lang:master Sep 22, 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.

3 participants