Skip to content

Commit 99b1054

Browse files
committed
Anonymize remaining line numbers at line starts
1 parent e650eef commit 99b1054

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/librustc_errors/emitter.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ impl EmitterWriter {
193193
Self { ui_testing, ..self }
194194
}
195195

196+
fn maybe_anonymized(&self, line_num: usize) -> String {
197+
if self.ui_testing {
198+
ANONYMIZED_LINE_NUM.to_string()
199+
} else {
200+
line_num.to_string()
201+
}
202+
}
203+
196204
fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
197205
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
198206
file: Rc<FileMap>,
@@ -344,14 +352,9 @@ impl EmitterWriter {
344352

345353
// First create the source line we will highlight.
346354
buffer.puts(line_offset, code_offset, &source_string, Style::Quotation);
347-
let line_index = if self.ui_testing {
348-
ANONYMIZED_LINE_NUM.to_string()
349-
} else {
350-
line.line_index.to_string()
351-
};
352355
buffer.puts(line_offset,
353356
0,
354-
&line_index,
357+
&self.maybe_anonymized(line.line_index),
355358
Style::LineNumber);
356359

357360
draw_col_separator(buffer, line_offset, width_offset - 2);
@@ -1174,8 +1177,8 @@ impl EmitterWriter {
11741177

11751178
buffer.puts(last_buffer_line_num,
11761179
0,
1177-
&(annotated_file.lines[line_idx + 1].line_index - 1)
1178-
.to_string(),
1180+
&self.maybe_anonymized(annotated_file.lines[line_idx + 1]
1181+
.line_index - 1),
11791182
Style::LineNumber);
11801183
draw_col_separator(&mut buffer,
11811184
last_buffer_line_num,
@@ -1250,7 +1253,7 @@ impl EmitterWriter {
12501253
// Print the span column to avoid confusion
12511254
buffer.puts(row_num,
12521255
0,
1253-
&((line_start + line_pos).to_string()),
1256+
&self.maybe_anonymized(line_start + line_pos),
12541257
Style::LineNumber);
12551258
// print the suggestion
12561259
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);

0 commit comments

Comments
 (0)