diff --git a/Cargo.toml b/Cargo.toml index b1657a46d05..d0269892ee4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/cargo/util/machine_message.rs b/src/cargo/util/machine_message.rs index 3104d4b6060..1c683934a08 100644 --- a/src/cargo/util/machine_message.rs +++ b/src/cargo/util/machine_message.rs @@ -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: &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, } impl<'a> Message for FromCompiler<'a> { diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 1fd1ef8b11d..3322986ad67 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -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(()) +}