Add new error-format value to use annotate-snippet output

This commit is contained in:
Philipp Hansch 2019-05-31 21:15:59 +02:00
parent 3f727aeeb7
commit c04a2ccb35
No known key found for this signature in database
GPG Key ID: 82AA61CAA11397E6
3 changed files with 40 additions and 14 deletions

View File

@ -2002,6 +2002,9 @@ pub fn build_session_options_and_crate_config(
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
None |
Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)),
Some("human-annotate-rs") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(color))
},
Some("json") => ErrorOutputType::Json { pretty: false, json_rendered },
Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)),
@ -2038,6 +2041,13 @@ pub fn build_session_options_and_crate_config(
"--error-format=pretty-json is unstable",
);
}
if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(_)) =
error_format {
early_error(
ErrorOutputType::Json { pretty: false, json_rendered },
"--error-format=human-annotate-rs is unstable",
);
}
}
if debugging_opts.pgo_gen.enabled() && debugging_opts.pgo_use.is_some() {

View File

@ -23,6 +23,8 @@ use rustc_data_structures::sync::{
use errors::{DiagnosticBuilder, DiagnosticId, Applicability};
use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType;
use errors::annotate_rs_emitter::{AnnotateRsEmitterWriter};
use syntax::ast::{self, NodeId};
use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeType};
@ -1031,22 +1033,31 @@ fn default_emitter(
match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(kind), dst) => {
let (short, color_config) = kind.unzip();
let emitter = match dst {
None => EmitterWriter::stderr(
color_config,
if let HumanReadableErrorType::AnnotateRs(_) = kind {
let emitter = AnnotateRsEmitterWriter::new(
Some(source_map.clone()),
short,
sopts.debugging_opts.teach,
),
Some(dst) => EmitterWriter::new(
dst,
Some(source_map.clone()),
short,
false, // no teach messages when writing to a buffer
false, // no colors when writing to a buffer
),
};
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
);
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
} else {
let emitter = match dst {
None => EmitterWriter::stderr(
color_config,
Some(source_map.clone()),
short,
sopts.debugging_opts.teach,
),
Some(dst) => EmitterWriter::new(
dst,
Some(source_map.clone()),
short,
false, // no teach messages when writing to a buffer
false, // no colors when writing to a buffer
),
};
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
}
},
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
JsonEmitter::stderr(

View File

@ -0,0 +1,5 @@
// compile-flags: --error-format human-annotate-rs
pub fn main() {
let x: Iter;
}