diff options
| author | Tshepang Mbambo <tshepang@gmail.com> | 2023-02-24 23:37:10 +0200 |
|---|---|---|
| committer | Tshepang Mbambo <tshepang@gmail.com> | 2023-02-24 23:37:10 +0200 |
| commit | dca52ac835f8c87dfc3167606d1146ce6b9bba11 (patch) | |
| tree | 15ef651644e42f0100f1e8b49c4a5c9c8f59189b /compiler/rustc_expand/src | |
| parent | 07c993eba8b76eae497e98433ae075b00f01be10 (diff) | |
| download | rust-dca52ac835f8c87dfc3167606d1146ce6b9bba11.tar.gz rust-dca52ac835f8c87dfc3167606d1146ce6b9bba11.zip | |
make "proc macro panicked" translatable
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/errors.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro.rs | 12 |
2 files changed, 22 insertions, 5 deletions
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index d9b2b5f4802..70ab222b484 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -375,3 +375,18 @@ pub struct TraceMacro { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(expand_proc_macro_panicked)] +pub(crate) struct ProcMacroPanicked { + #[primary_span] + pub span: Span, + #[subdiagnostic] + pub message: Option<ProcMacroPanickedHelp>, +} + +#[derive(Subdiagnostic)] +#[help(expand_help)] +pub(crate) struct ProcMacroPanickedHelp { + pub message: String, +} diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index e9a69192068..cef64a10479 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -1,4 +1,5 @@ use crate::base::{self, *}; +use crate::errors; use crate::proc_macro_server; use rustc_ast as ast; @@ -60,11 +61,12 @@ impl base::BangProcMacro for BangProcMacro { let strategy = exec_strategy(ecx); let server = proc_macro_server::Rustc::new(ecx); self.client.run(&strategy, server, input, proc_macro_backtrace).map_err(|e| { - let mut err = ecx.struct_span_err(span, "proc macro panicked"); - if let Some(s) = e.as_str() { - err.help(&format!("message: {}", s)); - } - err.emit() + ecx.sess.emit_err(errors::ProcMacroPanicked { + span, + message: e + .as_str() + .map(|message| errors::ProcMacroPanickedHelp { message: message.into() }), + }) }) } } |
