Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure to parse rustc's JSON output if it is too nested #11368

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use crate::util::interning::InternedString;
use crate::util::machine_message::{self, Message};
use crate::util::{add_path_args, internal, iter_join_onto, profile};
use cargo_util::{paths, ProcessBuilder, ProcessError};
use rustfix::diagnostics::{Applicability, Diagnostic};
use rustfix::diagnostics::Applicability;

const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";

Expand Down Expand Up @@ -1421,8 +1421,26 @@ fn on_stderr_line_inner(
rendered: String,
message: String,
level: String,
// `children: Vec<Diagnostic>` if we need to check them recursively
children: Vec<Diagnostic>,
children: Vec<PartialDiagnostic>,
}

// A partial rustfix::diagnostics::Diagnostic. We deserialize only a
// subset of the fields because rustc's output can be extremely
// deeply nested JSON in pathological cases involving macro
// expansion. Rustfix's Diagnostic struct is recursive containing a
// field `children: Vec<Self>`, and it can cause deserialization to
// hit serde_json's default recursion limit, or overflow the stack
// if we turn that off. Cargo only cares about the 1 field listed
// here.
#[derive(serde::Deserialize)]
weihanglo marked this conversation as resolved.
Show resolved Hide resolved
struct PartialDiagnostic {
spans: Vec<PartialDiagnosticSpan>,
}

// A partial rustfix::diagnostics::DiagnosticSpan.
#[derive(serde::Deserialize)]
struct PartialDiagnosticSpan {
suggestion_applicability: Option<Applicability>,
}

if let Ok(mut msg) = serde_json::from_str::<CompilerMessage>(compiler_message.get()) {
Expand Down