Skip to content

Commit

Permalink
Anonymize remaining line numbers at line starts
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Feb 26, 2018
1 parent e650eef commit 99b1054
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/librustc_errors/emitter.rs
Expand Up @@ -193,6 +193,14 @@ impl EmitterWriter {
Self { ui_testing, ..self }
}

fn maybe_anonymized(&self, line_num: usize) -> String {
if self.ui_testing {
ANONYMIZED_LINE_NUM.to_string()
} else {
line_num.to_string()
}
}

fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Rc<FileMap>,
Expand Down Expand Up @@ -344,14 +352,9 @@ impl EmitterWriter {

// First create the source line we will highlight.
buffer.puts(line_offset, code_offset, &source_string, Style::Quotation);
let line_index = if self.ui_testing {
ANONYMIZED_LINE_NUM.to_string()
} else {
line.line_index.to_string()
};
buffer.puts(line_offset,
0,
&line_index,
&self.maybe_anonymized(line.line_index),
Style::LineNumber);

draw_col_separator(buffer, line_offset, width_offset - 2);
Expand Down Expand Up @@ -1174,8 +1177,8 @@ impl EmitterWriter {

buffer.puts(last_buffer_line_num,
0,
&(annotated_file.lines[line_idx + 1].line_index - 1)
.to_string(),
&self.maybe_anonymized(annotated_file.lines[line_idx + 1]
.line_index - 1),
Style::LineNumber);
draw_col_separator(&mut buffer,
last_buffer_line_num,
Expand Down Expand Up @@ -1250,7 +1253,7 @@ impl EmitterWriter {
// Print the span column to avoid confusion
buffer.puts(row_num,
0,
&((line_start + line_pos).to_string()),
&self.maybe_anonymized(line_start + line_pos),
Style::LineNumber);
// print the suggestion
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
Expand Down

0 comments on commit 99b1054

Please sign in to comment.