Skip to content

Commit

Permalink
Rollup merge of rust-lang#108436 - tshepang:translatable-proc-macro-p…
Browse files Browse the repository at this point in the history
…anicked, r=estebank

make "proc macro panicked" translatable
  • Loading branch information
compiler-errors authored Feb 25, 2023
2 parents eb2da60 + dca52ac commit ec85ac5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_expand/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ expand_module_multiple_candidates =
.help = delete or rename one of them to remove the ambiguity
expand_trace_macro = trace_macro
expand_proc_macro_panicked =
proc macro panicked
.help = message: {$message}
15 changes: 15 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
12 changes: 7 additions & 5 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::base::{self, *};
use crate::errors;
use crate::proc_macro_server;

use rustc_ast as ast;
Expand Down Expand Up @@ -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() }),
})
})
}
}
Expand Down

0 comments on commit ec85ac5

Please sign in to comment.