Fix missing messages when --message-format=json is deeply nested

This commit switches from serde_json::Value to RawValue, which can
process arbitrarily deeply nested JSON content without recursion.
This commit is contained in:
David Tolnay 2018-09-23 14:11:25 -07:00
parent fd77d9dc2b
commit d1218d2961
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
3 changed files with 30 additions and 6 deletions

View file

@ -48,7 +48,7 @@ semver = { version = "0.9.0", features = ["serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.0.4"
serde_json = "1.0.24"
serde_json = { version = "1.0.30", features = ["raw_value"] }
shell-escape = "0.1.4"
tar = { version = "0.4.15", default-features = false }
tempfile = "3.0"

View file

@ -1,5 +1,5 @@
use serde::ser;
use serde_json::{self, Value};
use serde_json::{self, value::RawValue};
use core::{PackageId, Target};
@ -8,16 +8,17 @@ pub trait Message: ser::Serialize {
}
pub fn emit<T: Message>(t: &T) {
let mut json: Value = serde_json::to_value(t).unwrap();
json["reason"] = json!(t.reason());
println!("{}", json);
let json = serde_json::to_string(t).unwrap();
assert!(json.starts_with("{\""));
let reason = json!(t.reason());
println!("{{\"reason\":{},{}", reason, &json[1..]);
}
#[derive(Serialize)]
pub struct FromCompiler<'a> {
pub package_id: &'a PackageId,
pub target: &'a Target,
pub message: serde_json::Value,
pub message: Box<RawValue>,
}
impl<'a> Message for FromCompiler<'a> {

View file

@ -1,3 +1,5 @@
use std::fmt::{self, Write};
use glob::glob;
use support::install::exe;
use support::is_nightly;
@ -690,3 +692,24 @@ fn does_not_use_empty_rustc_wrapper() {
let p = project().file("src/lib.rs", "").build();
p.cargo("check").env("RUSTC_WRAPPER", "").run();
}
#[test]
fn error_from_deep_recursion() -> Result<(), fmt::Error> {
let mut big_macro = String::new();
writeln!(big_macro, "macro_rules! m {{")?;
for i in 0..130 {
writeln!(big_macro, "({}) => {{ m!({}); }};", i, i + 1)?;
}
writeln!(big_macro, "}}")?;
writeln!(big_macro, "m!(0);")?;
let p = project().file("src/lib.rs", &big_macro).build();
p.cargo("check --message-format=json")
.with_status(101)
.with_stdout_contains(
"[..]\"message\":\"recursion limit reached while expanding the macro `m`\"[..]",
)
.run();
Ok(())
}