Skip to content

Commit

Permalink
review comment: deduplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 24, 2019
1 parent 0baf61b commit 508d032
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,27 +1583,26 @@ impl EmitterWriter {
Ok(())
}

fn emit_messages_default(&mut self,
level: &Level,
message: &[(String, Style)],
code: &Option<DiagnosticId>,
span: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion]) {
fn emit_messages_default(
&mut self,
level: &Level,
message: &[(String, Style)],
code: &Option<DiagnosticId>,
span: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion],
) {
let max_line_num_len = if self.ui_testing {
ANONYMIZED_LINE_NUM.len()
} else {
self.get_max_line_num(span, children).to_string().len()
};

match self.emit_message_default(span,
message,
code,
level,
max_line_num_len,
false) {
match self.emit_message_default(span, message, code, level, max_line_num_len, false) {
Ok(()) => {
if !children.is_empty() {
if !children.is_empty() || suggestions.iter().any(|s| {
s.style != SuggestionStyle::CompletelyHidden
}) {
let mut buffer = StyledBuffer::new();
if !self.short_message {
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
Expand All @@ -1629,19 +1628,6 @@ impl EmitterWriter {
_ => ()
}
}
if children.is_empty() && suggestions.iter().any(|s| {
s.style != SuggestionStyle::CompletelyHidden
}) {
let mut buffer = StyledBuffer::new();
if !self.short_message {
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
}
match emit_to_destination(&buffer.render(), level, &mut self.dst,
self.short_message) {
Ok(()) => (),
Err(e) => panic!("failed to emit error: {}", e)
}
}
for sugg in suggestions {
if sugg.style == SuggestionStyle::CompletelyHidden {
// do not display this suggestion, it is meant only for tools
Expand Down

0 comments on commit 508d032

Please sign in to comment.