diff options
| author | Ezra Shaw <ezrasure@outlook.com> | 2023-03-17 21:41:26 +1300 |
|---|---|---|
| committer | Ezra Shaw <ezrasure@outlook.com> | 2023-03-19 20:24:06 +1300 |
| commit | b4e17a5098f0413b01c90c8505e0f01e8bea50de (patch) | |
| tree | 48ec7d45ab5f0608ee1ffaadcbf360efceb67ad1 /compiler/rustc_span/src | |
| parent | c9ddb73184290e0698060a80b0b5727d6ee11098 (diff) | |
| download | rust-b4e17a5098f0413b01c90c8505e0f01e8bea50de.tar.gz rust-b4e17a5098f0413b01c90c8505e0f01e8bea50de.zip | |
refactor: improve "ident starts with number" error
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 873cd33f6a4..02cffc762be 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -795,6 +795,18 @@ impl Span { }) } + /// Splits a span into two composite spans around a certain position. + pub fn split_at(self, pos: u32) -> (Span, Span) { + let len = self.hi().0 - self.lo().0; + debug_assert!(pos <= len); + + let split_pos = BytePos(self.lo().0 + pos); + ( + Span::new(self.lo(), split_pos, self.ctxt(), self.parent()), + Span::new(split_pos, self.hi(), self.ctxt(), self.parent()), + ) + } + /// Returns a `Span` that would enclose both `self` and `end`. /// /// Note that this can also be used to extend the span "backwards": |
