From 6c14aad58e65c9c50faa45ed88369c5c72d6d0d7 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 31 Jan 2021 15:21:28 -0500 Subject: 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 --- compiler/rustc_span/src/source_map.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'compiler/rustc_span/src') diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 4e0ce0d344d..2b429372dcf 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -799,6 +799,9 @@ impl SourceMap { /// Returns a new span representing the next character after the end-point of this span. pub fn next_point(&self, sp: Span) -> Span { + if sp.is_dummy() { + return sp; + } let start_of_next_point = sp.hi().0; let width = self.find_width_of_character_at_span(sp.shrink_to_hi(), true); -- cgit 1.4.1-3-g733a5