diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2021-01-31 15:21:28 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2021-01-31 15:24:34 -0500 |
| commit | 6c14aad58e65c9c50faa45ed88369c5c72d6d0d7 (patch) | |
| tree | 4556d6d03bc8729cdd8c38d57bbfe2d48c75e386 /compiler/rustc_parse/src/parser | |
| parent | 04caa632dd10c2bf64b69524c7f9c4c30a436877 (diff) | |
| download | rust-6c14aad58e65c9c50faa45ed88369c5c72d6d0d7.tar.gz rust-6c14aad58e65c9c50faa45ed88369c5c72d6d0d7.zip | |
Improve handling of spans around macro result parse errors
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: * 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
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f2fcce5c226..5512e849c45 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1104,7 +1104,7 @@ impl<'a> Parser<'a> { let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) { // Point at the end of the macro call when reaching end of macro arguments. (token::Eof, Some(_)) => { - let sp = self.sess.source_map().next_point(self.token.span); + let sp = self.sess.source_map().next_point(self.prev_token.span); (sp, sp) } // We don't want to point at the following span after DUMMY_SP. @@ -1721,7 +1721,7 @@ impl<'a> Parser<'a> { pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> { let (span, msg) = match (&self.token.kind, self.subparser_name) { (&token::Eof, Some(origin)) => { - let sp = self.sess.source_map().next_point(self.token.span); + let sp = self.sess.source_map().next_point(self.prev_token.span); (sp, format!("expected expression, found end of {}", origin)) } _ => ( |
