Skip to content

Commit

Permalink
Move JSON emitter to rustc_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Nov 15, 2019
1 parent 3f93ffc commit c31a875
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/json.rs → src/librustc_errors/json.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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| {
Expand Down
14 changes: 10 additions & 4 deletions src/libsyntax/json/tests.rs → src/librustc_errors/json/tests.rs
@@ -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};

Expand Down Expand Up @@ -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] };
Expand Down
1 change: 1 addition & 0 deletions src/librustc_errors/lib.rs
Expand Up @@ -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>>;

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/lib.rs
Expand Up @@ -87,8 +87,6 @@ pub mod util {
pub mod map_in_place;
}

pub mod json;

pub mod ast;
pub mod attr;
pub mod expand;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/json.rs
@@ -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};
Expand Down

0 comments on commit c31a875

Please sign in to comment.