Skip to content

Commit e9dbd9f

Browse files
authored
Fix regression that swallowed json diagnostic explanations (#16075)
Fixes #16074
2 parents b89128d + 6b189ce commit e9dbd9f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,12 +2168,14 @@ fn on_stderr_line_inner(
21682168
rendered: String,
21692169
#[serde(flatten, borrow)]
21702170
other: std::collections::BTreeMap<Cow<'a, str>, serde_json::Value>,
2171-
code: Option<DiagnosticCode>,
2171+
code: Option<DiagnosticCode<'a>>,
21722172
}
21732173

21742174
#[derive(serde::Deserialize, serde::Serialize)]
2175-
struct DiagnosticCode {
2175+
struct DiagnosticCode<'a> {
21762176
code: String,
2177+
#[serde(flatten, borrow)]
2178+
other: std::collections::BTreeMap<Cow<'a, str>, serde_json::Value>,
21772179
}
21782180

21792181
if let Ok(mut error) =

tests/testsuite/test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4455,6 +4455,47 @@ fn json_artifact_includes_executable_for_library_tests() {
44554455
.run();
44564456
}
44574457

4458+
#[cargo_test]
4459+
fn json_diagnostic_includes_explanation() {
4460+
let p = project()
4461+
.file(
4462+
"src/main.rs",
4463+
"fn main() { const OH_NO: &'static mut usize = &mut 1; }",
4464+
)
4465+
.build();
4466+
4467+
p.cargo("check --message-format=json")
4468+
.with_stdout_data(
4469+
str![[r#"
4470+
[
4471+
{
4472+
"manifest_path": "[ROOT]/foo/Cargo.toml",
4473+
"message": {
4474+
"$message_type": "diagnostic",
4475+
"children": "{...}",
4476+
"code": {
4477+
"code": "E0764",
4478+
"explanation": "{...}"
4479+
},
4480+
"level": "error",
4481+
"message": "{...}",
4482+
"rendered": "{...}",
4483+
"spans": "{...}"
4484+
},
4485+
"package_id": "{...}",
4486+
"reason": "compiler-message",
4487+
"target": "{...}"
4488+
},
4489+
"{...}"
4490+
]
4491+
"#]]
4492+
.is_json()
4493+
.against_jsonlines(),
4494+
)
4495+
.with_status(101)
4496+
.run();
4497+
}
4498+
44584499
#[cargo_test]
44594500
fn json_artifact_includes_executable_for_integration_tests() {
44604501
let p = project()

0 commit comments

Comments
 (0)