Skip to content
Permalink
Browse files

Move JSON emitter to rustc_errors

  • Loading branch information
Mark-Simulacrum committed Nov 14, 2019
1 parent 3f93ffc commit c31a8754e3f3a9274759cb429aad4ae594d39e29
@@ -22,7 +22,7 @@ use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeType};
use syntax::json::JsonEmitter;
use errors::json::JsonEmitter;
use syntax::source_map;
use syntax::sess::{ParseSess, ProcessCfgMod};
use syntax::symbol::Symbol;
@@ -9,15 +9,15 @@

// FIXME: spec the JSON output properly.

use crate::source_map::{SourceMap, FilePathMapping};
use syntax_pos::source_map::{SourceMap, FilePathMapping};

use errors::registry::Registry;
use errors::{SubDiagnostic, CodeSuggestion};
use errors::{DiagnosticId, Applicability};
use errors::emitter::{Emitter, HumanReadableErrorType};
use crate::registry::Registry;
use crate::{SubDiagnostic, CodeSuggestion};
use crate::{DiagnosticId, Applicability};
use crate::emitter::{Emitter, HumanReadableErrorType};

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::path::Path;
use std::vec;
@@ -92,7 +92,7 @@ impl 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 result = if self.pretty {
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
@@ -212,7 +212,7 @@ struct ArtifactNotification<'a> {
}

impl Diagnostic {
fn from_errors_diagnostic(diag: &errors::Diagnostic,
fn from_errors_diagnostic(diag: &crate::Diagnostic,
je: &JsonEmitter)
-> Diagnostic {
let sugg = diag.suggestions.iter().map(|sugg| {
@@ -1,11 +1,10 @@
use super::*;

use crate::json::JsonEmitter;
use crate::source_map::{FilePathMapping, SourceMap};
use crate::with_default_globals;
use syntax_pos::source_map::{FilePathMapping, SourceMap};

use errors::emitter::{ColorConfig, HumanReadableErrorType};
use errors::Handler;
use crate::emitter::{ColorConfig, HumanReadableErrorType};
use crate::Handler;
use rustc_serialize::json::decode;
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.
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
let expected_output = TestData { spans: vec![expected_output] };
@@ -37,6 +37,7 @@ mod snippet;
pub mod registry;
mod styled_buffer;
mod lock;
pub mod json;

pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;

@@ -18,7 +18,7 @@ use syntax::ast::CRATE_NODE_ID;
use syntax::source_map;
use syntax::attr;
use syntax::feature_gate::UnstableFeatures;
use syntax::json::JsonEmitter;
use errors::json::JsonEmitter;
use syntax::symbol::sym;
use syntax_pos::DUMMY_SP;
use errors;
@@ -87,8 +87,6 @@ pub mod util {
pub mod map_in_place;
}

pub mod json;

pub mod ast;
pub mod attr;
pub mod expand;
@@ -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.

use crate::errors::{Error, ErrorKind};

0 comments on commit c31a875

Please sign in to comment.
You can’t perform that action at this time.