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

improve span of erroneous empty macro invocation #27584

Merged
merged 2 commits into from
Aug 12, 2015

Conversation

TimNN
Copy link
Contributor

@TimNN TimNN commented Aug 7, 2015

The ideas is to use the span of the complete macro invocation if the span of a macro error is DUMMY_SP.

fixes #7970

The ideas is to use the span of the complete macro invocation if the span of a
macro error is `DUMMY_SP`.

fixes rust-lang#7970
@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 @huonw (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. 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.

@TimNN TimNN closed this Aug 7, 2015
@TimNN TimNN deleted the macro-eof-span branch August 7, 2015 15:53
@TimNN TimNN restored the macro-eof-span branch August 7, 2015 15:53
@TimNN
Copy link
Contributor Author

TimNN commented Aug 7, 2015

Don't know how this got closed, but it shouldn't be.

@TimNN TimNN reopened this Aug 7, 2015
@@ -249,22 +249,6 @@ pub enum ParseResult<T> {
pub type NamedParseResult = ParseResult<HashMap<Ident, Rc<NamedMatch>>>;
pub type PositionalParseResult = ParseResult<Vec<Rc<NamedMatch>>>;

pub fn parse_or_else(sess: &ParseSess,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this function could be changed to take in a substitute_span: Span and have the DUMMY_SP comparison internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I choose to remove it because

  1. It was only called in one place
  2. It only forwarded it's arguments to parse and panicked on failure

Taking this into account I don't think the existence of this function is really justified, especially since I would have had to add another parameter to it.

Copy link
Member

Choose a reason for hiding this comment

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

Your reasoning sounds good to me.

@huonw
Copy link
Member

huonw commented Aug 10, 2015

I wonder if Span could get a method:

fn substitute_dummy(self, other: Span) -> Span {
    if *self == DUMMY_SP { other } else { *self }
}

Which can be used like:

Error(err_sp, ref msg) => panic!(cx.span_fatal(err_sp.substitute_dummy(sp), msg))

@huonw
Copy link
Member

huonw commented Aug 10, 2015

Thanks for tackling this, it's definitely annoying.

@TimNN
Copy link
Contributor Author

TimNN commented Aug 10, 2015

Regarding substitute_dummy, I've gone over all the other DUMMY_SP usages, and such a method would only be useful in two other places:

which again does not seem to justify adding such a method to me.

@huonw
Copy link
Member

huonw commented Aug 10, 2015

Your choice, but I do think abstracting out this pattern is a good way to encourage avoiding printing DUMMY_SP even if it isn't used that much right now (even 3 uses seems like enough to justify it for me).

@TimNN
Copy link
Contributor Author

TimNN commented Aug 10, 2015

Alright, should I add the method and change the other usages in this pull request or does that require another?

@huonw
Copy link
Member

huonw commented Aug 10, 2015

I think doing it in this PR is fine.

@TimNN
Copy link
Contributor Author

TimNN commented Aug 10, 2015

I added the suggested method and have to admit that the code looks cleaner that way :)

@huonw
Copy link
Member

huonw commented Aug 10, 2015

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Aug 10, 2015

📌 Commit d46e840 has been approved by huonw

Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 11, 2015
The ideas is to use the span of the complete macro invocation if the span of a macro error is `DUMMY_SP`.

fixes rust-lang#7970
@bors
Copy link
Contributor

bors commented Aug 11, 2015

⌛ Testing commit d46e840 with merge 58b0aa5...

bors added a commit that referenced this pull request Aug 11, 2015
The ideas is to use the span of the complete macro invocation if the span of a macro error is `DUMMY_SP`.

fixes #7970
@bors
Copy link
Contributor

bors commented Aug 12, 2015

💔 Test failed - auto-linux-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Tue, Aug 11, 2015 at 5:39 PM, bors [email protected] wrote:

[image: 💔] Test failed - auto-linux-32-opt
http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/6069


Reply to this email directly or view it on GitHub
#27584 (comment).

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.

Span for "unexpected end of macro invocation" is terrible
5 participants