Skip to content

Commit

Permalink
Avoid the overflow with rustc+debugassertions in issue-44406
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 20, 2021
1 parent 4281380 commit c9fe093
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 23 additions & 6 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,30 @@ impl Span {
/// ^^^^^^^^^^^^^^^^^
/// ```
pub fn until(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
// Most of this function's body is copied from `to`.
// We can't just do `self.to(end.shrink_to_lo())`,
// because to also does some magic where it uses min/max so
// it can handle overlapping spans. Some advanced mis-use of
// `until` with different ctxts makes this visible.
let span_data = self.data();
let end_data = end.data();
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. 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::root() {
return end;
} else if end_data.ctxt == SyntaxContext::root() {
return self;
}
// Both spans fall within a macro.
// FIXME(estebank): check if it is the *same* macro.
}
Span::new(
span.lo,
end.lo,
if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
if span.parent == end.parent { span.parent } else { None },
span_data.lo,
end_data.lo,
if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-44406.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LL | bar { }
help: if `bar` is a function, use the arguments directly
|
LL - bar(baz: $rest)
LL + bar(true);
LL + bar(: $rest)
|

error: aborting due to 2 previous errors
Expand Down

0 comments on commit c9fe093

Please sign in to comment.