Improve handling of spans around macro result parse errors#81608
Merged
bors merged 1 commit intorust-lang:masterfrom Feb 2, 2021
Merged
Improve handling of spans around macro result parse errors#81608bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Fixes rust-lang#81543 After we expand a macro, we try to parse the resulting tokens as a AST node. This commit makes several improvements to how we handle spans when an error occurs: * Only ovewrite the original `Span` if it's a dummy span. This preserves a more-specific span if one is available. * Use `self.prev_token` instead of `self.token` when emitting an error message after encountering EOF, since an EOF token always has a dummy span * Make `SourceMap::next_point` leave dummy spans unused. A dummy span does not have a logical 'next point', since it's a zero-length span. Re-using the span span preserves its 'dummy-ness' for other checks
Contributor
|
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
davidtwco
approved these changes
Feb 1, 2021
Member
|
@bors r+ |
Collaborator
|
📌 Commit 6c14aad has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 2, 2021
…as-schievink Rollup of 11 pull requests Successful merges: - rust-lang#80629 (Add lint for 2229 migrations) - rust-lang#81022 (Add Frames Iterator for Backtrace) - rust-lang#81481 (move some tests) - rust-lang#81485 (Add some tests for associated-type-bounds issues) - rust-lang#81492 (rustdoc: Note why `rustdoc::html::markdown` is public) - rust-lang#81577 (const_evaluatable: consider sub-expressions to be evaluatable) - rust-lang#81599 (Implement `TrustedLen` for `Fuse<I: TrustedLen>`) - rust-lang#81608 (Improve handling of spans around macro result parse errors) - rust-lang#81609 (Remove the remains of query categories) - rust-lang#81630 (Fix overflowing text on mobile when sidebar is displayed) - rust-lang#81631 (Remove unneeded `mut` variable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #81543
After we expand a macro, we try to parse the resulting tokens as a AST
node. This commit makes several improvements to how we handle spans when
an error occurs:
Spanif it's a dummy span. This preservesa more-specific span if one is available.
self.prev_tokeninstead ofself.tokenwhen emitting an errormessage after encountering EOF, since an EOF token always has a dummy
span
SourceMap::next_pointleave dummy spans unused. A dummy spandoes not have a logical 'next point', since it's a zero-length span.
Re-using the span span preserves its 'dummy-ness' for other checks