From c31a8754e3f3a9274759cb429aad4ae594d39e29 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Nov 2019 17:24:44 -0500 Subject: [PATCH] Move JSON emitter to rustc_errors --- src/librustc/session/mod.rs | 2 +- src/{libsyntax => librustc_errors}/json.rs | 16 ++++++++-------- src/{libsyntax => librustc_errors}/json/tests.rs | 14 ++++++++++---- src/librustc_errors/lib.rs | 1 + src/librustdoc/core.rs | 2 +- src/libsyntax/lib.rs | 2 -- src/tools/compiletest/src/json.rs | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) rename src/{libsyntax => librustc_errors}/json.rs (97%) rename src/{libsyntax => librustc_errors}/json/tests.rs (92%) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index a69584cb90ad1..4fbc8da9cbf02 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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; diff --git a/src/libsyntax/json.rs b/src/librustc_errors/json.rs similarity index 97% rename from src/libsyntax/json.rs rename to src/librustc_errors/json.rs index 6096a930acfc4..ebbd49bd84a73 100644 --- a/src/libsyntax/json.rs +++ b/src/librustc_errors/json.rs @@ -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| { diff --git a/src/libsyntax/json/tests.rs b/src/librustc_errors/json/tests.rs similarity index 92% rename from src/libsyntax/json/tests.rs rename to src/librustc_errors/json/tests.rs index 1edefd5bc4bd8..4ab5cd21b0b00 100644 --- a/src/libsyntax/json/tests.rs +++ b/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}; @@ -40,6 +39,13 @@ impl Write for Shared { } } +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] }; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 1a6ac328a47d4..17765ef9deefa 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -37,6 +37,7 @@ mod snippet; pub mod registry; mod styled_buffer; mod lock; +pub mod json; pub type PResult<'a, T> = Result>; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a40325448b10b..507732a9107fb 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index a1de0a2c9e461..e3eca75dfe7e7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -87,8 +87,6 @@ pub mod util { pub mod map_in_place; } -pub mod json; - pub mod ast; pub mod attr; pub mod expand; diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 02b09e21ff022..7930d1249e7dc 100644 --- a/src/tools/compiletest/src/json.rs +++ b/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};