Skip to content

Add short error message-format #44636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -711,19 +711,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 @@ -867,10 +871,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 @@ -880,10 +886,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