1
Fork 0

Rollup merge of #76846 - botika:master, r=davidtwco

Avoiding unnecesary allocations at rustc_errors

Simplify the code avoiding allocations with easy alternative
This commit is contained in:
Ralf Jung 2020-09-21 10:40:30 +02:00 committed by GitHub
commit c2d9af68a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 21 deletions

View file

@ -1227,18 +1227,14 @@ impl EmitterWriter {
} }
draw_note_separator(&mut buffer, 0, max_line_num_len + 1); draw_note_separator(&mut buffer, 0, max_line_num_len + 1);
if *level != Level::FailureNote { if *level != Level::FailureNote {
let level_str = level.to_string(); buffer.append(0, level.to_str(), Style::MainHeaderMsg);
if !level_str.is_empty() { buffer.append(0, ": ", Style::NoStyle);
buffer.append(0, &level_str, Style::MainHeaderMsg);
buffer.append(0, ": ", Style::NoStyle);
}
} }
self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None); self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None);
} else { } else {
let level_str = level.to_string();
// The failure note level itself does not provide any useful diagnostic information // The failure note level itself does not provide any useful diagnostic information
if *level != Level::FailureNote && !level_str.is_empty() { if *level != Level::FailureNote {
buffer.append(0, &level_str, Style::Level(*level)); buffer.append(0, level.to_str(), Style::Level(*level));
} }
// only render error codes, not lint codes // only render error codes, not lint codes
if let Some(DiagnosticId::Error(ref code)) = *code { if let Some(DiagnosticId::Error(ref code)) = *code {
@ -1246,7 +1242,7 @@ impl EmitterWriter {
buffer.append(0, &code, Style::Level(*level)); buffer.append(0, &code, Style::Level(*level));
buffer.append(0, "]", Style::Level(*level)); buffer.append(0, "]", Style::Level(*level));
} }
if *level != Level::FailureNote && !level_str.is_empty() { if *level != Level::FailureNote {
buffer.append(0, ": ", header_style); buffer.append(0, ": ", header_style);
} }
for &(ref text, _) in msg.iter() { for &(ref text, _) in msg.iter() {
@ -1548,11 +1544,9 @@ impl EmitterWriter {
let mut buffer = StyledBuffer::new(); let mut buffer = StyledBuffer::new();
// Render the suggestion message // Render the suggestion message
let level_str = level.to_string(); buffer.append(0, level.to_str(), Style::Level(*level));
if !level_str.is_empty() { buffer.append(0, ": ", Style::HeaderMsg);
buffer.append(0, &level_str, Style::Level(*level));
buffer.append(0, ": ", Style::HeaderMsg);
}
self.msg_to_buffer( self.msg_to_buffer(
&mut buffer, &mut buffer,
&[(suggestion.msg.to_owned(), Style::NoStyle)], &[(suggestion.msg.to_owned(), Style::NoStyle)],

View file

@ -973,16 +973,14 @@ impl HandlerInner {
fn panic_if_treat_err_as_bug(&self) { fn panic_if_treat_err_as_bug(&self) {
if self.treat_err_as_bug() { if self.treat_err_as_bug() {
let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) { match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
(0, _) => return, (1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
(1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(), (0, _) | (1, _) => {}
(1, _) => return, (count, as_bug) => panic!(
(count, as_bug) => format!(
"aborting after {} errors due to `-Z treat-err-as-bug={}`", "aborting after {} errors due to `-Z treat-err-as-bug={}`",
count, as_bug, count, as_bug,
), ),
}; }
panic!(s);
} }
} }
} }