Skip to content

Commit 576f766

Browse files
authored
Auto merge of #35401 - jonathandturner:enable_json_and_new_errors, r=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
2 parents e1d2bc2 + 9b510ba commit 576f766

File tree

20 files changed

+31
-599
lines changed

20 files changed

+31
-599
lines changed

src/librustc/infer/error_reporting.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use syntax::ast;
9494
use syntax::parse::token;
9595
use syntax::ptr::P;
9696
use syntax_pos::{self, Pos, Span};
97-
use errors::{DiagnosticBuilder, check_old_school};
97+
use errors::DiagnosticBuilder;
9898

9999
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
100100
pub fn note_and_explain_region(self,
@@ -541,25 +541,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
541541

542542
let span = origin.span();
543543

544-
let mut is_simple_error = false;
545-
546544
if let Some((expected, found)) = expected_found {
547-
is_simple_error = if let &TypeError::Sorts(ref values) = terr {
545+
let is_simple_error = if let &TypeError::Sorts(ref values) = terr {
548546
values.expected.is_primitive() && values.found.is_primitive()
549547
} else {
550548
false
551549
};
552550

553-
if !is_simple_error || check_old_school() {
551+
if !is_simple_error {
554552
diag.note_expected_found(&"type", &expected, &found);
555553
}
556554
}
557555

558-
if !is_simple_error && check_old_school() {
559-
diag.span_note(span, &format!("{}", terr));
560-
} else {
561-
diag.span_label(span, &terr);
562-
}
556+
diag.span_label(span, &terr);
563557

564558
self.note_error_origin(diag, &origin);
565559
self.check_and_note_conflicting_crates(diag, terr, span);

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
10571057
"NAME=PATH"),
10581058
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
10591059
opt::multi_ubnr("Z", "", "Set internal debugging options", "FLAG"),
1060-
opt::opt_ubnr("", "error-format",
1060+
opt::opt_s("", "error-format",
10611061
"How errors and other messages are produced",
10621062
"human|json"),
10631063
opt::opt_s("", "color", "Configure coloring of output:

src/librustc/session/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use mir::transform as mir_pass;
2323
use syntax::ast::{NodeId, Name};
2424
use errors::{self, DiagnosticBuilder};
2525
use errors::emitter::{Emitter, EmitterWriter};
26-
use errors::snippet::FormatMode;
2726
use syntax::json::JsonEmitter;
2827
use syntax::feature_gate;
2928
use syntax::parse;
@@ -369,9 +368,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
369368
let emitter: Box<Emitter> = match sopts.error_format {
370369
config::ErrorOutputType::HumanReadable(color_config) => {
371370
Box::new(EmitterWriter::stderr(color_config,
372-
Some(registry),
373-
Some(codemap.clone()),
374-
errors::snippet::FormatMode::EnvironmentSelected))
371+
Some(codemap.clone())))
375372
}
376373
config::ErrorOutputType::Json => {
377374
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
@@ -509,9 +506,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
509506
let emitter: Box<Emitter> = match output {
510507
config::ErrorOutputType::HumanReadable(color_config) => {
511508
Box::new(EmitterWriter::stderr(color_config,
512-
None,
513-
None,
514-
FormatMode::EnvironmentSelected))
509+
None))
515510
}
516511
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
517512
};
@@ -524,9 +519,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
524519
let emitter: Box<Emitter> = match output {
525520
config::ErrorOutputType::HumanReadable(color_config) => {
526521
Box::new(EmitterWriter::stderr(color_config,
527-
None,
528-
None,
529-
FormatMode::EnvironmentSelected))
522+
None))
530523
}
531524
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
532525
};

src/librustc_const_eval/eval.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::cmp::Ordering;
4444
use std::collections::hash_map::Entry::Vacant;
4545

4646
use rustc_const_math::*;
47-
use rustc_errors::{DiagnosticBuilder, check_old_school};
47+
use rustc_errors::DiagnosticBuilder;
4848

4949
macro_rules! math {
5050
($e:expr, $op:expr) => {
@@ -378,11 +378,7 @@ pub fn note_const_eval_err<'a, 'tcx>(
378378
{
379379
match err.description() {
380380
ConstEvalErrDescription::Simple(message) => {
381-
if check_old_school() {
382-
diag.note(&message);
383-
} else {
384-
diag.span_label(err.span, &message);
385-
}
381+
diag.span_label(err.span, &message);
386382
}
387383
}
388384

src/librustc_driver/lib.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
100100
use syntax::parse::{self, PResult};
101101
use syntax_pos::MultiSpan;
102102
use errors::emitter::Emitter;
103-
use errors::snippet::FormatMode;
104103

105104
#[cfg(test)]
106105
pub mod test;
@@ -141,9 +140,7 @@ pub fn run(args: Vec<String>) -> isize {
141140
None => {
142141
let emitter =
143142
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
144-
None,
145-
None,
146-
FormatMode::EnvironmentSelected);
143+
None);
147144
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
148145
handler.emit(&MultiSpan::new(),
149146
&abort_msg(err_count),
@@ -381,10 +378,7 @@ fn check_cfg(sopts: &config::Options,
381378
output: ErrorOutputType) {
382379
let emitter: Box<Emitter> = match output {
383380
config::ErrorOutputType::HumanReadable(color_config) => {
384-
Box::new(errors::emitter::EmitterWriter::stderr(color_config,
385-
None,
386-
None,
387-
FormatMode::EnvironmentSelected))
381+
Box::new(errors::emitter::EmitterWriter::stderr(color_config, None))
388382
}
389383
config::ErrorOutputType::Json => Box::new(json::JsonEmitter::basic()),
390384
};
@@ -1050,10 +1044,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
10501044
// Thread panicked without emitting a fatal diagnostic
10511045
if !value.is::<errors::FatalError>() {
10521046
let emitter =
1053-
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
1054-
None,
1055-
None,
1056-
FormatMode::EnvironmentSelected));
1047+
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None));
10571048
let handler = errors::Handler::with_emitter(true, false, emitter);
10581049

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

0 commit comments

Comments
 (0)