diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-02-01 11:51:49 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-02-01 11:51:49 -0800 |
| commit | aaec60836761da35a8d0cf6179769eb9bc9f63c3 (patch) | |
| tree | ba16a12cb639464d40d9a97470ee6afe1bf297b6 /src/libsyntax_pos | |
| parent | bacb5c58dfdde7c35e99b2b0d8171238cc33cf6c (diff) | |
| download | rust-aaec60836761da35a8d0cf6179769eb9bc9f63c3.tar.gz rust-aaec60836761da35a8d0cf6179769eb9bc9f63c3.zip | |
Minimize weird spans involving macro context
Sometimes the parser attempts to synthesize spans from within a macro context with the span for the captured argument, leading to non-sensical spans with very bad output. Given that an incorrect span is worse than a partially incomplete span, when detecting this situation return only one of the spans without mergin them.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 85f0925b982..09e2677eed6 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -361,13 +361,24 @@ impl Span { /// Return a `Span` that would enclose both `self` and `end`. pub fn to(self, end: Span) -> Span { - let span = self.data(); - let end = end.data(); + let span_data = self.data(); + let end_data = end.data(); + // FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480) + // Return the macro span on its own to avoid weird diagnostic output. It is preferable to + // have an incomplete span than a completely nonsensical one. + if span_data.ctxt != end_data.ctxt { + if span_data.ctxt == SyntaxContext::empty() { + return end; + } else if end_data.ctxt == SyntaxContext::empty() { + return self; + } + // both span fall within a macro + // FIXME(estebank) check if it is the *same* macro + } Span::new( - cmp::min(span.lo, end.lo), - cmp::max(span.hi, end.hi), - // FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480) - if span.ctxt == SyntaxContext::empty() { end.ctxt } else { span.ctxt }, + cmp::min(span_data.lo, end_data.lo), + cmp::max(span_data.hi, end_data.hi), + if span_data.ctxt == SyntaxContext::empty() { end_data.ctxt } else { span_data.ctxt }, ) } |
