summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-22 22:44:39 +0100
committerGitHub <noreply@github.com>2023-03-22 22:44:39 +0100
commit34fa6daa5ce0c64cca205263abcd32a2c6cf068d (patch)
tree7e237feae45154be505b1961b36484382bd1a77d /compiler/rustc_span/src
parent0392e2996e828fe5f435b3f13037f8af7ad4563b (diff)
parent05b5046633e9f594f955e0365a1219d1a96a5b54 (diff)
downloadrust-34fa6daa5ce0c64cca205263abcd32a2c6cf068d.tar.gz
rust-34fa6daa5ce0c64cca205263abcd32a2c6cf068d.zip
Rollup merge of #109203 - Ezrashaw:refactor-ident-parsing, r=Nilstrieb
refactor/feat: refactor identifier parsing a bit

\+ error recovery for `expected_ident_found`

Prior art: #108854
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/lib.rs12
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":