Skip to content

Commit c31a875

Browse files
Move JSON emitter to rustc_errors
1 parent 3f93ffc commit c31a875

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use errors::emitter::HumanReadableErrorType;
2222
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2323
use syntax::edition::Edition;
2424
use syntax::feature_gate::{self, AttributeType};
25-
use syntax::json::JsonEmitter;
25+
use errors::json::JsonEmitter;
2626
use syntax::source_map;
2727
use syntax::sess::{ParseSess, ProcessCfgMod};
2828
use syntax::symbol::Symbol;

src/libsyntax/json.rs renamed to src/librustc_errors/json.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
1010
// FIXME: spec the JSON output properly.
1111

12-
use crate::source_map::{SourceMap, FilePathMapping};
12+
use syntax_pos::source_map::{SourceMap, FilePathMapping};
1313

14-
use errors::registry::Registry;
15-
use errors::{SubDiagnostic, CodeSuggestion};
16-
use errors::{DiagnosticId, Applicability};
17-
use errors::emitter::{Emitter, HumanReadableErrorType};
14+
use crate::registry::Registry;
15+
use crate::{SubDiagnostic, CodeSuggestion};
16+
use crate::{DiagnosticId, Applicability};
17+
use crate::emitter::{Emitter, HumanReadableErrorType};
1818

1919
use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
20-
use rustc_data_structures::sync::{self, Lrc};
20+
use rustc_data_structures::sync::Lrc;
2121
use std::io::{self, Write};
2222
use std::path::Path;
2323
use std::vec;
@@ -92,7 +92,7 @@ impl JsonEmitter {
9292
}
9393

9494
impl Emitter for JsonEmitter {
95-
fn emit_diagnostic(&mut self, diag: &errors::Diagnostic) {
95+
fn emit_diagnostic(&mut self, diag: &crate::Diagnostic) {
9696
let data = Diagnostic::from_errors_diagnostic(diag, self);
9797
let result = if self.pretty {
9898
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
@@ -212,7 +212,7 @@ struct ArtifactNotification<'a> {
212212
}
213213

214214
impl Diagnostic {
215-
fn from_errors_diagnostic(diag: &errors::Diagnostic,
215+
fn from_errors_diagnostic(diag: &crate::Diagnostic,
216216
je: &JsonEmitter)
217217
-> Diagnostic {
218218
let sugg = diag.suggestions.iter().map(|sugg| {

src/libsyntax/json/tests.rs renamed to src/librustc_errors/json/tests.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use super::*;
22

33
use crate::json::JsonEmitter;
4-
use crate::source_map::{FilePathMapping, SourceMap};
5-
use crate::with_default_globals;
4+
use syntax_pos::source_map::{FilePathMapping, SourceMap};
65

7-
use errors::emitter::{ColorConfig, HumanReadableErrorType};
8-
use errors::Handler;
6+
use crate::emitter::{ColorConfig, HumanReadableErrorType};
7+
use crate::Handler;
98
use rustc_serialize::json::decode;
109
use syntax_pos::{BytePos, Span};
1110

@@ -40,6 +39,13 @@ impl<T: Write> Write for Shared<T> {
4039
}
4140
}
4241

42+
fn with_default_globals(f: impl FnOnce()) {
43+
let globals = syntax_pos::Globals::new(syntax_pos::edition::DEFAULT_EDITION);
44+
syntax_pos::GLOBALS.set(&globals, || {
45+
syntax_pos::GLOBALS.set(&globals, f)
46+
})
47+
}
48+
4349
/// Test the span yields correct positions in JSON.
4450
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
4551
let expected_output = TestData { spans: vec![expected_output] };

src/librustc_errors/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod snippet;
3737
pub mod registry;
3838
mod styled_buffer;
3939
mod lock;
40+
pub mod json;
4041

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

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::ast::CRATE_NODE_ID;
1818
use syntax::source_map;
1919
use syntax::attr;
2020
use syntax::feature_gate::UnstableFeatures;
21-
use syntax::json::JsonEmitter;
21+
use errors::json::JsonEmitter;
2222
use syntax::symbol::sym;
2323
use syntax_pos::DUMMY_SP;
2424
use errors;

src/libsyntax/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ pub mod util {
8787
pub mod map_in_place;
8888
}
8989

90-
pub mod json;
91-
9290
pub mod ast;
9391
pub mod attr;
9492
pub mod expand;

src/tools/compiletest/src/json.rs

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

0 commit comments

Comments
 (0)