Skip to content

Commit 1d8f6a7

Browse files
committed
save-analysis: Use serde instead of libserialize to dump JSON data
1 parent a2bbf7d commit 1d8f6a7

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

Cargo.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -2932,11 +2932,12 @@ dependencies = [
29322932
"rls-data 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)",
29332933
"rls-span 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
29342934
"rustc 0.0.0",
2935-
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
29362935
"rustc_codegen_utils 0.0.0",
29372936
"rustc_data_structures 0.0.0",
29382937
"rustc_target 0.0.0",
29392938
"rustc_typeck 0.0.0",
2939+
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
2940+
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
29402941
"syntax 0.0.0",
29412942
"syntax_pos 0.0.0",
29422943
]

src/librustc_save_analysis/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ crate-type = ["dylib"]
1111

1212
[dependencies]
1313
log = "0.4"
14+
rls-data = { version = "0.18.2", features = ["serialize-serde"] }
15+
rls-span = "0.4"
1416
rustc = { path = "../librustc" }
1517
rustc_data_structures = { path = "../librustc_data_structures" }
1618
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
1719
rustc_target = { path = "../librustc_target" }
1820
rustc_typeck = { path = "../librustc_typeck" }
21+
serde = "1.0"
22+
serde_json = "1.0"
1923
syntax = { path = "../libsyntax" }
2024
syntax_pos = { path = "../libsyntax_pos" }
21-
rls-data = "0.18.1"
22-
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

+10-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,16 @@ 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+
let json = match serde_json::to_string(result) {
33+
Ok(json) => json,
34+
Err(e) => {
35+
error!("Can't serialize save-analysis: {}", e);
36+
return;
37+
}
38+
};
39+
40+
if let Err(e) = write!(self.output, "{}", json) {
41+
error!("Error writing save-analysis: {:?}", e);
3642
}
3743
}
3844
}

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)