From 326b44e4d371644e8d48469087d763085b6c7711 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 22 Feb 2024 11:53:40 +1100 Subject: [PATCH] Fix panic when compiling `Rocket`. `Rustc::emit_diagnostic` reconstructs a diagnostic passed in from the macro machinery. Currently it uses the type `DiagnosticBuilder<'_, ErrorGuaranteed>`, which is incorrect, because the diagnostic might be a warning. And if it is a warning, because of the `ErrorGuaranteed` we end up calling into `emit_producing_error_guaranteed` and the assertion within that function (correctly) fails because the level is not an error level. The fix is simple: change the type to `DiagnosticBuilder<'_, ()>`. Using `()` works no matter what the diagnostic level is, and we don't need an `ErrorGuaranteed` here. The panic was reported in #120576. --- compiler/rustc_expand/src/proc_macro_server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index b80ecbc9c65..62d0deb2d3a 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -510,7 +510,7 @@ fn literal_from_str(&mut self, s: &str) -> Result) { let message = rustc_errors::DiagnosticMessage::from(diagnostic.message); - let mut diag: DiagnosticBuilder<'_, rustc_errors::ErrorGuaranteed> = + let mut diag: DiagnosticBuilder<'_, ()> = DiagnosticBuilder::new(&self.sess().dcx, diagnostic.level.to_internal(), message); diag.span(MultiSpan::from_spans(diagnostic.spans)); for child in diagnostic.children {