review comment: deduplicate logic

This commit is contained in:
Esteban Küber 2019-10-24 15:44:43 -07:00
parent 0baf61bfdb
commit 508d032647

View file

@ -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);
@ -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