Move JSON emitter to rustc_errors

This commit is contained in:
Mark Rousskov 2019-11-14 17:24:44 -05:00
parent 3f93ffc333
commit c31a8754e3
7 changed files with 22 additions and 17 deletions

View file

@ -22,7 +22,7 @@ use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeType}; use syntax::feature_gate::{self, AttributeType};
use syntax::json::JsonEmitter; use errors::json::JsonEmitter;
use syntax::source_map; use syntax::source_map;
use syntax::sess::{ParseSess, ProcessCfgMod}; use syntax::sess::{ParseSess, ProcessCfgMod};
use syntax::symbol::Symbol; use syntax::symbol::Symbol;

View file

@ -9,15 +9,15 @@
// FIXME: spec the JSON output properly. // FIXME: spec the JSON output properly.
use crate::source_map::{SourceMap, FilePathMapping}; use syntax_pos::source_map::{SourceMap, FilePathMapping};
use errors::registry::Registry; use crate::registry::Registry;
use errors::{SubDiagnostic, CodeSuggestion}; use crate::{SubDiagnostic, CodeSuggestion};
use errors::{DiagnosticId, Applicability}; use crate::{DiagnosticId, Applicability};
use errors::emitter::{Emitter, HumanReadableErrorType}; use crate::emitter::{Emitter, HumanReadableErrorType};
use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan}; use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
use rustc_data_structures::sync::{self, Lrc}; use rustc_data_structures::sync::Lrc;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::Path; use std::path::Path;
use std::vec; use std::vec;
@ -92,7 +92,7 @@ impl JsonEmitter {
} }
impl Emitter for JsonEmitter { impl Emitter for JsonEmitter {
fn emit_diagnostic(&mut self, diag: &errors::Diagnostic) { fn emit_diagnostic(&mut self, diag: &crate::Diagnostic) {
let data = Diagnostic::from_errors_diagnostic(diag, self); let data = Diagnostic::from_errors_diagnostic(diag, self);
let result = if self.pretty { let result = if self.pretty {
writeln!(&mut self.dst, "{}", as_pretty_json(&data)) writeln!(&mut self.dst, "{}", as_pretty_json(&data))
@ -212,7 +212,7 @@ struct ArtifactNotification<'a> {
} }
impl Diagnostic { impl Diagnostic {
fn from_errors_diagnostic(diag: &errors::Diagnostic, fn from_errors_diagnostic(diag: &crate::Diagnostic,
je: &JsonEmitter) je: &JsonEmitter)
-> Diagnostic { -> Diagnostic {
let sugg = diag.suggestions.iter().map(|sugg| { let sugg = diag.suggestions.iter().map(|sugg| {

View file

@ -1,11 +1,10 @@
use super::*; use super::*;
use crate::json::JsonEmitter; use crate::json::JsonEmitter;
use crate::source_map::{FilePathMapping, SourceMap}; use syntax_pos::source_map::{FilePathMapping, SourceMap};
use crate::with_default_globals;
use errors::emitter::{ColorConfig, HumanReadableErrorType}; use crate::emitter::{ColorConfig, HumanReadableErrorType};
use errors::Handler; use crate::Handler;
use rustc_serialize::json::decode; use rustc_serialize::json::decode;
use syntax_pos::{BytePos, Span}; use syntax_pos::{BytePos, Span};
@ -40,6 +39,13 @@ impl<T: Write> Write for Shared<T> {
} }
} }
fn with_default_globals(f: impl FnOnce()) {
let globals = syntax_pos::Globals::new(syntax_pos::edition::DEFAULT_EDITION);
syntax_pos::GLOBALS.set(&globals, || {
syntax_pos::GLOBALS.set(&globals, f)
})
}
/// Test the span yields correct positions in JSON. /// Test the span yields correct positions in JSON.
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
let expected_output = TestData { spans: vec![expected_output] }; let expected_output = TestData { spans: vec![expected_output] };

View file

@ -37,6 +37,7 @@ mod snippet;
pub mod registry; pub mod registry;
mod styled_buffer; mod styled_buffer;
mod lock; mod lock;
pub mod json;
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>; pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;

View file

@ -18,7 +18,7 @@ use syntax::ast::CRATE_NODE_ID;
use syntax::source_map; use syntax::source_map;
use syntax::attr; use syntax::attr;
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
use syntax::json::JsonEmitter; use errors::json::JsonEmitter;
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
use errors; use errors;

View file

@ -87,8 +87,6 @@ pub mod util {
pub mod map_in_place; pub mod map_in_place;
} }
pub mod json;
pub mod ast; pub mod ast;
pub mod attr; pub mod attr;
pub mod expand; pub mod expand;

View file

@ -1,4 +1,4 @@
//! These structs are a subset of the ones found in `syntax::json`. //! These structs are a subset of the ones found in `rustc_errors::json`.
//! They are only used for deserialization of JSON output provided by libtest. //! They are only used for deserialization of JSON output provided by libtest.
use crate::errors::{Error, ErrorKind}; use crate::errors::{Error, ErrorKind};