Skip to content

Commit 83bca40

Browse files
Add short message-format
1 parent c0e0a38 commit 83bca40

File tree

10 files changed

+223
-149
lines changed

10 files changed

+223
-149
lines changed

src/librustc/session/config.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl OutputType {
156156
pub enum ErrorOutputType {
157157
HumanReadable(ColorConfig),
158158
Json,
159+
Short(ColorConfig),
159160
}
160161

161162
impl Default for ErrorOutputType {
@@ -1362,7 +1363,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
13621363
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
13631364
opt::opt_s("", "error-format",
13641365
"How errors and other messages are produced",
1365-
"human|json"),
1366+
"human|json|short"),
13661367
opt::opt_s("", "color", "Configure coloring of output:
13671368
auto = colorize, if output goes to a tty (default);
13681369
always = always colorize output;
@@ -1429,15 +1430,16 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14291430
// opt_present because the latter will panic.
14301431
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
14311432
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
1432-
Some("human") => ErrorOutputType::HumanReadable(color),
1433-
Some("json") => ErrorOutputType::Json,
1433+
Some("human") => ErrorOutputType::HumanReadable(color),
1434+
Some("json") => ErrorOutputType::Json,
1435+
Some("short") => ErrorOutputType::Short(color),
14341436

14351437
None => ErrorOutputType::HumanReadable(color),
14361438

14371439
Some(arg) => {
14381440
early_error(ErrorOutputType::HumanReadable(color),
1439-
&format!("argument for --error-format must be human or json (instead \
1440-
was `{}`)",
1441+
&format!("argument for --error-format must be `human`, `json` or \
1442+
`short` (instead was `{}`)",
14411443
arg))
14421444
}
14431445
}

src/librustc/session/mod.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -711,19 +711,23 @@ pub fn build_session_with_codemap(sopts: config::Options,
711711

712712
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
713713
(config::ErrorOutputType::HumanReadable(color_config), None) => {
714-
Box::new(EmitterWriter::stderr(color_config,
715-
Some(codemap.clone())))
714+
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
716715
}
717716
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
718-
Box::new(EmitterWriter::new(dst,
719-
Some(codemap.clone())))
717+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
720718
}
721719
(config::ErrorOutputType::Json, None) => {
722720
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
723721
}
724722
(config::ErrorOutputType::Json, Some(dst)) => {
725723
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone()))
726724
}
725+
(config::ErrorOutputType::Short(color_config), None) => {
726+
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))
727+
}
728+
(config::ErrorOutputType::Short(_), Some(dst)) => {
729+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true))
730+
}
727731
};
728732

729733
let diagnostic_handler =
@@ -867,10 +871,12 @@ pub enum IncrCompSession {
867871
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
868872
let emitter: Box<Emitter> = match output {
869873
config::ErrorOutputType::HumanReadable(color_config) => {
870-
Box::new(EmitterWriter::stderr(color_config,
871-
None))
874+
Box::new(EmitterWriter::stderr(color_config, None, false))
872875
}
873876
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
877+
config::ErrorOutputType::Short(color_config) => {
878+
Box::new(EmitterWriter::stderr(color_config, None, true))
879+
}
874880
};
875881
let handler = errors::Handler::with_emitter(true, false, emitter);
876882
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
@@ -880,10 +886,12 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
880886
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
881887
let emitter: Box<Emitter> = match output {
882888
config::ErrorOutputType::HumanReadable(color_config) => {
883-
Box::new(EmitterWriter::stderr(color_config,
884-
None))
889+
Box::new(EmitterWriter::stderr(color_config, None, false))
885890
}
886891
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
892+
config::ErrorOutputType::Short(color_config) => {
893+
Box::new(EmitterWriter::stderr(color_config, None, true))
894+
}
887895
};
888896
let handler = errors::Handler::with_emitter(true, false, emitter);
889897
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);

src/librustc_driver/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ pub fn run<F>(run_compiler: F) -> isize
138138
}
139139
None => {
140140
let emitter =
141-
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None);
141+
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
142+
None,
143+
true);
142144
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
143145
handler.emit(&MultiSpan::new(),
144146
"aborting due to previous error(s)",
@@ -1208,7 +1210,9 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
12081210
// Thread panicked without emitting a fatal diagnostic
12091211
if !value.is::<errors::FatalError>() {
12101212
let emitter =
1211-
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None));
1213+
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
1214+
None,
1215+
false));
12121216
let handler = errors::Handler::with_emitter(true, false, emitter);
12131217

12141218
// a .span_bug or .bug call has already printed what

0 commit comments

Comments
 (0)