Skip to content

Commit 52d1193

Browse files
committed
Anonymize remaining line numbers at line starts
1 parent 4fd765b commit 52d1193

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/librustc_errors/emitter.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ impl EmitterWriter {
162162
Self { ui_testing, ..self }
163163
}
164164

165+
fn maybe_anonymized(&self, line_num: usize) -> String {
166+
if self.ui_testing {
167+
ANONYMIZED_LINE_NUM.to_string()
168+
} else {
169+
line_num.to_string()
170+
}
171+
}
172+
165173
fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
166174
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
167175
file: Rc<FileMap>,
@@ -313,14 +321,9 @@ impl EmitterWriter {
313321

314322
// First create the source line we will highlight.
315323
buffer.puts(line_offset, code_offset, &source_string, Style::Quotation);
316-
let line_index = if self.ui_testing {
317-
ANONYMIZED_LINE_NUM.to_string()
318-
} else {
319-
line.line_index.to_string()
320-
};
321324
buffer.puts(line_offset,
322325
0,
323-
&line_index,
326+
&self.maybe_anonymized(line.line_index),
324327
Style::LineNumber);
325328

326329
draw_col_separator(buffer, line_offset, width_offset - 2);
@@ -1141,8 +1144,8 @@ impl EmitterWriter {
11411144

11421145
buffer.puts(last_buffer_line_num,
11431146
0,
1144-
&(annotated_file.lines[line_idx + 1].line_index - 1)
1145-
.to_string(),
1147+
&self.maybe_anonymized(annotated_file.lines[line_idx + 1]
1148+
.line_index - 1),
11461149
Style::LineNumber);
11471150
draw_col_separator(&mut buffer,
11481151
last_buffer_line_num,
@@ -1216,7 +1219,7 @@ impl EmitterWriter {
12161219
// Print the span column to avoid confusion
12171220
buffer.puts(row_num,
12181221
0,
1219-
&((line_start + line_pos).to_string()),
1222+
&self.maybe_anonymized(line_start + line_pos),
12201223
Style::LineNumber);
12211224
// print the suggestion
12221225
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);

0 commit comments

Comments
 (0)