Skip to content

Commit f9d2416

Browse files
committed
Auto merge of #44636 - GuillaumeGomez:little-error-msg, r=michaelwoerister
Add short error message-format Fixes #42653.
2 parents 2f5ae25 + b46c014 commit f9d2416

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
@@ -715,19 +715,23 @@ pub fn build_session_with_codemap(sopts: config::Options,
715715

716716
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
717717
(config::ErrorOutputType::HumanReadable(color_config), None) => {
718-
Box::new(EmitterWriter::stderr(color_config,
719-
Some(codemap.clone())))
718+
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
720719
}
721720
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
722-
Box::new(EmitterWriter::new(dst,
723-
Some(codemap.clone())))
721+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
724722
}
725723
(config::ErrorOutputType::Json, None) => {
726724
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
727725
}
728726
(config::ErrorOutputType::Json, Some(dst)) => {
729727
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone()))
730728
}
729+
(config::ErrorOutputType::Short(color_config), None) => {
730+
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))
731+
}
732+
(config::ErrorOutputType::Short(_), Some(dst)) => {
733+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true))
734+
}
731735
};
732736

733737
let diagnostic_handler =
@@ -891,10 +895,12 @@ pub enum IncrCompSession {
891895
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
892896
let emitter: Box<Emitter> = match output {
893897
config::ErrorOutputType::HumanReadable(color_config) => {
894-
Box::new(EmitterWriter::stderr(color_config,
895-
None))
898+
Box::new(EmitterWriter::stderr(color_config, None, false))
896899
}
897900
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
901+
config::ErrorOutputType::Short(color_config) => {
902+
Box::new(EmitterWriter::stderr(color_config, None, true))
903+
}
898904
};
899905
let handler = errors::Handler::with_emitter(true, false, emitter);
900906
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
@@ -904,10 +910,12 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
904910
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
905911
let emitter: Box<Emitter> = match output {
906912
config::ErrorOutputType::HumanReadable(color_config) => {
907-
Box::new(EmitterWriter::stderr(color_config,
908-
None))
913+
Box::new(EmitterWriter::stderr(color_config, None, false))
909914
}
910915
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
916+
config::ErrorOutputType::Short(color_config) => {
917+
Box::new(EmitterWriter::stderr(color_config, None, true))
918+
}
911919
};
912920
let handler = errors::Handler::with_emitter(true, false, emitter);
913921
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)