Skip to content

Commit c04a2cc

Browse files
committed
Add new error-format value to use annotate-snippet output
1 parent 3f727ae commit c04a2cc

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

src/librustc/session/config.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,9 @@ pub fn build_session_options_and_crate_config(
20022002
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
20032003
None |
20042004
Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)),
2005+
Some("human-annotate-rs") => {
2006+
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(color))
2007+
},
20052008
Some("json") => ErrorOutputType::Json { pretty: false, json_rendered },
20062009
Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
20072010
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)),
@@ -2038,6 +2041,13 @@ pub fn build_session_options_and_crate_config(
20382041
"--error-format=pretty-json is unstable",
20392042
);
20402043
}
2044+
if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(_)) =
2045+
error_format {
2046+
early_error(
2047+
ErrorOutputType::Json { pretty: false, json_rendered },
2048+
"--error-format=human-annotate-rs is unstable",
2049+
);
2050+
}
20412051
}
20422052

20432053
if debugging_opts.pgo_gen.enabled() && debugging_opts.pgo_use.is_some() {

src/librustc/session/mod.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use rustc_data_structures::sync::{
2323

2424
use errors::{DiagnosticBuilder, DiagnosticId, Applicability};
2525
use errors::emitter::{Emitter, EmitterWriter};
26+
use errors::emitter::HumanReadableErrorType;
27+
use errors::annotate_rs_emitter::{AnnotateRsEmitterWriter};
2628
use syntax::ast::{self, NodeId};
2729
use syntax::edition::Edition;
2830
use syntax::feature_gate::{self, AttributeType};
@@ -1031,22 +1033,31 @@ fn default_emitter(
10311033
match (sopts.error_format, emitter_dest) {
10321034
(config::ErrorOutputType::HumanReadable(kind), dst) => {
10331035
let (short, color_config) = kind.unzip();
1034-
let emitter = match dst {
1035-
None => EmitterWriter::stderr(
1036-
color_config,
1037-
Some(source_map.clone()),
1038-
short,
1039-
sopts.debugging_opts.teach,
1040-
),
1041-
Some(dst) => EmitterWriter::new(
1042-
dst,
1036+
1037+
if let HumanReadableErrorType::AnnotateRs(_) = kind {
1038+
let emitter = AnnotateRsEmitterWriter::new(
10431039
Some(source_map.clone()),
10441040
short,
1045-
false, // no teach messages when writing to a buffer
1046-
false, // no colors when writing to a buffer
1047-
),
1048-
};
1049-
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
1041+
);
1042+
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
1043+
} else {
1044+
let emitter = match dst {
1045+
None => EmitterWriter::stderr(
1046+
color_config,
1047+
Some(source_map.clone()),
1048+
short,
1049+
sopts.debugging_opts.teach,
1050+
),
1051+
Some(dst) => EmitterWriter::new(
1052+
dst,
1053+
Some(source_map.clone()),
1054+
short,
1055+
false, // no teach messages when writing to a buffer
1056+
false, // no colors when writing to a buffer
1057+
),
1058+
};
1059+
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
1060+
}
10501061
},
10511062
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
10521063
JsonEmitter::stderr(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags: --error-format human-annotate-rs
2+
3+
pub fn main() {
4+
let x: Iter;
5+
}

0 commit comments

Comments
 (0)