Currently, the translatable diagnostics effort is on hold due to causing a lot of friction for compiler contributors.
I think we should revisit the global registration idea to try to address this.
The main issue this attempts to address is all the boilerplate required for new diagnostics. Currently, when adding a new diagnostic, at least 3 sites need to be updated:
- the emission site
- the definition of the diagnostic
- the
messages.ftl
file
Ideally, we could write a procedural macro that could handle all of this in one easy step, but we can't do that, because the messages all need to be collected into a fluent bundle, and that means they either have to all appear together, or there needs to be a list of all the places they appear, both of which mean updating two locations.
If we had some sort of distributed slice mechanism, we could have the distributed slice defined by the fluent_messages!
macro, and then we could add a new macro, fluent_diag!
[1], that would automatically:
- make a diagnostic name and struct name based off of the passed identifiers[2]
- define a struct using
derive(Diagnostic)
, using the fields passed - append a message to the distributed list based on the diagnostic name and the passed message
- construct and return this struct based on the passed values
fn emit_some_lint(cx: &LateContext, span: Span, ident: Symbol) {
let diag = fluent_diag!(some_lint, "something is wrong with $ident", ident: &str = ident.as_str());
cx.emit_span_lint(SOME_LINT, span, diag);
}