Description
openedon Feb 14, 2024
Switching between a lint and a hard error used to be fairly simple, one basically just swapped out the function that is called to emit the diagnostic. However, with translatable diagnostic, this has become more work:
- the error type needs to be changed from
derive(LintDiagnostic)
toderive(Diagnostic)
- a
span
field needs to be added and decorated with#[primary_span]
- and only then the diagnostic-emitting code can be adjusted to call
emit_err
instead ofemit_node_span_lint
It can be hard to find out about this recipe. It is also a (small) roadblock whenever one wants to do a crater run with a lint turned into a hard error, just to see how much it happens in the ecosystem.
So maybe something could be done to unify these two APIs? I don't know whether "span-in-error-type" vs "separate-span" is the better API. I was told that sometimes having the span in the type is very useful because then extra attributes can be easily applied to it. OTOH, for parts of the compiler (e.g. the interpreter), the logic that determines which error to emit and the logic that determines the span are quite far apart from each other, leading kind of a mess with the current error APIs. Maybe there is a way to make both styles possible for both lints and hard errors?
Cc @davidtwco (not sure who else is pushing translatable diagnostics?)