about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/styled_buffer.rs
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-03-14 16:08:03 +0800
committerGitHub <noreply@github.com>2025-03-14 16:08:03 +0800
commit3d9bf08289176c2185aee3a7a864e165f1717af4 (patch)
tree478858b36091b857f8213f72f15ae300e41d963d /compiler/rustc_errors/src/styled_buffer.rs
parenta863f2c6b22a6bc7b9a85d7e7ff0534ab0e10a05 (diff)
parent7bde17630561c8df94676cb6950b27c648de0e54 (diff)
downloadrust-3d9bf08289176c2185aee3a7a864e165f1717af4.tar.gz
rust-3d9bf08289176c2185aee3a7a864e165f1717af4.zip
Merge pull request #2283 from jieyouxu/sync
Rustc pull
Diffstat (limited to 'compiler/rustc_errors/src/styled_buffer.rs')
-rw-r--r--compiler/rustc_errors/src/styled_buffer.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/styled_buffer.rs b/compiler/rustc_errors/src/styled_buffer.rs
index 5ca9e9b18f3..790efd0286e 100644
--- a/compiler/rustc_errors/src/styled_buffer.rs
+++ b/compiler/rustc_errors/src/styled_buffer.rs
@@ -89,6 +89,19 @@ impl StyledBuffer {
         }
     }
 
+    pub(crate) fn replace(&mut self, line: usize, start: usize, end: usize, string: &str) {
+        if start == end {
+            return;
+        }
+        if start > self.lines[line].len() || end > self.lines[line].len() {
+            return;
+        }
+        let _ = self.lines[line].drain(start..(end - string.chars().count()));
+        for (i, c) in string.chars().enumerate() {
+            self.lines[line][start + i] = StyledChar::new(c, Style::LineNumber);
+        }
+    }
+
     /// For given `line` inserts `string` with `style` before old content of that line,
     /// adding lines if needed
     pub(crate) fn prepend(&mut self, line: usize, string: &str, style: Style) {