Skip to content

Commit 2545196

Browse files
committed
save-analysis: Use serde instead of libserialize to dump JSON data
1 parent 4d9c6cd commit 2545196

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -2933,11 +2933,11 @@ dependencies = [
29332933
"rls-data 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)",
29342934
"rls-span 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
29352935
"rustc 0.0.0",
2936-
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
29372936
"rustc_codegen_utils 0.0.0",
29382937
"rustc_data_structures 0.0.0",
29392938
"rustc_target 0.0.0",
29402939
"rustc_typeck 0.0.0",
2940+
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
29412941
"syntax 0.0.0",
29422942
"syntax_pos 0.0.0",
29432943
]

src/librustc_save_analysis/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1616
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
1717
rustc_target = { path = "../librustc_target" }
1818
rustc_typeck = { path = "../librustc_typeck" }
19+
serde_json = "1"
1920
syntax = { path = "../libsyntax" }
2021
syntax_pos = { path = "../libsyntax_pos" }
2122
rls-data = "0.18.1"
2223
rls-span = "0.4"
23-
# FIXME(#40527) should move rustc serialize out of tree
24-
rustc-serialize = "0.3"

src/librustc_save_analysis/json_dumper.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::io::Write;
22

3-
use rustc_serialize::json::as_json;
4-
53
use rls_data::config::Config;
64
use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKind, Impl, Import,
75
MacroRef, Ref, RefKind, Relation};
@@ -31,8 +29,8 @@ pub struct WriteOutput<'b, W: Write> {
3129

3230
impl<'b, W: Write> DumpOutput for WriteOutput<'b, W> {
3331
fn dump(&mut self, result: &Analysis) {
34-
if write!(self.output, "{}", as_json(&result)).is_err() {
35-
error!("Error writing output");
32+
if let Err(e) = serde_json::to_writer(self.output.by_ref(), result) {
33+
error!("Can't serialize save-analysis: {:?}", e);
3634
}
3735
}
3836
}

src/librustc_save_analysis/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1141,10 +1141,15 @@ fn find_config(supplied: Option<Config>) -> Config {
11411141
if let Some(config) = supplied {
11421142
return config;
11431143
}
1144+
11441145
match env::var_os("RUST_SAVE_ANALYSIS_CONFIG") {
1145-
Some(config_string) => rustc_serialize::json::decode(config_string.to_str().unwrap())
1146-
.expect("Could not deserialize save-analysis config"),
11471146
None => Config::default(),
1147+
Some(config) => config.to_str()
1148+
.ok_or(())
1149+
.map_err(|_| error!("`RUST_SAVE_ANALYSIS_CONFIG` isn't UTF-8"))
1150+
.and_then(|cfg| serde_json::from_str(cfg)
1151+
.map_err(|_| error!("Could not deserialize save-analysis config"))
1152+
).unwrap_or_default()
11481153
}
11491154
}
11501155

0 commit comments

Comments
 (0)