end_point handling multibyte characters correctly.

This commit is contained in:
David Wood 2018-01-14 17:29:07 +00:00
parent c6e6428d1a
commit c71cec8834
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
11 changed files with 61 additions and 35 deletions

View file

@ -216,22 +216,6 @@ impl Span {
self.data().with_ctxt(ctxt)
}
/// Returns a new span representing just the end-point of this span
pub fn end_point(self) -> Span {
let span = self.data();
// We can avoid an ICE by checking if subtraction would cause an overflow.
let hi = if span.hi.0 == u32::min_value() { span.hi.0 } else { span.hi.0 - 1 };
let lo = cmp::max(hi, span.lo.0);
span.with_lo(BytePos(lo))
}
/// Returns a new span representing the next character after the end-point of this span
pub fn next_point(self) -> Span {
let span = self.data();
let lo = cmp::max(span.hi.0, span.lo.0 + 1);
Span::new(BytePos(lo), BytePos(lo), span.ctxt)
}
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
pub fn substitute_dummy(self, other: Span) -> Span {
if self.source_equal(&DUMMY_SP) { other } else { self }