Skip to content

Commit b2b34ac

Browse files
committed
Auto merge of #6081 - dtolnay:raw, r=alexcrichton
Fix missing messages when --message-format=json is deeply nested This commit switches from `serde_json::Value` to [`RawValue`](https://docs.rs/serde_json/1.0/serde_json/value/struct.RawValue.html), which can process arbitrarily deeply nested JSON content without recursion. Fixes #5992. @ehuss
2 parents 650b5d8 + d1218d2 commit b2b34ac

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ semver = { version = "0.9.0", features = ["serde"] }
4848
serde = "1.0"
4949
serde_derive = "1.0"
5050
serde_ignored = "0.0.4"
51-
serde_json = "1.0.24"
51+
serde_json = { version = "1.0.30", features = ["raw_value"] }
5252
shell-escape = "0.1.4"
5353
tar = { version = "0.4.15", default-features = false }
5454
tempfile = "3.0"

src/cargo/util/machine_message.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::ser;
2-
use serde_json::{self, Value};
2+
use serde_json::{self, value::RawValue};
33

44
use core::{PackageId, Target};
55

@@ -8,16 +8,17 @@ pub trait Message: ser::Serialize {
88
}
99

1010
pub fn emit<T: Message>(t: &T) {
11-
let mut json: Value = serde_json::to_value(t).unwrap();
12-
json["reason"] = json!(t.reason());
13-
println!("{}", json);
11+
let json = serde_json::to_string(t).unwrap();
12+
assert!(json.starts_with("{\""));
13+
let reason = json!(t.reason());
14+
println!("{{\"reason\":{},{}", reason, &json[1..]);
1415
}
1516

1617
#[derive(Serialize)]
1718
pub struct FromCompiler<'a> {
1819
pub package_id: &'a PackageId,
1920
pub target: &'a Target,
20-
pub message: serde_json::Value,
21+
pub message: Box<RawValue>,
2122
}
2223

2324
impl<'a> Message for FromCompiler<'a> {

tests/testsuite/check.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::{self, Write};
2+
13
use glob::glob;
24
use support::install::exe;
35
use support::is_nightly;
@@ -690,3 +692,24 @@ fn does_not_use_empty_rustc_wrapper() {
690692
let p = project().file("src/lib.rs", "").build();
691693
p.cargo("check").env("RUSTC_WRAPPER", "").run();
692694
}
695+
696+
#[test]
697+
fn error_from_deep_recursion() -> Result<(), fmt::Error> {
698+
let mut big_macro = String::new();
699+
writeln!(big_macro, "macro_rules! m {{")?;
700+
for i in 0..130 {
701+
writeln!(big_macro, "({}) => {{ m!({}); }};", i, i + 1)?;
702+
}
703+
writeln!(big_macro, "}}")?;
704+
writeln!(big_macro, "m!(0);")?;
705+
706+
let p = project().file("src/lib.rs", &big_macro).build();
707+
p.cargo("check --message-format=json")
708+
.with_status(101)
709+
.with_stdout_contains(
710+
"[..]\"message\":\"recursion limit reached while expanding the macro `m`\"[..]",
711+
)
712+
.run();
713+
714+
Ok(())
715+
}

0 commit comments

Comments
 (0)