diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index ea6b39504e8..8381adaea79 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -689,6 +689,15 @@ impl CodeMap { self.span_until_char(sp, '{') } + /// Returns a new span representing just the start-point of this span + pub fn start_point(&self, sp: Span) -> Span { + let pos = sp.lo().0; + let width = self.find_width_of_character_at_span(sp, false); + let corrected_start_position = pos.checked_add(width).unwrap_or(pos); + let end_point = BytePos(cmp::max(corrected_start_position, sp.lo().0)); + sp.with_hi(end_point) + } + /// Returns a new span representing just the end-point of this span pub fn end_point(&self, sp: Span) -> Span { let pos = sp.hi().0; |
