mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
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:
parent
fd77d9dc2b
commit
d1218d2961
|
@ -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"
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue