Use serde_json for json error messages
This commit is contained in:
parent
fc1df4ff17
commit
62a4f91a5a
6 changed files with 39 additions and 33 deletions
|
@ -28,7 +28,7 @@ use std::path::Path;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::vec;
|
||||
|
||||
use rustc_serialize::json::{as_json, as_pretty_json};
|
||||
use serde::Serialize;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -126,9 +126,9 @@ impl Emitter for JsonEmitter {
|
|||
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))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string_pretty(&data).unwrap())
|
||||
} else {
|
||||
writeln!(&mut self.dst, "{}", as_json(&data))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string(&data).unwrap())
|
||||
}
|
||||
.and_then(|_| self.dst.flush());
|
||||
if let Err(e) = result {
|
||||
|
@ -139,9 +139,9 @@ impl Emitter for JsonEmitter {
|
|||
fn emit_artifact_notification(&mut self, path: &Path, artifact_type: &str) {
|
||||
let data = ArtifactNotification { artifact: path, emit: artifact_type };
|
||||
let result = if self.pretty {
|
||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string_pretty(&data).unwrap())
|
||||
} else {
|
||||
writeln!(&mut self.dst, "{}", as_json(&data))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string(&data).unwrap())
|
||||
}
|
||||
.and_then(|_| self.dst.flush());
|
||||
if let Err(e) = result {
|
||||
|
@ -161,9 +161,9 @@ impl Emitter for JsonEmitter {
|
|||
.collect();
|
||||
let report = FutureIncompatReport { future_incompat_report: data };
|
||||
let result = if self.pretty {
|
||||
writeln!(&mut self.dst, "{}", as_pretty_json(&report))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string_pretty(&report).unwrap())
|
||||
} else {
|
||||
writeln!(&mut self.dst, "{}", as_json(&report))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string(&report).unwrap())
|
||||
}
|
||||
.and_then(|_| self.dst.flush());
|
||||
if let Err(e) = result {
|
||||
|
@ -175,9 +175,9 @@ impl Emitter for JsonEmitter {
|
|||
let lint_level = lint_level.as_str();
|
||||
let data = UnusedExterns { lint_level, unused_extern_names: unused_externs };
|
||||
let result = if self.pretty {
|
||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string_pretty(&data).unwrap())
|
||||
} else {
|
||||
writeln!(&mut self.dst, "{}", as_json(&data))
|
||||
writeln!(&mut self.dst, "{}", serde_json::to_string(&data).unwrap())
|
||||
}
|
||||
.and_then(|_| self.dst.flush());
|
||||
if let Err(e) = result {
|
||||
|
@ -204,7 +204,7 @@ impl Emitter for JsonEmitter {
|
|||
|
||||
// The following data types are provided just for serialisation.
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct Diagnostic {
|
||||
/// The primary error message.
|
||||
message: String,
|
||||
|
@ -218,7 +218,7 @@ struct Diagnostic {
|
|||
rendered: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct DiagnosticSpan {
|
||||
file_name: String,
|
||||
byte_start: u32,
|
||||
|
@ -245,7 +245,7 @@ struct DiagnosticSpan {
|
|||
expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct DiagnosticSpanLine {
|
||||
text: String,
|
||||
|
||||
|
@ -255,7 +255,7 @@ struct DiagnosticSpanLine {
|
|||
highlight_end: usize,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct DiagnosticSpanMacroExpansion {
|
||||
/// span where macro was applied to generate this code; note that
|
||||
/// this may itself derive from a macro (if
|
||||
|
@ -269,7 +269,7 @@ struct DiagnosticSpanMacroExpansion {
|
|||
def_site_span: DiagnosticSpan,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct DiagnosticCode {
|
||||
/// The code itself.
|
||||
code: String,
|
||||
|
@ -277,7 +277,7 @@ struct DiagnosticCode {
|
|||
explanation: Option<&'static str>,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct ArtifactNotification<'a> {
|
||||
/// The path of the artifact.
|
||||
artifact: &'a Path,
|
||||
|
@ -285,12 +285,12 @@ struct ArtifactNotification<'a> {
|
|||
emit: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct FutureBreakageItem {
|
||||
diagnostic: Diagnostic,
|
||||
}
|
||||
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct FutureIncompatReport {
|
||||
future_incompat_report: Vec<FutureBreakageItem>,
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ struct FutureIncompatReport {
|
|||
// doctest component (as well as cargo).
|
||||
// We could unify this struct the one in rustdoc but they have different
|
||||
// ownership semantics, so doing so would create wasteful allocations.
|
||||
#[derive(Encodable)]
|
||||
#[derive(Serialize)]
|
||||
struct UnusedExterns<'a, 'b, 'c> {
|
||||
/// The severity level of the unused dependencies lint
|
||||
lint_level: &'a str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue