Skip to content

Commit

Permalink
Auto merge of #44636 - GuillaumeGomez:little-error-msg, r=michaelwoer…
Browse files Browse the repository at this point in the history
…ister

Add short error message-format

Fixes #42653.
  • Loading branch information
bors committed Oct 25, 2017
2 parents 2f5ae25 + b46c014 commit f9d2416
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 149 deletions.
12 changes: 7 additions & 5 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl OutputType {
pub enum ErrorOutputType {
HumanReadable(ColorConfig),
Json,
Short(ColorConfig),
}

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

None => ErrorOutputType::HumanReadable(color),

Some(arg) => {
early_error(ErrorOutputType::HumanReadable(color),
&format!("argument for --error-format must be human or json (instead \
was `{}`)",
&format!("argument for --error-format must be `human`, `json` or \
`short` (instead was `{}`)",
arg))
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,23 @@ pub fn build_session_with_codemap(sopts: config::Options,

let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(color_config), None) => {
Box::new(EmitterWriter::stderr(color_config,
Some(codemap.clone())))
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
}
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
Box::new(EmitterWriter::new(dst,
Some(codemap.clone())))
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
}
(config::ErrorOutputType::Json, None) => {
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
}
(config::ErrorOutputType::Json, Some(dst)) => {
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone()))
}
(config::ErrorOutputType::Short(color_config), None) => {
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))
}
(config::ErrorOutputType::Short(_), Some(dst)) => {
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true))
}
};

let diagnostic_handler =
Expand Down Expand Up @@ -891,10 +895,12 @@ pub enum IncrCompSession {
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
let emitter: Box<Emitter> = match output {
config::ErrorOutputType::HumanReadable(color_config) => {
Box::new(EmitterWriter::stderr(color_config,
None))
Box::new(EmitterWriter::stderr(color_config, None, false))
}
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
config::ErrorOutputType::Short(color_config) => {
Box::new(EmitterWriter::stderr(color_config, None, true))
}
};
let handler = errors::Handler::with_emitter(true, false, emitter);
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
Expand All @@ -904,10 +910,12 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
let emitter: Box<Emitter> = match output {
config::ErrorOutputType::HumanReadable(color_config) => {
Box::new(EmitterWriter::stderr(color_config,
None))
Box::new(EmitterWriter::stderr(color_config, None, false))
}
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
config::ErrorOutputType::Short(color_config) => {
Box::new(EmitterWriter::stderr(color_config, None, true))
}
};
let handler = errors::Handler::with_emitter(true, false, emitter);
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ pub fn run<F>(run_compiler: F) -> isize
}
None => {
let emitter =
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None);
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
true);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
"aborting due to previous error(s)",
Expand Down Expand Up @@ -1208,7 +1210,9 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
// Thread panicked without emitting a fatal diagnostic
if !value.is::<errors::FatalError>() {
let emitter =
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None));
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
false));
let handler = errors::Handler::with_emitter(true, false, emitter);

// a .span_bug or .bug call has already printed what
Expand Down
Loading

0 comments on commit f9d2416

Please sign in to comment.