Toggle span highlighting on -Zteach
This commit is contained in:
parent
871856e831
commit
08287c1e26
8 changed files with 33 additions and 18 deletions
|
@ -904,10 +904,13 @@ pub fn build_session_with_codemap(sopts: config::Options,
|
||||||
|
|
||||||
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
|
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
|
||||||
(config::ErrorOutputType::HumanReadable(color_config), None) => {
|
(config::ErrorOutputType::HumanReadable(color_config), None) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
|
Box::new(EmitterWriter::stderr(color_config,
|
||||||
|
Some(codemap.clone()),
|
||||||
|
false,
|
||||||
|
sopts.debugging_opts.teach))
|
||||||
}
|
}
|
||||||
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
|
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
|
||||||
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
|
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false, false))
|
||||||
}
|
}
|
||||||
(config::ErrorOutputType::Json(pretty), None) => {
|
(config::ErrorOutputType::Json(pretty), None) => {
|
||||||
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(), pretty))
|
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(), pretty))
|
||||||
|
@ -916,10 +919,10 @@ pub fn build_session_with_codemap(sopts: config::Options,
|
||||||
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(), pretty))
|
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(), pretty))
|
||||||
}
|
}
|
||||||
(config::ErrorOutputType::Short(color_config), None) => {
|
(config::ErrorOutputType::Short(color_config), None) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))
|
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true, false))
|
||||||
}
|
}
|
||||||
(config::ErrorOutputType::Short(_), Some(dst)) => {
|
(config::ErrorOutputType::Short(_), Some(dst)) => {
|
||||||
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true))
|
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true, false))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1095,11 +1098,11 @@ pub enum IncrCompSession {
|
||||||
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
||||||
let emitter: Box<Emitter> = match output {
|
let emitter: Box<Emitter> = match output {
|
||||||
config::ErrorOutputType::HumanReadable(color_config) => {
|
config::ErrorOutputType::HumanReadable(color_config) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, false))
|
Box::new(EmitterWriter::stderr(color_config, None, false, false))
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
|
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
|
||||||
config::ErrorOutputType::Short(color_config) => {
|
config::ErrorOutputType::Short(color_config) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, true))
|
Box::new(EmitterWriter::stderr(color_config, None, true, false))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let handler = errors::Handler::with_emitter(true, false, emitter);
|
let handler = errors::Handler::with_emitter(true, false, emitter);
|
||||||
|
@ -1110,11 +1113,11 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
||||||
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
|
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
|
||||||
let emitter: Box<Emitter> = match output {
|
let emitter: Box<Emitter> = match output {
|
||||||
config::ErrorOutputType::HumanReadable(color_config) => {
|
config::ErrorOutputType::HumanReadable(color_config) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, false))
|
Box::new(EmitterWriter::stderr(color_config, None, false, false))
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
|
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
|
||||||
config::ErrorOutputType::Short(color_config) => {
|
config::ErrorOutputType::Short(color_config) => {
|
||||||
Box::new(EmitterWriter::stderr(color_config, None, true))
|
Box::new(EmitterWriter::stderr(color_config, None, true, false))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let handler = errors::Handler::with_emitter(true, false, emitter);
|
let handler = errors::Handler::with_emitter(true, false, emitter);
|
||||||
|
|
|
@ -163,7 +163,8 @@ pub fn run<F>(run_compiler: F) -> isize
|
||||||
let emitter =
|
let emitter =
|
||||||
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
||||||
None,
|
None,
|
||||||
true);
|
true,
|
||||||
|
false);
|
||||||
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
|
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
|
||||||
handler.emit(&MultiSpan::new(),
|
handler.emit(&MultiSpan::new(),
|
||||||
"aborting due to previous error(s)",
|
"aborting due to previous error(s)",
|
||||||
|
@ -1241,6 +1242,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
|
||||||
let emitter =
|
let emitter =
|
||||||
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
false));
|
false));
|
||||||
let handler = errors::Handler::with_emitter(true, false, emitter);
|
let handler = errors::Handler::with_emitter(true, false, emitter);
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ pub struct EmitterWriter {
|
||||||
dst: Destination,
|
dst: Destination,
|
||||||
cm: Option<Rc<CodeMapper>>,
|
cm: Option<Rc<CodeMapper>>,
|
||||||
short_message: bool,
|
short_message: bool,
|
||||||
|
teach: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FileWithAnnotatedLines {
|
struct FileWithAnnotatedLines {
|
||||||
|
@ -117,32 +118,37 @@ struct FileWithAnnotatedLines {
|
||||||
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>>,
|
||||||
short_message: bool)
|
short_message: bool,
|
||||||
|
teach: bool)
|
||||||
-> EmitterWriter {
|
-> EmitterWriter {
|
||||||
if color_config.use_color() {
|
if color_config.use_color() {
|
||||||
let dst = Destination::from_stderr();
|
let dst = Destination::from_stderr();
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst,
|
dst,
|
||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message: short_message,
|
short_message,
|
||||||
|
teach,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst: Raw(Box::new(io::stderr())),
|
dst: Raw(Box::new(io::stderr())),
|
||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message: short_message,
|
short_message,
|
||||||
|
teach,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(dst: Box<Write + Send>,
|
pub fn new(dst: Box<Write + Send>,
|
||||||
code_map: Option<Rc<CodeMapper>>,
|
code_map: Option<Rc<CodeMapper>>,
|
||||||
short_message: bool)
|
short_message: bool,
|
||||||
|
teach: bool)
|
||||||
-> EmitterWriter {
|
-> EmitterWriter {
|
||||||
EmitterWriter {
|
EmitterWriter {
|
||||||
dst: Raw(dst),
|
dst: Raw(dst),
|
||||||
cm: code_map,
|
cm: code_map,
|
||||||
short_message: short_message,
|
short_message,
|
||||||
|
teach,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,13 +557,14 @@ impl EmitterWriter {
|
||||||
code_offset + annotation.start_col,
|
code_offset + annotation.start_col,
|
||||||
style);
|
style);
|
||||||
}
|
}
|
||||||
_ => {
|
_ if self.teach => {
|
||||||
buffer.set_style_range(line_offset,
|
buffer.set_style_range(line_offset,
|
||||||
code_offset + annotation.start_col,
|
code_offset + annotation.start_col,
|
||||||
code_offset + annotation.end_col,
|
code_offset + annotation.end_col,
|
||||||
style,
|
style,
|
||||||
annotation.is_primary);
|
annotation.is_primary);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,7 @@ impl Handler {
|
||||||
cm: Option<Rc<CodeMapper>>,
|
cm: Option<Rc<CodeMapper>>,
|
||||||
flags: HandlerFlags)
|
flags: HandlerFlags)
|
||||||
-> Handler {
|
-> Handler {
|
||||||
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false));
|
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
|
||||||
Handler::with_emitter_and_flags(emitter, flags)
|
Handler::with_emitter_and_flags(emitter, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
|
||||||
));
|
));
|
||||||
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()),
|
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()),
|
||||||
Some(codemap.clone()),
|
Some(codemap.clone()),
|
||||||
|
false,
|
||||||
false);
|
false);
|
||||||
let old = io::set_panic(Some(box Sink(data.clone())));
|
let old = io::set_panic(Some(box Sink(data.clone())));
|
||||||
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
|
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl Diagnostic {
|
||||||
}
|
}
|
||||||
let buf = BufWriter::default();
|
let buf = BufWriter::default();
|
||||||
let output = buf.clone();
|
let output = buf.clone();
|
||||||
EmitterWriter::new(Box::new(buf), Some(je.cm.clone()), false).emit(db);
|
EmitterWriter::new(Box::new(buf), Some(je.cm.clone()), false, false).emit(db);
|
||||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||||
let output = String::from_utf8(output).unwrap();
|
let output = String::from_utf8(output).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1745,6 +1745,7 @@ mod tests {
|
||||||
fn mk_sess(cm: Rc<CodeMap>) -> ParseSess {
|
fn mk_sess(cm: Rc<CodeMap>) -> ParseSess {
|
||||||
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
|
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
|
||||||
Some(cm.clone()),
|
Some(cm.clone()),
|
||||||
|
false,
|
||||||
false);
|
false);
|
||||||
ParseSess {
|
ParseSess {
|
||||||
span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),
|
span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),
|
||||||
|
|
|
@ -62,6 +62,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
|
||||||
|
|
||||||
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
|
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
|
||||||
Some(code_map.clone()),
|
Some(code_map.clone()),
|
||||||
|
false,
|
||||||
false);
|
false);
|
||||||
let handler = Handler::with_emitter(true, false, Box::new(emitter));
|
let handler = Handler::with_emitter(true, false, Box::new(emitter));
|
||||||
handler.span_err(msp, "foo");
|
handler.span_err(msp, "foo");
|
||||||
|
|
Loading…
Reference in a new issue