Skip to content

Commit

Permalink
Auto merge of #35401 - jonathandturner:enable_json_and_new_errors, r=…
Browse files Browse the repository at this point in the history
…jonathandturner

Turn on new errors and json mode

This PR is a big-switch, but on a well-worn path:

* Turns on new errors by default (and removes old skool)
* Moves json output from behind a flag

The RFC for new errors [landed](rust-lang/rfcs#1644) and as part of that we wanted some bake time.  It's now had a few weeks + all the time leading up to the RFC of people banging on it.  We've also had [editors updating to the new format](https://github.com/saviorisdead/RustyCode/pull/159) and expect more to follow.

We also have an [issue on old skool](#35330) that needs to be fixed as more errors are switched to the new style, but it seems silly to fix old skool errors when we fully intend to throw the switch in the near future.

This makes it lean towards "why not just throw the switch now, rather than waiting a couple more weeks?"  I only know of vim that wanted to try to parse the new format but were not sure how, and I think we can reach out to them and work out something in the 8 weeks before this would appear in a stable release.

We've [hashed out](#35330) stabilizing JSON output, and it seems like people are relatively happy making what we have v1 and then likely adding to it in the future.  The idea is that we'd maintain backward compatibility and just add new fields as needed.  We'll also work on a separate output format that'd be better suited for interactive tools like IDES (since JSON message can get a little long depending on the error).

This PR stabilizes JSON mode, allowing its use without `-Z unstable-options`

Combined, this gives editors two ways to support errors going forward: parsing the new error format or using the JSON mode.  By moving JSON to stable, we can also add support to Cargo, which plugin authors tell us does help simplify their support story.

r? @nikomatsakis
cc @rust-lang/tools

Closes #34826
  • Loading branch information
bors committed Aug 9, 2016
2 parents e1d2bc2 + 9b510ba commit 576f766
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 599 deletions.
14 changes: 4 additions & 10 deletions src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use syntax::ast;
use syntax::parse::token;
use syntax::ptr::P;
use syntax_pos::{self, Pos, Span};
use errors::{DiagnosticBuilder, check_old_school};
use errors::DiagnosticBuilder;

impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn note_and_explain_region(self,
Expand Down Expand Up @@ -541,25 +541,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

let span = origin.span();

let mut is_simple_error = false;

if let Some((expected, found)) = expected_found {
is_simple_error = if let &TypeError::Sorts(ref values) = terr {
let is_simple_error = if let &TypeError::Sorts(ref values) = terr {
values.expected.is_primitive() && values.found.is_primitive()
} else {
false
};

if !is_simple_error || check_old_school() {
if !is_simple_error {
diag.note_expected_found(&"type", &expected, &found);
}
}

if !is_simple_error && check_old_school() {
diag.span_note(span, &format!("{}", terr));
} else {
diag.span_label(span, &terr);
}
diag.span_label(span, &terr);

self.note_error_origin(diag, &origin);
self.check_and_note_conflicting_crates(diag, terr, span);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"NAME=PATH"),
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
opt::multi_ubnr("Z", "", "Set internal debugging options", "FLAG"),
opt::opt_ubnr("", "error-format",
opt::opt_s("", "error-format",
"How errors and other messages are produced",
"human|json"),
opt::opt_s("", "color", "Configure coloring of output:
Expand Down
13 changes: 3 additions & 10 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use mir::transform as mir_pass;
use syntax::ast::{NodeId, Name};
use errors::{self, DiagnosticBuilder};
use errors::emitter::{Emitter, EmitterWriter};
use errors::snippet::FormatMode;
use syntax::json::JsonEmitter;
use syntax::feature_gate;
use syntax::parse;
Expand Down Expand Up @@ -369,9 +368,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
let emitter: Box<Emitter> = match sopts.error_format {
config::ErrorOutputType::HumanReadable(color_config) => {
Box::new(EmitterWriter::stderr(color_config,
Some(registry),
Some(codemap.clone()),
errors::snippet::FormatMode::EnvironmentSelected))
Some(codemap.clone())))
}
config::ErrorOutputType::Json => {
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
Expand Down Expand Up @@ -509,9 +506,7 @@ 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,
None,
FormatMode::EnvironmentSelected))
None))
}
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
};
Expand All @@ -524,9 +519,7 @@ 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,
None,
FormatMode::EnvironmentSelected))
None))
}
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
};
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::cmp::Ordering;
use std::collections::hash_map::Entry::Vacant;

use rustc_const_math::*;
use rustc_errors::{DiagnosticBuilder, check_old_school};
use rustc_errors::DiagnosticBuilder;

macro_rules! math {
($e:expr, $op:expr) => {
Expand Down Expand Up @@ -378,11 +378,7 @@ pub fn note_const_eval_err<'a, 'tcx>(
{
match err.description() {
ConstEvalErrDescription::Simple(message) => {
if check_old_school() {
diag.note(&message);
} else {
diag.span_label(err.span, &message);
}
diag.span_label(err.span, &message);
}
}

Expand Down
15 changes: 3 additions & 12 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult};
use syntax_pos::MultiSpan;
use errors::emitter::Emitter;
use errors::snippet::FormatMode;

#[cfg(test)]
pub mod test;
Expand Down Expand Up @@ -141,9 +140,7 @@ pub fn run(args: Vec<String>) -> isize {
None => {
let emitter =
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
None,
FormatMode::EnvironmentSelected);
None);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
&abort_msg(err_count),
Expand Down Expand Up @@ -381,10 +378,7 @@ fn check_cfg(sopts: &config::Options,
output: ErrorOutputType) {
let emitter: Box<Emitter> = match output {
config::ErrorOutputType::HumanReadable(color_config) => {
Box::new(errors::emitter::EmitterWriter::stderr(color_config,
None,
None,
FormatMode::EnvironmentSelected))
Box::new(errors::emitter::EmitterWriter::stderr(color_config, None))
}
config::ErrorOutputType::Json => Box::new(json::JsonEmitter::basic()),
};
Expand Down Expand Up @@ -1050,10 +1044,7 @@ 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,
None,
FormatMode::EnvironmentSelected));
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None));
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 576f766

Please sign in to comment.