Skip to content

Commit

Permalink
revert "Add rustc --explain back"
Browse files Browse the repository at this point in the history
This reverts commit 9b597a1. That
commit added a message informing users about the `rustc --explain`
functionality inside of a `Drop` implementation for `EmitterWriter`. In
addition to exhibiting questionable semantics (printing a
hopefully-helpful message for the user does not seem like a "cleanup"
action), this resulted in divergent behavior between humanized output
and JSON output, because the latter actually instantiates an
`EmitterWriter` for every diagnostic.

Several conflicts in this revert commit had to be fixed manually, again
owing to code-area collision between rust-lang#48449 and rust-lang#48337.

This is in the matter of rust-lang#48550.

Conflicts:
	src/librustc_errors/emitter.rs
  • Loading branch information
zackmdavis committed Feb 28, 2018
1 parent 3ad06b3 commit 5e6cc9b
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::io::prelude::*;
use std::io;
use std::rc::Rc;
use term;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::cmp::min;
use unicode_width;

Expand Down Expand Up @@ -109,7 +109,6 @@ pub struct EmitterWriter {
cm: Option<Rc<CodeMapper>>,
short_message: bool,
teach: bool,
error_codes: HashSet<String>,
ui_testing: bool,
}

Expand All @@ -119,33 +118,6 @@ struct FileWithAnnotatedLines {
multiline_depth: usize,
}

impl Drop for EmitterWriter {
fn drop(&mut self) {
if !self.short_message && !self.error_codes.is_empty() {
let mut error_codes = self.error_codes.clone().into_iter().collect::<Vec<_>>();
error_codes.sort();
if error_codes.len() > 1 {
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
writeln!(self.dst,
"You've got a few errors: {}{}",
error_codes[..limit].join(", "),
if error_codes.len() > 9 { "..." } else { "" }
).expect("failed to give tips...");
writeln!(self.dst,
"If you want more information on an error, try using \
\"rustc --explain {}\"",
&error_codes[0]).expect("failed to give tips...");
} else {
writeln!(self.dst,
"If you want more information on this error, try using \
\"rustc --explain {}\"",
&error_codes[0]).expect("failed to give tips...");
}
self.dst.flush().expect("failed to emit errors");
}
}
}

impl EmitterWriter {
pub fn stderr(color_config: ColorConfig,
code_map: Option<Rc<CodeMapper>>,
Expand All @@ -159,7 +131,6 @@ impl EmitterWriter {
cm: code_map,
short_message,
teach,
error_codes: HashSet::new(),
ui_testing: false,
}
} else {
Expand All @@ -168,7 +139,6 @@ impl EmitterWriter {
cm: code_map,
short_message,
teach,
error_codes: HashSet::new(),
ui_testing: false,
}
}
Expand All @@ -184,7 +154,6 @@ impl EmitterWriter {
cm: code_map,
short_message,
teach,
error_codes: HashSet::new(),
ui_testing: false,
}
}
Expand Down Expand Up @@ -1025,14 +994,12 @@ impl EmitterWriter {
if primary_span != &&DUMMY_SP {
(cm.lookup_char_pos(primary_span.lo()), cm)
} else {
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
&mut self.error_codes)?;
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
return Ok(());
}
} else {
// If we don't have span information, emit and exit
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
&mut self.error_codes)?;
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
return Ok(());
};
if let Ok(pos) =
Expand Down Expand Up @@ -1205,8 +1172,7 @@ impl EmitterWriter {
}

// final step: take our styled buffer, render it, then output it
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
&mut self.error_codes)?;
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;

Ok(())

Expand Down Expand Up @@ -1294,8 +1260,7 @@ impl EmitterWriter {
let msg = format!("and {} other candidates", suggestions.len() - MAX_SUGGESTIONS);
buffer.puts(row_num, 0, &msg, Style::NoStyle);
}
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
&mut self.error_codes)?;
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
}
Ok(())
}
Expand Down Expand Up @@ -1326,7 +1291,7 @@ impl EmitterWriter {
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, &mut self.error_codes) {
self.short_message) {
Ok(()) => (),
Err(e) => panic!("failed to emit error: {}", e)
}
Expand Down Expand Up @@ -1419,8 +1384,7 @@ fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
lvl: &Level,
dst: &mut Destination,
short_message: bool,
error_codes: &mut HashSet<String>)
short_message: bool)
-> io::Result<()> {
use lock;

Expand All @@ -1441,9 +1405,6 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
for part in line {
dst.apply_style(lvl.clone(), part.style)?;
write!(dst, "{}", part.text)?;
if !short_message && part.text.len() == 12 && part.text.starts_with("error[E") {
error_codes.insert(part.text[6..11].to_owned());
}
dst.reset_attrs()?;
}
if !short_message {
Expand Down

0 comments on commit 5e6cc9b

Please sign in to comment.