diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-22 11:53:40 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-22 13:46:33 +1100 |
| commit | 326b44e4d371644e8d48469087d763085b6c7711 (patch) | |
| tree | 05ee3d916aacdb0c53d722e8958237ab177df5ee /compiler/rustc_expand/src/proc_macro_server.rs | |
| parent | f8131a48a46ac3bc8a3d0fe0477055b132cffdc3 (diff) | |
| download | rust-326b44e4d371644e8d48469087d763085b6c7711.tar.gz rust-326b44e4d371644e8d48469087d763085b6c7711.zip | |
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.
Diffstat (limited to 'compiler/rustc_expand/src/proc_macro_server.rs')
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro_server.rs | 2 |
1 files changed, 1 insertions, 1 deletions
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 @@ impl server::FreeFunctions for Rustc<'_, '_> { fn emit_diagnostic(&mut self, diagnostic: Diagnostic<Self::Span>) { 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 { |
