1
Fork 0

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[..]) { match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
None | None |
Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)), 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("json") => ErrorOutputType::Json { pretty: false, json_rendered },
Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered }, Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)), 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", "--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() { 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::{DiagnosticBuilder, DiagnosticId, Applicability};
use errors::emitter::{Emitter, EmitterWriter}; use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType;
use errors::annotate_rs_emitter::{AnnotateRsEmitterWriter};
use syntax::ast::{self, NodeId}; use syntax::ast::{self, NodeId};
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeType}; use syntax::feature_gate::{self, AttributeType};
@ -1031,22 +1033,31 @@ fn default_emitter(
match (sopts.error_format, emitter_dest) { match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(kind), dst) => { (config::ErrorOutputType::HumanReadable(kind), dst) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
let emitter = match dst {
None => EmitterWriter::stderr( if let HumanReadableErrorType::AnnotateRs(_) = kind {
color_config, let emitter = AnnotateRsEmitterWriter::new(
Some(source_map.clone()), Some(source_map.clone()),
short, short,
sopts.debugging_opts.teach, );
), Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
Some(dst) => EmitterWriter::new( } else {
dst, let emitter = match dst {
Some(source_map.clone()), None => EmitterWriter::stderr(
short, color_config,
false, // no teach messages when writing to a buffer Some(source_map.clone()),
false, // no colors when writing to a buffer short,
), sopts.debugging_opts.teach,
}; ),
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing)) 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( (config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
JsonEmitter::stderr( JsonEmitter::stderr(

View file

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