Add rustc --explain back
This commit is contained in:
parent
026339e42b
commit
9b597a1542
@ -21,7 +21,7 @@ use std::io::prelude::*;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use term;
|
use term;
|
||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use unicode_width;
|
use unicode_width;
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ pub struct EmitterWriter {
|
|||||||
cm: Option<Rc<CodeMapper>>,
|
cm: Option<Rc<CodeMapper>>,
|
||||||
short_message: bool,
|
short_message: bool,
|
||||||
teach: bool,
|
teach: bool,
|
||||||
|
error_codes: HashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FileWithAnnotatedLines {
|
struct FileWithAnnotatedLines {
|
||||||
@ -115,6 +116,30 @@ struct FileWithAnnotatedLines {
|
|||||||
multiline_depth: usize,
|
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 {
|
||||||
|
writeln!(self.dst,
|
||||||
|
"You've got a few errors: {}",
|
||||||
|
error_codes.join(", ")).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 {
|
impl EmitterWriter {
|
||||||
pub fn stderr(color_config: ColorConfig,
|
pub fn stderr(color_config: ColorConfig,
|
||||||
code_map: Option<Rc<CodeMapper>>,
|
code_map: Option<Rc<CodeMapper>>,
|
||||||
@ -128,6 +153,7 @@ impl EmitterWriter {
|
|||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message,
|
short_message,
|
||||||
teach,
|
teach,
|
||||||
|
error_codes: HashSet::new(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
@ -135,6 +161,7 @@ impl EmitterWriter {
|
|||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message,
|
short_message,
|
||||||
teach,
|
teach,
|
||||||
|
error_codes: HashSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,6 +176,7 @@ impl EmitterWriter {
|
|||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message,
|
short_message,
|
||||||
teach,
|
teach,
|
||||||
|
error_codes: HashSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,12 +1003,14 @@ impl EmitterWriter {
|
|||||||
if primary_span != &&DUMMY_SP {
|
if primary_span != &&DUMMY_SP {
|
||||||
(cm.lookup_char_pos(primary_span.lo()), cm)
|
(cm.lookup_char_pos(primary_span.lo()), cm)
|
||||||
} else {
|
} else {
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
|
||||||
|
&mut self.error_codes)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we don't have span information, emit and exit
|
// If we don't have span information, emit and exit
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
|
||||||
|
&mut self.error_codes)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
if let Ok(pos) =
|
if let Ok(pos) =
|
||||||
@ -1153,7 +1183,8 @@ impl EmitterWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// final step: take our styled buffer, render it, then output it
|
// final step: take our styled buffer, render it, then output it
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
|
||||||
|
&mut self.error_codes)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
@ -1241,7 +1272,8 @@ impl EmitterWriter {
|
|||||||
let msg = format!("and {} other candidates", suggestions.len() - MAX_SUGGESTIONS);
|
let msg = format!("and {} other candidates", suggestions.len() - MAX_SUGGESTIONS);
|
||||||
buffer.puts(row_num, 0, &msg, Style::NoStyle);
|
buffer.puts(row_num, 0, &msg, Style::NoStyle);
|
||||||
}
|
}
|
||||||
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
|
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message,
|
||||||
|
&mut self.error_codes)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1269,7 +1301,7 @@ impl EmitterWriter {
|
|||||||
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
|
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
|
||||||
}
|
}
|
||||||
match emit_to_destination(&buffer.render(), level, &mut self.dst,
|
match emit_to_destination(&buffer.render(), level, &mut self.dst,
|
||||||
self.short_message) {
|
self.short_message, &mut self.error_codes) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(e) => panic!("failed to emit error: {}", e)
|
Err(e) => panic!("failed to emit error: {}", e)
|
||||||
}
|
}
|
||||||
@ -1362,7 +1394,8 @@ fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
|
|||||||
fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
|
fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
|
||||||
lvl: &Level,
|
lvl: &Level,
|
||||||
dst: &mut Destination,
|
dst: &mut Destination,
|
||||||
short_message: bool)
|
short_message: bool,
|
||||||
|
error_codes: &mut HashSet<String>)
|
||||||
-> io::Result<()> {
|
-> io::Result<()> {
|
||||||
use lock;
|
use lock;
|
||||||
|
|
||||||
@ -1383,6 +1416,9 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
|
|||||||
for part in line {
|
for part in line {
|
||||||
dst.apply_style(lvl.clone(), part.style)?;
|
dst.apply_style(lvl.clone(), part.style)?;
|
||||||
write!(dst, "{}", part.text)?;
|
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()?;
|
dst.reset_attrs()?;
|
||||||
}
|
}
|
||||||
if !short_message {
|
if !short_message {
|
||||||
|
Loading…
Reference in New Issue
Block a user