Skip to content

Commit 6554554

Browse files
Merge pull request #822 from Mark-Simulacrum/next
Avoid recursion issues in parsing rustc messages
2 parents 1a2e31f + 786dc6d commit 6554554

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/runner/test.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::runner::tasks::TaskCtx;
77
use crate::runner::OverrideResult;
88
use anyhow::Error;
99
use cargo_metadata::diagnostic::DiagnosticLevel;
10-
use cargo_metadata::{CrateType, Message, Metadata, Package, Target, TargetKind};
10+
use cargo_metadata::{CrateType, Metadata, Package, Target, TargetKind};
1111
use docsrs_metadata::Metadata as DocsrsMetadata;
1212
use remove_dir_all::remove_dir_all;
1313
use rustwide::cmd::{CommandError, MountKind, ProcessLinesActions, SandboxBuilder};
@@ -233,6 +233,45 @@ fn run_cargo(
233233
}
234234
}
235235

236+
/// A cargo message
237+
///
238+
/// This duplicates cargo_metadata::Message, but without variants we don't need to avoid recursion
239+
/// issues. See https://github.com/rust-lang/rust/issues/152354 for context.
240+
#[derive(Debug, Deserialize)]
241+
#[serde(tag = "reason", rename_all = "kebab-case")]
242+
enum Message {
243+
/// The compiler wants to display a message
244+
CompilerMessage(CompilerMessage),
245+
#[serde(other)]
246+
Other,
247+
}
248+
249+
/// A cargo message
250+
///
251+
/// This duplicates cargo_metadata::CompilerMessage, but without variants we don't need to avoid recursion
252+
/// issues. See https://github.com/rust-lang/rust/issues/152354 for context.
253+
#[derive(Debug, Deserialize)]
254+
struct CompilerMessage {
255+
/// The package this message belongs to
256+
package_id: cargo_metadata::PackageId,
257+
/// The message the compiler sent.
258+
message: Diagnostic,
259+
}
260+
261+
/// A diagnostic message generated by rustc
262+
///
263+
/// This duplicates cargo_metadata::Diagnostic, but without variants we don't need to avoid recursion
264+
/// issues. See https://github.com/rust-lang/rust/issues/152354 for context.
265+
#[derive(Debug, Deserialize)]
266+
struct Diagnostic {
267+
/// The associated error code for this diagnostic
268+
code: Option<cargo_metadata::diagnostic::DiagnosticCode>,
269+
/// "error: internal compiler error", "error", "warning", "note", "help"
270+
level: cargo_metadata::diagnostic::DiagnosticLevel,
271+
/// The message as rustc would render it
272+
rendered: Option<String>,
273+
}
274+
236275
pub(super) fn run_test(
237276
action: &str,
238277
ctx: &TaskCtx,

0 commit comments

Comments
 (0)