Skip to content

Commit 60b71f5

Browse files
Remove support for JSON deserialization to Rust
This is no longer used by the compiler itself, and removing this support opens the door to massively simplifying the Decodable/Decoder API by dropping the self-describing deserialization support (necessary for JSON).
1 parent 45e2c28 commit 60b71f5

File tree

9 files changed

+46
-718
lines changed

9 files changed

+46
-718
lines changed

compiler/rustc_errors/src/json/tests.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
55

66
use crate::emitter::{ColorConfig, HumanReadableErrorType};
77
use crate::Handler;
8-
use rustc_serialize::json::decode;
8+
use rustc_serialize::json;
99
use rustc_span::{BytePos, Span};
1010

1111
use std::str;
1212

13-
#[derive(Decodable, Debug, PartialEq, Eq)]
14-
struct TestData {
15-
spans: Vec<SpanTestData>,
16-
}
17-
18-
#[derive(Decodable, Debug, PartialEq, Eq)]
13+
#[derive(Debug, PartialEq, Eq)]
1914
struct SpanTestData {
2015
pub byte_start: u32,
2116
pub byte_end: u32,
@@ -41,8 +36,6 @@ impl<T: Write> Write for Shared<T> {
4136

4237
/// Test the span yields correct positions in JSON.
4338
fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
44-
let expected_output = TestData { spans: vec![expected_output] };
45-
4639
rustc_span::create_default_session_globals_then(|| {
4740
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
4841
sm.new_source_file(Path::new("test.rs").to_owned().into(), code.to_owned());
@@ -64,9 +57,19 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
6457

6558
let bytes = output.lock().unwrap();
6659
let actual_output = str::from_utf8(&bytes).unwrap();
67-
let actual_output: TestData = decode(actual_output);
68-
69-
assert_eq!(expected_output, actual_output)
60+
let actual_output = json::from_str(&actual_output).unwrap();
61+
let spans = actual_output["spans"].as_array().unwrap();
62+
assert_eq!(spans.len(), 1);
63+
let obj = &spans[0];
64+
let actual_output = SpanTestData {
65+
byte_start: obj["byte_start"].as_u64().unwrap() as u32,
66+
byte_end: obj["byte_end"].as_u64().unwrap() as u32,
67+
line_start: obj["line_start"].as_u64().unwrap() as u32,
68+
line_end: obj["line_end"].as_u64().unwrap() as u32,
69+
column_start: obj["column_start"].as_u64().unwrap() as u32,
70+
column_end: obj["column_end"].as_u64().unwrap() as u32,
71+
};
72+
assert_eq!(expected_output, actual_output);
7073
})
7174
}
7275

0 commit comments

Comments
 (0)